Skip to content

Commit

Permalink
optionally more verbose output on STDOUT, like the line number of the…
Browse files Browse the repository at this point in the history
… rule in the grammar.xml
  • Loading branch information
danielnaber committed Jan 13, 2023
1 parent f7288bd commit 617e672
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private static CommandLine ensureCorrectUsageOrExit(String[] args) {
.desc("URL of a named entity recognition service").build());
options.addOption(Option.builder().longOpt("skip-exceptions")
.desc("Whether internal Java exceptions should only be printed instead of stopping this script").build());
options.addOption(Option.builder("v").longOpt("verbose")
.desc("More verbose output on STDOUT, like the line number of the rule in the grammar.xml").build());
try {
CommandLineParser parser = new DefaultParser();
return parser.parse(options, args);
Expand Down Expand Up @@ -231,7 +233,7 @@ private void run(File propFile, Set<String> disabledRules, String langCode, Stri
} else if (propFile != null) {
resultHandler = new DatabaseHandler(propFile, maxSentences, maxErrors);
} else {
resultHandler = new StdoutHandler(maxSentences, maxErrors, contextSize);
resultHandler = new StdoutHandler(maxSentences, maxErrors, contextSize, options.hasOption("verbose"));
}
MixingSentenceSource mixingSource = MixingSentenceSource.create(Arrays.asList(fileNames), lang, filter);
while (mixingSource.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@
class StdoutHandler extends ResultHandler {

private final ContextTools contextTools = new ContextTools();
private final boolean verbose;

StdoutHandler(int maxSentences, int maxErrors) {
this(maxSentences, maxErrors, CONTEXT_SIZE);
}

StdoutHandler(int maxSentences, int maxErrors, int contextSize) {
this(maxSentences, maxErrors, contextSize, false);
}

StdoutHandler(int maxSentences, int maxErrors, int contextSize, boolean verbose) {
super(maxSentences, maxErrors);
contextTools.setContextSize(contextSize);
this.verbose = verbose;
//contextTools.setContextSize(100);
//contextTools.setErrorMarker("**", "**");
//contextTools.setEscapeHtml(false);
Expand All @@ -60,6 +66,10 @@ protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Lang
if (match.getRule().isDefaultTempOff()) {
output += " [temp_off]";
}
if (verbose && match.getRule() instanceof AbstractPatternRule) {
AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
output += " ruleLine=" + pRule.getXmlLineNumber();
}
System.out.println(output);
String msg = match.getMessage();
msg = msg.replaceAll("<suggestion>", "'");
Expand Down

0 comments on commit 617e672

Please sign in to comment.