Skip to content

Commit 4c45437

Browse files
authored
OPENNLP-1546 NER training code example in documentation needs updated (#595)
- adjusts NER training code example to be complete and consistent with 2.x
1 parent 71f8d45 commit 4c45437

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: opennlp-docs/src/docbkx/namefinder.xml

+8-6
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,19 @@ $ opennlp TokenNameFinderTrainer -featuregen brown.xml -sequenceCodec BILOU -res
288288
The three steps are illustrated by the following sample code:
289289
<programlisting language="java">
290290
<![CDATA[
291+
TokenNameFinderFactory factory = TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec());
292+
File trainingFile = new File("en-ner-person.train");
291293
ObjectStream<String> lineStream =
292-
new PlainTextByLineStream(new MarkableFileInputStreamFactory(new File("en-ner-person.train")), StandardCharsets.UTF_8);
293-
294-
TokenNameFinderModel model;
294+
new PlainTextByLineStream(new MarkableFileInputStreamFactory(trainingFile), StandardCharsets.UTF_8);
295295
296+
TokenNameFinderModel trainedModel;
296297
try (ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream)) {
297-
model = NameFinderME.train("eng", "person", sampleStream, TrainingParameters.defaultParams(), nameFinderFactory);
298+
trainedModel = NameFinderME.train("eng", "person", sampleStream, TrainingParameters.defaultParams(), factory);
298299
}
299300
300-
try (ObjectStream modelOut = new BufferedOutputStream(new FileOutputStream(modelFile)){
301-
model.serialize(modelOut);
301+
File modelFile = new File("en-ner-person.bin");
302+
try (OutputStream modelOut = new BufferedOutputStream(new FileOutputStream(modelFile))) {
303+
trainedModel.serialize(modelOut);
302304
}]]>
303305
</programlisting>
304306
</para>

0 commit comments

Comments
 (0)