JENA-1802: Flag --count for riot
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
index 527fae6..2c38039 100644
--- a/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
+++ b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
@@ -37,6 +37,7 @@
private ArgDecl argCheck = new ArgDecl(ArgDecl.NoValue, "check") ;
private ArgDecl argNoCheck = new ArgDecl(ArgDecl.NoValue, "nocheck", "noCheck") ;
private ArgDecl argSink = new ArgDecl(ArgDecl.NoValue, "sink", "null") ;
+ private ArgDecl argCount = new ArgDecl(ArgDecl.NoValue, "count") ;
private ArgDecl argStrict = new ArgDecl(ArgDecl.NoValue, "strict") ;
private ArgDecl argValidate = new ArgDecl(ArgDecl.NoValue, "validate") ;
@@ -63,6 +64,7 @@
private boolean bitbucket = false ;
private boolean strict = false ;
private boolean validate = false ;
+ private boolean outputCount = false ;
private Lang lang = null ;
@Override
@@ -74,6 +76,7 @@
cmdLine.add(argCheck, "--check", "Addition checking of RDF terms") ; // (default: off for N-triples, N-Quads, on for Turtle and TriG)") ;
cmdLine.add(argStrict, "--strict", "Run with in strict mode") ;
cmdLine.add(argValidate,"--validate", "Same as --sink --check --strict") ;
+ cmdLine.add(argCount, "--count", "Count triples/quads parsed, not output them") ;
cmdLine.add(argRDFS, "--rdfs=file", "Apply some RDFS inference using the vocabulary in the file") ;
cmdLine.add(argNoCheck, "--nocheck", "Turn off checking of RDF terms") ;
@@ -131,6 +134,11 @@
if ( cmdLine.contains(argSink) )
bitbucket = true ;
+
+ if ( cmdLine.contains(argCount) ) {
+ bitbucket = true ;
+ outputCount = true ;
+ }
if ( cmdLine.contains(argRDFS) ) {
try {
@@ -160,6 +168,10 @@
return validate ;
}
+ public boolean outputCount() {
+ return outputCount ;
+ }
+
public boolean skipOnBadTerm() {
return skipOnBadTerm ;
}
diff --git a/jena-cmds/src/main/java/riotcmd/CmdLangParse.java b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
index c696315..777ee31 100644
--- a/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
+++ b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
@@ -82,7 +82,7 @@
@Override
protected String getSummary() {
- return getCommandName()+" [--time] [--check|--noCheck] [--sink] [--base=IRI] [--out=FORMAT] [--compress] file ..." ;
+ return getCommandName()+" [--help] [--time] [--base=IRI] [-syntax=FORMAT] [--out=FORMAT] [--count] file ..." ;
}
protected List<ParseRecord> outcomes = new ArrayList<>();
@@ -170,7 +170,7 @@
postParse.postParse();
// Post parse information.
// Total if more than one file.
- if ( super.getPositional().size() > 1 && modTime.timingEnabled() ) {
+ if ( super.getPositional().size() > 1 && ( modTime.timingEnabled() || modLangParse.outputCount() ) ) {
long totalMillis = 0;
long totalTriples = 0;
long totalQuads = 0;
@@ -207,6 +207,14 @@
}
public void outcome(ParseRecord rtn) {
+ if ( modLangParse.outputCount() ) {
+ System.err.printf("%-15s", rtn.filename);
+ if ( rtn.triples > 0 )
+ System.err.printf(" : Triples = %,d", rtn.triples);
+ if ( rtn.quads > 0 )
+ System.err.printf(" : Quads = %,d", rtn.quads);
+ System.err.println();
+ }
outcomes.add(rtn);
if ( modTime.timingEnabled() )
output(rtn);
@@ -235,6 +243,7 @@
baseURI = "http://base/";
builder.base(baseURI);
}
+ filename = "stdin";
builder.source(System.in);
} else {
builder.source(filename);
@@ -246,7 +255,7 @@
// Contrast with --syntax=.. which forces the language.
protected abstract Lang dftLang() ;
- protected ParseRecord parseRIOT(RDFParserBuilder builder, /*Info for the ProcessOutcome*/ String filename) {
+ protected ParseRecord parseRIOT(RDFParserBuilder builder, String filename) {
boolean checking = true ;
if ( modLangParse.explicitChecking() )
checking = true;
@@ -303,7 +312,6 @@
}
sink.finish() ;
long x = modTime.endTimer() ;
- // TEMP
ParseRecord outcome = new ParseRecord(filename, successful, x, sink.countTriples(), sink.countQuads(), errHandler);
return outcome;
}
@@ -362,14 +370,14 @@
long total = numberTriples + numberQuads + numberTuples;
StringBuilder sb = new StringBuilder();
if ( total > 0 ) {
- sb.append(label);
+ sb.append(String.format("%-15s", label));
if ( success )
- appendFmt(sb, " : %,5.2f sec", timeSec);
+ appendFmt(sb, " : %,4.2f sec", timeSec);
appendCount(sb, numberTriples, "Triple", "Triples", "TPS");
appendCount(sb, numberQuads, "Quad", "Quads", "QPS");
appendCount(sb, numberTuples, "Tuple", "Tuples", "TPS");
if ( success && timeMillis > 0 )
- appendFmt(sb," : %,.2f %s", numberTriples/timeSec, "per second");
+ appendFmt(sb," : %,.2f %s", total/timeSec, "per second");
} else {
appendFmt(sb, "%s : (No Output)", label) ;
}