TokenizerEvaluationMonitor missclassifiedListener = null;
if (params.getMisclassified()) {
missclassifiedListener = new TokenEvaluationErrorListener();
}
TokenizerEvaluator evaluator = new TokenizerEvaluator(
new opennlp.tools.tokenize.TokenizerME(model), missclassifiedListener);
System.out.print("Evaluating ... ");
File testData = params.getData();
CmdLineUtil.checkInputFile("Test data", testData);
ObjectStream<TokenSample> sampleStream = TokenizerTrainerTool
.openSampleData("Test", testData, encoding);
try {
evaluator.evaluate(sampleStream);
} catch (IOException e) {
System.err.println("failed");
System.err.println("Reading test data error " + e.getMessage());
throw new TerminateToolException(-1);
} finally {
try {
sampleStream.close();
} catch (IOException e) {
// sorry that this can fail
}
}
System.out.println("done");
System.out.println();
System.out.println(evaluator.getFMeasure());
}