}
public void run(String[] args) {
if (!ArgumentParser.validateArguments(args, TrainerToolParams.class)) {
System.err.println(getHelp());
throw new TerminateToolException(1);
}
TrainerToolParams params = ArgumentParser.parse(args,
TrainerToolParams.class);
opennlp.tools.util.TrainingParameters mlParams =
CmdLineUtil.loadTrainingParameters(params.getParams(), false);
if (mlParams != null) {
if (!TrainUtil.isValid(mlParams.getSettings())) {
System.err.println("Training parameters file is invalid!");
throw new TerminateToolException(-1);
}
if (TrainUtil.isSequenceTraining(mlParams.getSettings())) {
System.err.println("Sequence training is not supported!");
throw new TerminateToolException(-1);
}
}
File trainingDataInFile = params.getData();
File modelOutFile = params.getModel();
CmdLineUtil.checkOutputFile("tokenizer model", modelOutFile);
ObjectStream<TokenSample> sampleStream = openSampleData("Training",
trainingDataInFile, params.getEncoding());
if(mlParams == null)
mlParams = createTrainingParameters(params.getIterations(), params.getCutoff());
TokenizerModel model;
try {
Dictionary dict = loadDict(params.getAbbDict());
model = opennlp.tools.tokenize.TokenizerME.train(params.getLang(),
sampleStream, dict, params.getAlphaNumOpt(), mlParams);
} catch (IOException e) {
CmdLineUtil.printTrainingIoError(e);
throw new TerminateToolException(-1);
}
finally {
try {
sampleStream.close();
} catch (IOException e) {