}
public void run(String[] args) {
if (!ArgumentParser.validateArguments(args, CVToolParams.class)) {
System.err.println(getHelp());
throw new TerminateToolException(1);
}
CVToolParams params = ArgumentParser.parse(args,
CVToolParams.class);
opennlp.tools.util.TrainingParameters mlParams = CmdLineUtil
.loadTrainingParameters(params.getParams(), false);
File trainingDataInFile = params.getData();
CmdLineUtil.checkInputFile("Training Data", trainingDataInFile);
ObjectStream<ChunkSample> sampleStream =
ChunkerTrainerTool.openSampleData("Training Data",
trainingDataInFile, params.getEncoding());
List<EvaluationMonitor<ChunkSample>> listeners = new LinkedList<EvaluationMonitor<ChunkSample>>();
ChunkerDetailedFMeasureListener detailedFMeasureListener = null;
if (params.getMisclassified()) {
listeners.add(new ChunkEvaluationErrorListener());
}
if (params.getDetailedF()) {
detailedFMeasureListener = new ChunkerDetailedFMeasureListener();
listeners.add(detailedFMeasureListener);
}
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()));
}
ChunkerCrossValidator validator = new ChunkerCrossValidator(
params.getLang(), mlParams,
listeners.toArray(new ChunkerEvaluationMonitor[listeners.size()]));
try {
validator.evaluate(sampleStream, params.getFolds());
}
catch (IOException e) {
CmdLineUtil.printTrainingIoError(e);
throw new TerminateToolException(-1);
}
finally {
try {
sampleStream.close();
} catch (IOException e) {