Repository: opennlp
Updated Branches:
  refs/heads/master ac1e0fd30 -> 15ac7bd17


OPENNLP-1087: Add convenience methods to load from Path


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

Branch: refs/heads/master
Commit: 15ac7bd178a0f06e7a1fa18a85d3dee631bc7fc9
Parents: ac1e0fd
Author: Jörn Kottmann <[email protected]>
Authored: Thu Jun 1 00:17:57 2017 +0200
Committer: Jörn Kottmann <[email protected]>
Committed: Thu Jun 1 09:44:02 2017 +0200

----------------------------------------------------------------------
 .../opennlp/tools/chunker/ChunkerModel.java     |  5 +++++
 .../java/opennlp/tools/doccat/DoccatModel.java  |  5 +++++
 .../tools/lemmatizer/DictionaryLemmatizer.java  | 22 ++++++++++++++++----
 .../tools/lemmatizer/LemmatizerModel.java       |  5 +++++
 .../tools/namefind/TokenNameFinderModel.java    |  5 +++++
 .../java/opennlp/tools/parser/ParserModel.java  |  5 +++++
 .../java/opennlp/tools/postag/POSModel.java     |  5 +++++
 .../opennlp/tools/sentdetect/SentenceModel.java |  5 +++++
 .../opennlp/tools/tokenize/TokenizerModel.java  |  5 +++++
 9 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
index 12c8bbe..393c2fa 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.Properties;
 
@@ -80,6 +81,10 @@ public class ChunkerModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public ChunkerModel(Path modelPath) throws IOException, 
InvalidFormatException {
+    this(modelPath.toFile());
+  }
+
   public ChunkerModel(URL modelURL) throws IOException, InvalidFormatException 
{
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
index e71b625..1b5c164 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 
 import opennlp.tools.ml.model.AbstractModel;
@@ -53,6 +54,10 @@ public class DoccatModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public DoccatModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   public DoccatModel(URL modelURL) throws IOException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java
 
b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java
index 97d6854..b480ad1 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java
@@ -18,9 +18,12 @@
 package opennlp.tools.lemmatizer;
 
 import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -37,7 +40,7 @@ public class DictionaryLemmatizer implements Lemmatizer {
   /**
    * The hashmap containing the dictionary.
    */
-  private final Map<List<String>, List<String>> dictMap;
+  private final Map<List<String>, List<String>> dictMap = new HashMap<>();
 
   /**
    * Construct a hashmap from the input tab separated dictionary.
@@ -50,7 +53,20 @@ public class DictionaryLemmatizer implements Lemmatizer {
    *          the input dictionary via inputstream
    */
   public DictionaryLemmatizer(final InputStream dictionary) throws IOException 
{
-    this.dictMap = new HashMap<>();
+    init(dictionary);
+  }
+
+  public DictionaryLemmatizer(File dictionaryFile) throws IOException {
+    try (InputStream in = new FileInputStream(dictionaryFile)) {
+      init(in);
+    }
+  }
+
+  public DictionaryLemmatizer(Path dictionaryFile) throws IOException {
+    this(dictionaryFile.toFile());
+  }
+
+  private void init(InputStream dictionary) throws IOException {
     final BufferedReader breader = new BufferedReader(
         new InputStreamReader(dictionary));
     String line;
@@ -60,8 +76,6 @@ public class DictionaryLemmatizer implements Lemmatizer {
       this.dictMap.put(Arrays.asList(elems[0], elems[1]), 
Arrays.asList(lemmas));
     }
   }
-
-
   /**
    * Get the Map containing the dictionary.
    *

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
index 2f5f6ef..cb11e8b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.Properties;
 
@@ -77,6 +78,10 @@ public class LemmatizerModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public LemmatizerModel(Path modelPath) throws IOException, 
InvalidFormatException {
+    this(modelPath.toFile());
+  }
+
   public LemmatizerModel(URL modelURL) throws IOException, 
InvalidFormatException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
index 5b72449..98dad06 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.Properties;
 
@@ -107,6 +108,10 @@ public class TokenNameFinderModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public TokenNameFinderModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   public TokenNameFinderModel(URL modelURL) throws IOException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
index c290d9f..86ea2f0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.Objects;
 
@@ -133,6 +134,10 @@ public class ParserModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public ParserModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   public ParserModel(URL modelURL) throws IOException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
index f81092b..95a41a8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
@@ -98,6 +99,10 @@ public final class POSModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public POSModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   public POSModel(URL modelURL) throws IOException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
index a716210..e8df1d6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 
 import opennlp.tools.dictionary.Dictionary;
@@ -95,6 +96,10 @@ public class SentenceModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public SentenceModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   public SentenceModel(URL modelURL) throws IOException {
     super(COMPONENT_NAME, modelURL);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/15ac7bd1/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java 
b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
index 04db0ce..1db7c49 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Map;
 
 import opennlp.tools.dictionary.Dictionary;
@@ -81,6 +82,10 @@ public final class TokenizerModel extends BaseModel {
     super(COMPONENT_NAME, modelFile);
   }
 
+  public TokenizerModel(Path modelPath) throws IOException {
+    this(modelPath.toFile());
+  }
+
   /**
    * Initializes the current instance.
    *

Reply via email to