mlParams = CmdLineUtil.loadTrainingParameters(params.getParams(), true);
if (mlParams != null) {
if (!TrainUtil.isValid(mlParams.getSettings("build"))) {
throw new TerminateToolException(1, "Build training parameters are invalid!");
}
if (!TrainUtil.isValid(mlParams.getSettings("check"))) {
throw new TerminateToolException(1, "Check training parameters are invalid!");
}
if (!TrainUtil.isValid(mlParams.getSettings("attach"))) {
throw new TerminateToolException(1, "Attach training parameters are invalid!");
}
if (!TrainUtil.isValid(mlParams.getSettings("tagger"))) {
throw new TerminateToolException(1, "Tagger training parameters are invalid!");
}
if (!TrainUtil.isValid(mlParams.getSettings("chunker"))) {
throw new TerminateToolException(1, "Chunker training parameters are invalid!");
}
}
if(mlParams == null) {
mlParams = ModelUtil.createTrainingParameters(params.getIterations(), params.getCutoff());
}
File modelOutFile = params.getModel();
CmdLineUtil.checkOutputFile("parser model", modelOutFile);
ParserModel model;
try {
// TODO hard-coded language reference
HeadRules rules = new opennlp.tools.parser.lang.en.HeadRules(
new InputStreamReader(new FileInputStream(params.getHeadRules()),
params.getEncoding()));
ParserType type = parseParserType(params.getParserType());
if(params.getFun()){
Parse.useFunctionTags(true);
}
if (ParserType.CHUNKING.equals(type)) {
model = opennlp.tools.parser.chunking.Parser.train(
params.getLang(), sampleStream, rules,
mlParams);
}
else if (ParserType.TREEINSERT.equals(type)) {
model = opennlp.tools.parser.treeinsert.Parser.train(params.getLang(), sampleStream, rules,
mlParams);
}
else {
throw new IllegalStateException();
}
}
catch (IOException e) {
throw new TerminateToolException(-1, "IO error while reading training data or indexing data: "
+ e.getMessage(), e);
}
finally {
try {
sampleStream.close();