ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1754146 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eventTimeRelationPrinter.java
Date Tue, 26 Jul 2016 15:40:51 GMT
Author: dligach
Date: Tue Jul 26 15:40:51 2016
New Revision: 1754146

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

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

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eventTimeRelationPrinter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eventTimeRelationPrinter.java?rev=1754146&r1=1754145&r2=1754146&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eventTimeRelationPrinter.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eventTimeRelationPrinter.java
Tue Jul 26 15:40:51 2016
@@ -29,7 +29,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 
 import org.apache.ctakes.temporal.duration.Utils;
 import org.apache.ctakes.temporal.eval.CommandLine;
@@ -199,10 +198,10 @@ public class eventTimeRelationPrinter {
             String context;
             if(time.getBegin() < event.getBegin()) {
               // ... time ... event ... scenario
-              context = getTokensBetween(systemView, sentence, time, "t", event, "e", 2);
 
+              context = getTokenContext(systemView, sentence, time, "t", event, "e", 2);
 
             } else {
               // ... event ... time ... scenario
-              context = getTokensBetween(systemView, sentence, event, "e", time, "t", 2);
+              context = getTokenContext(systemView, sentence, event, "e", time, "t", 2);
             }
             
             String text = String.format("%s|%s", label, context);
@@ -220,10 +219,10 @@ public class eventTimeRelationPrinter {
   }
 
   /**
-   * Print context from left to right.
+   * Print words 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 getTokensBetween(
+  public static String getTokenContext(
       JCas jCas, 
       Sentence sent, 
       Annotation left,
@@ -253,6 +252,47 @@ public class eventTimeRelationPrinter {
       }
     }
 
+    return String.join(" ", tokens).replaceAll("[\r\n]", " ");
+  }
+  
+  /**
+   * Print POS tags 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 getPosContext(
+      JCas jCas, 
+      Sentence sent, 
+      Annotation left,
+      String leftType,
+      Annotation right,
+      String rightType,
+      int contextSize) {
+
+    List<String> tokens = new ArrayList<>();
+    for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, left, contextSize))
{
+      if(sent.getBegin() <= baseToken.getBegin()) {
+        tokens.add(baseToken.getPartOfSpeech()); 
+      }
+    }
+    tokens.add("<" + leftType + ">");
+    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, left)) {
+      tokens.add(baseToken.getPartOfSpeech());
+    }
+    tokens.add("</" + leftType + ">");
+    for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, left, right))
{
+      tokens.add(baseToken.getPartOfSpeech());
+    }
+    tokens.add("<" + rightType + ">");
+    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, right)) {
+      tokens.add(baseToken.getPartOfSpeech());
+    }
+    tokens.add("</" + rightType + ">");
+    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, right, contextSize))
{
+      if(baseToken.getEnd() <= sent.getEnd()) {
+        tokens.add(baseToken.getPartOfSpeech());
+      }
+    }
+
     return String.join(" ", tokens).replaceAll("[\r\n]", " ");
   }
 }



Mime
View raw message