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 2018/05/30 13:31:03 UTC

[opennlp-sandbox] branch master updated: Implement the TokenNameFinder interface

This is an automated email from the ASF dual-hosted git repository.

joern pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git


The following commit(s) were added to refs/heads/master by this push:
     new 19d046d  Implement the TokenNameFinder interface
19d046d is described below

commit 19d046dd7700c8b10d4fb20b934e325e168bb04b
Author: Jörn Kottmann <jo...@apache.org>
AuthorDate: Wed May 30 15:29:04 2018 +0200

    Implement the TokenNameFinder interface
---
 .../tf/guillaumegenthial/SequenceTagging.java      | 28 ++++++++++++----------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/tf-ner-poc/src/main/java/org/apache/opennlp/tf/guillaumegenthial/SequenceTagging.java b/tf-ner-poc/src/main/java/org/apache/opennlp/tf/guillaumegenthial/SequenceTagging.java
index 637ccec..b30509d 100644
--- a/tf-ner-poc/src/main/java/org/apache/opennlp/tf/guillaumegenthial/SequenceTagging.java
+++ b/tf-ner-poc/src/main/java/org/apache/opennlp/tf/guillaumegenthial/SequenceTagging.java
@@ -17,18 +17,20 @@
 
 package org.apache.opennlp.tf.guillaumegenthial;
 
-import org.tensorflow.SavedModelBundle;
-import org.tensorflow.Session;
-import org.tensorflow.Tensor;
-
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
-import java.util.zip.GZIPInputStream;
 
-public class SequenceTagging implements AutoCloseable {
+import org.tensorflow.SavedModelBundle;
+import org.tensorflow.Session;
+import org.tensorflow.Tensor;
+
+import opennlp.tools.namefind.BioCodec;
+import opennlp.tools.namefind.TokenNameFinder;
+import opennlp.tools.util.Span;
 
+public class SequenceTagging implements TokenNameFinder, AutoCloseable {
   private final SavedModelBundle model;
   private final Session session;
   private final WordIndexer wordIndexer;
@@ -38,18 +40,16 @@ public class SequenceTagging implements AutoCloseable {
     model = SavedModelBundle.load(config.getSavedModel(), "serve");
     session = model.session();
 
-
-    Iterator<Operation> opit = model.graph().operations();
-
     this.wordIndexer = new WordIndexer(new FileInputStream(config.getVocabWords()),
             new FileInputStream(config.getVocabChars()));
 
     this.indexTagger = new IndexTagger((new FileInputStream(config.getVocabTags())));
   }
 
-  public String[] predict(String[] sentence) {
+  @Override
+  public Span[] find(String[] sentence) {
     TokenIds tokenIds = wordIndexer.toTokenIds(sentence);
-    return predict(tokenIds)[0];
+    return new BioCodec().decode(Arrays.asList(predict(tokenIds)[0]));
   }
 
   public String[][] predict(String[][] sentences) {
@@ -87,7 +87,11 @@ public class SequenceTagging implements AutoCloseable {
   }
 
   @Override
-  public void close() throws Exception {
+  public void clearAdaptiveData() {
+  }
+
+  @Override
+  public void close() {
     session.close();
   }
 }

-- 
To stop receiving notification emails like this one, please contact
joern@apache.org.