Charset encoding = params.getEncoding();
ObjectStream<NameSample> sampleStream = TokenNameFinderTrainerTool
.openSampleData("Training Data", trainingDataInFile, encoding);
TokenNameFinderCrossValidator validator;
List<EvaluationMonitor<NameSample>> listeners = new LinkedList<EvaluationMonitor<NameSample>>();
if (params.getMisclassified()) {
listeners.add(new NameEvaluationErrorListener());
}
TokenNameFinderDetailedFMeasureListener detailedFListener = null;
if (params.getDetailedF()) {
detailedFListener = new TokenNameFinderDetailedFMeasureListener();
listeners.add(detailedFListener);
}
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 {
validator = new TokenNameFinderCrossValidator(params.getLang(),
params.getType(), mlParams, featureGeneratorBytes, resources, listeners.toArray(new TokenNameFinderEvaluationMonitor[listeners.size()]));
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
}
}
System.out.println("done");
System.out.println();
if(detailedFListener == null) {
System.out.println(validator.getFMeasure());
} else {
System.out.println(detailedFListener.toString());
}
}