You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/07/11 14:49:53 UTC
svn commit: r1145153 -
/incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml
Author: joern
Date: Mon Jul 11 12:49:52 2011
New Revision: 1145153
URL: http://svn.apache.org/viewvc?rev=1145153&view=rev
Log:
OPENNLP-115 Enhanced stream handling in training sample code
Modified:
incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml
Modified: incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml?rev=1145153&r1=1145152&r2=1145153&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml (original)
+++ incubator/opennlp/trunk/opennlp-docs/src/docbkx/namefinder.xml Mon Jul 11 12:49:52 2011
@@ -243,12 +243,20 @@ $bin/opennlp TokenNameFinderTrainer -enc
The three steps are illustrated by the following sample code:
<programlisting language="java">
<![CDATA[
+Charset charset = Charset.forName("UTF-8");
ObjectStream<String> lineStream =
- new PlainTextByLineStream(new FileInputStream("en-ner-person.train"), "UTF-8");
+ new PlainTextByLineStream(new FileInputStream("en-ner-person.train"), charset);
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream);
-TokenNameFinderModel model = NameFinderME.train("en", "person", sampleStream,
- Collections.<String, Object>emptyMap(), 100, 5);
+TokenNameFinderModel model;
+
+try {
+ model = NameFinderME.train("en", "person", sampleStream,
+ Collections.<String, Object>emptyMap(), 100, 5);
+}
+finally {
+ sampleStream.close();
+}
try {
modelOut = new BufferedOutputStream(new FileOutputStream(modelFile));