ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1754794 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java
Date Mon, 01 Aug 2016 20:17:37 GMT
Author: dligach
Date: Mon Aug  1 20:17:36 2016
New Revision: 1754794

URL: http://svn.apache.org/viewvc?rev=1754794&view=rev
Log:
added a method to print pos sequences

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java?rev=1754794&r1=1754793&r2=1754794&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/DtrRelPrinter.java
Mon Aug  1 20:17:36 2016
@@ -43,6 +43,7 @@ import org.apache.uima.fit.factory.Analy
 import org.apache.uima.fit.pipeline.SimplePipeline;
 import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
 
 import com.lexicalscope.jewel.cli.CliFactory;
 import com.lexicalscope.jewel.cli.Option;
@@ -147,7 +148,7 @@ public class DtrRelPrinter {
         for(EventMention event : JCasUtil.selectCovered(goldView, EventMention.class, sentence))
{
           if(event.getEvent() != null) {
             String label = event.getEvent().getProperties().getDocTimeRel();
-            String context = getEventContext(systemView, sentence, event, "e", 10);
+            String context = getEventPosContext(systemView, sentence, event, "e", 10);
             String text = String.format("%s|%s", label, context);
             docTimeRelExamplesInSentence.add(text.toLowerCase());
           } else {
@@ -185,6 +186,32 @@ public class DtrRelPrinter {
       }
     }
     
+    return String.join(" ", tokens).replaceAll("[\r\n]", " ");
+  }
+  
+  /**
+   * Print context from left to right.
+   * @param contextSize number of tokens to include on the left of arg1 and on the right
of arg2
+   */
+  public static String getEventPosContext(JCas jCas, Sentence sent, EventMention event, String
marker, int contextSize) {
+    
+    List<String> tokens = new ArrayList<>();
+    for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, event, contextSize))
{
+      if(sent.getBegin() <= baseToken.getBegin()) {
+        tokens.add(baseToken.getPartOfSpeech()); 
+      }
+    }
+    tokens.add("<" + marker + ">");
+    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, event)) {
+      tokens.add(baseToken.getPartOfSpeech());
+    }
+    tokens.add("</" + marker + ">");
+    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, event, contextSize))
{
+      if(baseToken.getEnd() <= sent.getEnd()) {
+        tokens.add(baseToken.getPartOfSpeech());
+      }
+    }
+    
     return String.join(" ", tokens).replaceAll("[\r\n]", " ");
   }
 }



Mime
View raw message