You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2016/11/11 00:58:51 UTC

opennlp git commit: Remove references to PlainTextByLineStream constructor that takes FileChannel

Repository: opennlp
Updated Branches:
  refs/heads/trunk 4a4b591f0 -> c28a54208


Remove references to PlainTextByLineStream constructor that takes FileChannel

The PlainTextByLineStream that takes FileChannel was deprecated. We can remove safely remove it after reviewing internal code that was still using it.

There still deprecated methods that are using the constructors, but it will handled in another issue. After that we are save to permanently remove the deprecated methods from PlainTextByLineStream.

See issue OPENNLP-882


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/c28a5420
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/c28a5420
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/c28a5420

Branch: refs/heads/trunk
Commit: c28a5420822f5a704d080c4169434a12fa707a87
Parents: 4a4b591
Author: William Colen <wi...@gmail.com>
Authored: Thu Nov 10 22:58:37 2016 -0200
Committer: William Colen <wi...@gmail.com>
Committed: Thu Nov 10 22:58:37 2016 -0200

----------------------------------------------------------------------
 .../DictionaryNameFinderEvaluatorTest.java      | 20 ++++++++--------
 .../TokenNameFinderCrossValidatorTest.java      | 25 ++++++++++----------
 2 files changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/c28a5420/opennlp-tools/src/test/java/opennlp/tools/namefind/DictionaryNameFinderEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/DictionaryNameFinderEvaluatorTest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/DictionaryNameFinderEvaluatorTest.java
index 0b5b6ab..2150de7 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/namefind/DictionaryNameFinderEvaluatorTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/DictionaryNameFinderEvaluatorTest.java
@@ -17,25 +17,26 @@
 
 package opennlp.tools.namefind;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.junit.Test;
+
 import opennlp.tools.cmdline.namefind.NameEvaluationErrorListener;
 import opennlp.tools.dictionary.Dictionary;
+import opennlp.tools.formats.ResourceAsStreamFactory;
+import opennlp.tools.util.InputStreamFactory;
 import opennlp.tools.util.ObjectStream;
 import opennlp.tools.util.PlainTextByLineStream;
 import opennlp.tools.util.Span;
 import opennlp.tools.util.StringList;
 import opennlp.tools.util.eval.FMeasure;
 
-import org.junit.Test;
-
 /**
  * Tests the evaluation of a {@link DictionaryNameFinder}.
  */
@@ -66,13 +67,12 @@ public class DictionaryNameFinderEvaluatorTest {
    */
   private static ObjectStream<NameSample> createSample() throws IOException,
       URISyntaxException {
-    FileInputStream sampleDataIn = new FileInputStream(new File(
-        DictionaryNameFinderEvaluatorTest.class.getClassLoader()
-            .getResource("opennlp/tools/namefind/AnnotatedSentences.txt")
-            .toURI()));
+    
+    InputStreamFactory in = new ResourceAsStreamFactory(
+        DictionaryNameFinderEvaluatorTest.class,
+        "/opennlp/tools/namefind/AnnotatedSentences.txt");
 
-    return new NameSampleDataStream(new PlainTextByLineStream(
-        sampleDataIn.getChannel(), "ISO-8859-1"));
+    return new NameSampleDataStream(new PlainTextByLineStream(in, ISO_8859_1));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/opennlp/blob/c28a5420/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderCrossValidatorTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderCrossValidatorTest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderCrossValidatorTest.java
index 132264e..22567ee 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderCrossValidatorTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderCrossValidatorTest.java
@@ -17,23 +17,24 @@
 
 package opennlp.tools.namefind;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
 import java.util.Collections;
 import java.util.Map;
 
+import org.junit.Test;
+
 import opennlp.tools.cmdline.namefind.NameEvaluationErrorListener;
+import opennlp.tools.formats.ResourceAsStreamFactory;
+import opennlp.tools.util.InputStreamFactory;
 import opennlp.tools.util.ObjectStream;
 import opennlp.tools.util.PlainTextByLineStream;
 import opennlp.tools.util.TrainingParameters;
 import opennlp.tools.util.model.ModelType;
 
-import org.junit.Test;
-
 public class TokenNameFinderCrossValidatorTest {
 
   private final String TYPE = null;
@@ -44,12 +45,11 @@ public class TokenNameFinderCrossValidatorTest {
    */
   public void testWithNullResources() throws Exception {
 
-    FileInputStream sampleDataIn = new FileInputStream(new File(getClass()
-        .getClassLoader()
-        .getResource("opennlp/tools/namefind/AnnotatedSentences.txt").toURI()));
+    InputStreamFactory in = new ResourceAsStreamFactory(getClass(),
+        "/opennlp/tools/namefind/AnnotatedSentences.txt");
 
     ObjectStream<NameSample> sampleStream = new NameSampleDataStream(
-        new PlainTextByLineStream(sampleDataIn.getChannel(), "ISO-8859-1"));
+        new PlainTextByLineStream(in, ISO_8859_1));
 
     TrainingParameters mlParams = new TrainingParameters();
     mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(70));
@@ -59,7 +59,7 @@ public class TokenNameFinderCrossValidatorTest {
         ModelType.MAXENT.toString());
 
     TokenNameFinderCrossValidator cv = new TokenNameFinderCrossValidator("en",
-        TYPE, mlParams, null, null);
+        TYPE, mlParams, null, (TokenNameFinderEvaluationMonitor)null);
 
     cv.evaluate(sampleStream, 2);
 
@@ -72,12 +72,11 @@ public class TokenNameFinderCrossValidatorTest {
    */
   public void testWithNameEvaluationErrorListener() throws Exception {
 
-    FileInputStream sampleDataIn = new FileInputStream(new File(getClass()
-        .getClassLoader()
-        .getResource("opennlp/tools/namefind/AnnotatedSentences.txt").toURI()));
+    InputStreamFactory in = new ResourceAsStreamFactory(getClass(),
+        "/opennlp/tools/namefind/AnnotatedSentences.txt");
 
     ObjectStream<NameSample> sampleStream = new NameSampleDataStream(
-        new PlainTextByLineStream(sampleDataIn.getChannel(), "ISO-8859-1"));
+        new PlainTextByLineStream(in, ISO_8859_1));
 
     TrainingParameters mlParams = new TrainingParameters();
     mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(70));