Charset encoding = params.getEncoding();
ObjectStream<SentenceSample> sampleStream = SentenceDetectorTrainerTool.openSampleData("Training Data",
trainingDataInFile, encoding);
SDCrossValidator validator;
SentenceDetectorEvaluationMonitor errorListener = null;
if (params.getMisclassified()) {
errorListener = new SentenceEvaluationErrorListener();
}
if (mlParams == null) {
mlParams = new TrainingParameters();
mlParams.put(TrainingParameters.ALGORITHM_PARAM, "MAXENT");
mlParams.put(TrainingParameters.ITERATIONS_PARAM,
Integer.toString(params.getIterations()));
mlParams.put(TrainingParameters.CUTOFF_PARAM,
Integer.toString(params.getCutoff()));
}
try {
Dictionary abbreviations = SentenceDetectorTrainerTool.loadDict(params
.getAbbDict());
validator = new SDCrossValidator(params.getLang(), mlParams,
abbreviations, errorListener);
validator.evaluate(sampleStream, params.getFolds());
}
catch (IOException e) {
CmdLineUtil.printTrainingIoError(e);
throw new TerminateToolException(-1);
}
finally {
try {
sampleStream.close();
} catch (IOException e) {
// sorry that this can fail
}
}
FMeasure result = validator.getFMeasure();
System.out.println(result.toString());
}