Parser extends AbstractBottomUpParser { public static ParserModel train(String languageCode, ObjectStream<Parse> parseSamples, HeadRules rules, TrainingParameters mlParams) throws IOException { Map<String, String> manifestInfoEntries = new HashMap<String, String>(); System.err.println("Building dictionary"); Dictionary mdict = buildDictionary(parseSamples, rules, mlParams); parseSamples.reset(); POSModel posModel = POSTaggerME.train(languageCode, new PosSampleStream( parseSamples), mlParams.getParameters("tagger"), null, null); parseSamples.reset(); ChunkerModel chunkModel = ChunkerME.train(languageCode, new ChunkSampleStream( parseSamples), new ChunkContextGenerator(), mlParams.getParameters("chunker")); parseSamples.reset(); System.err.println("Training builder"); opennlp.model.EventStream bes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.BUILD, mdict); Map<String, String> buildReportMap = new HashMap<String, String>(); AbstractModel buildModel = TrainUtil.train(bes, mlParams.getSettings("build"), buildReportMap); opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, buildReportMap, "build"); parseSamples.reset(); System.err.println("Training checker"); opennlp.model.EventStream kes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.CHECK); Map<String, String> checkReportMap = new HashMap<String, String>(); AbstractModel checkModel = TrainUtil.train(kes, mlParams.getSettings("check"), checkReportMap); opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, checkReportMap, "check"); parseSamples.reset(); System.err.println("Training attacher"); opennlp.model.EventStream attachEvents = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.ATTACH); Map<String, String> attachReportMap = new HashMap<String, String>(); AbstractModel attachModel = TrainUtil.train(attachEvents, mlParams.getSettings("attach"), attachReportMap); opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, attachReportMap, "attach"); return new ParserModel(languageCode, buildModel, checkModel, attachModel, posModel, chunkModel, (opennlp.tools.parser.lang.en.HeadRules) rules, ParserType.TREEINSERT, manifestInfoEntries); } Parser(ParserModel model, int beamSize, double advancePercentage);  Parser(ParserModel model); @Deprecated  Parser(AbstractModel buildModel, AbstractModel attachModel, AbstractModel checkModel, POSTagger tagger, Chunker chunker, HeadRules headRules, int beamSize, double advancePercentage); @Deprecated  Parser(AbstractModel buildModel, AbstractModel attachModel, AbstractModel checkModel, POSTagger tagger, Chunker chunker, HeadRules headRules); static List<Parse> getRightFrontier(Parse root,Set<String> punctSet); static ParserModel train(String languageCode,
      ObjectStream<Parse> parseSamples, HeadRules rules, TrainingParameters mlParams); static ParserModel train(String languageCode,
      ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cut); @Deprecated static AbstractModel train(opennlp.model.EventStream es, int iterations, int cut); static final String DONE; static final String ATTACH_SISTER; static final String ATTACH_DAUGHTER; static final String NON_ATTACH; static final String BUILT; }
@Test public void testTreeInsertParserTraining() throws Exception { ObjectStream<Parse> parseSamples = ParserTestUtil.openTestTrainingData(); HeadRules headRules = ParserTestUtil.createTestHeadRules(); ParserModel model = Parser.train("en", parseSamples, headRules, 100, 0); opennlp.tools.parser.Parser parser = ParserFactory.create(model); parser.parse(Parse.parseParse("She was just another freighter from the " + "States and she seemed as commonplace as her name .")); ByteArrayOutputStream outArray = new ByteArrayOutputStream(); model.serialize(outArray); outArray.close(); new ParserModel(new ByteArrayInputStream(outArray.toByteArray())); }