ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1663414 - /ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java
Date Mon, 02 Mar 2015 20:11:30 GMT
Author: dligach
Date: Mon Mar  2 20:11:30 2015
New Revision: 1663414

URL: http://svn.apache.org/r1663414
Log:
added a static method to extract last word of an annotation

Modified:
    ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java

Modified: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java?rev=1663414&r1=1663413&r2=1663414&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java
(original)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/data/analysis/Utils.java
Mon Mar  2 20:11:30 2015
@@ -23,8 +23,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.ctakes.core.cr.XMIReader;
+import org.apache.ctakes.typesystem.type.syntax.WordToken;
 import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.fit.factory.CollectionReaderFactory;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
 
 /**
  * Various useful classes and methods.
@@ -51,4 +55,18 @@ public class Utils {
         XMIReader.PARAM_FILES,
         paths);
   }
+  
+  /**
+   * Given an annotation, retrieve its last word.
+   */
+  public static String getLastWord(JCas systemView, Annotation annotation) {
+    
+    List<WordToken> tokens = JCasUtil.selectCovered(systemView, WordToken.class, annotation);
+    if(tokens.size() == 0) {
+          return annotation.getCoveredText();
+    }
+    
+    WordToken lastToken = tokens.get(tokens.size() - 1);
+    return lastToken.getCoveredText();
+  }
 }



Mime
View raw message