Author: dligach
Date: Mon Oct 17 14:34:09 2016
New Revision: 1765297

URL: http://svn.apache.org/viewvc?rev=1765297&view=rev
Log:
moved context printing methods to separate class

Added:
    
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
Modified:
    
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventEventCNNAnnotator.java
    
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
    
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java

Modified: 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventEventCNNAnnotator.java
URL: 
http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventEventCNNAnnotator.java?rev=1765297&r1=1765296&r2=1765297&view=diff
==============================================================================
--- 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventEventCNNAnnotator.java
 (original)
+++ 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventEventCNNAnnotator.java
 Mon Oct 17 14:34:09 2016
@@ -8,6 +8,7 @@ import java.util.List;
 import java.util.Map;
 
 import 
org.apache.ctakes.temporal.ae.TemporalRelationExtractorAnnotator.IdentifiedAnnotationPair;
+import org.apache.ctakes.temporal.nn.data.ArgContextProvider;
 import org.apache.ctakes.temporal.nn.data.EventEventRelPrinter;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.RelationArgument;
@@ -71,11 +72,11 @@ public class EventEventCNNAnnotator exte
                                String context;
                                if(arg2.getBegin() < arg1.getBegin()) {
                                        // ... time ... event ... scenario
-                                       context = 
EventEventRelPrinter.getTokensBetween(jCas, sentence, arg2, "e", arg1, "e", 5); 
+                                       context = 
ArgContextProvider.getTokensBetween(jCas, sentence, arg2, "e", arg1, "e", 5); 
 //                                     context = 
getTokensBetweenExpanded(jCas, sentence, arg2, "e", arg1, "e", 5, coveringMap);
                                } else {
                                        // ... event ... time ... scenario
-                                       context = 
EventEventRelPrinter.getTokensBetween(jCas, sentence, arg1, "e", arg2, "e", 5);
+                                       context = 
ArgContextProvider.getTokensBetween(jCas, sentence, arg1, "e", arg2, "e", 5);
 //                                     context = 
getTokensBetweenExpanded(jCas, sentence, arg1, "e", arg2, "e", 5, coveringMap);
                                }
 

Modified: 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
URL: 
http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java?rev=1765297&r1=1765296&r2=1765297&view=diff
==============================================================================
--- 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
 (original)
+++ 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
 Mon Oct 17 14:34:09 2016
@@ -8,7 +8,7 @@ import java.util.Map;
 import java.util.Random;
 
 import 
org.apache.ctakes.temporal.ae.TemporalRelationExtractorAnnotator.IdentifiedAnnotationPair;
-import org.apache.ctakes.temporal.nn.data.EventEventRelPrinter;
+import org.apache.ctakes.temporal.nn.data.ArgContextProvider;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.RelationArgument;
 import org.apache.ctakes.typesystem.type.relation.TemporalTextRelation;
@@ -69,10 +69,10 @@ public class EventEventTokenBasedAnnotat
         if(arg2.getBegin() < arg1.getBegin()) {
           // ... event2 ... event1 ... scenario
           System.out.println("\n-------------- THIS NEVER NAPPENS 
------------\n");
-          context = EventEventRelPrinter.getTokensBetween(jCas, sentence, 
arg2, "e2", arg1, "e1", 2); 
+          context = ArgContextProvider.getTokensBetween(jCas, sentence, arg2, 
"e2", arg1, "e1", 2); 
         } else {
           // ... event1 ... event2 ... scenario
-          context = EventEventRelPrinter.getTokensBetween(jCas, sentence, 
arg1, "e1", arg2, "e2", 2);
+          context = ArgContextProvider.getTokensBetween(jCas, sentence, arg1, 
"e1", arg2, "e2", 2);
         }
 
         //derive features based on context:

Added: 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
URL: 
http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java?rev=1765297&view=auto
==============================================================================
--- 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
 (added)
+++ 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
 Mon Oct 17 14:34:09 2016
@@ -0,0 +1,98 @@
+package org.apache.ctakes.temporal.nn.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+
+public class ArgContextProvider {
+  /**
+   * Return tokens between arg1 and arg2 as string 
+   * @param contextSize number of tokens to include on the left of arg1 and on 
the right of arg2
+   */
+  public static String getRegions(JCas jCas, Sentence sent, Annotation left, 
Annotation right, int contextSize) {
+
+    
+    // tokens to the left from the left argument
+    List<String> leftTokens = new ArrayList<>();
+    for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, 
left, contextSize)) {
+      if(sent.getBegin() <= baseToken.getBegin()) {
+        leftTokens.add(baseToken.getCoveredText()); 
+      }
+    }
+    String leftAsString = String.join(" ", leftTokens).replaceAll("[\r\n]", " 
");
+    
+    // left arg tokens
+    List<String> arg1Tokens = new ArrayList<>(); 
+    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, 
left)) {
+      arg1Tokens.add(baseToken.getCoveredText());
+    }
+    String arg1AsString = String.join(" ", arg1Tokens).replaceAll("[\r\n]", " 
");
+    
+    // tokens between the arguments
+    List<String> betweenTokens = new ArrayList<>();
+    for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, 
left, right)) {
+      betweenTokens.add(baseToken.getCoveredText());
+    }
+    String betweenAsString = String.join(" ", 
betweenTokens).replaceAll("[\r\n]", " ");
+    
+    // right arg tokens
+    List<String> arg2Tokens = new ArrayList<>(); 
+    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, 
right)) {
+      arg2Tokens.add(baseToken.getCoveredText());
+    }
+    String arg2AsString = String.join(" ", arg2Tokens).replaceAll("[\r\n]", " 
");
+    
+    // tokens to the right from the right argument
+    List<String> rightTokens = new ArrayList<>();
+    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, 
right, contextSize)) {
+      if(baseToken.getEnd() <= sent.getEnd()) {
+        rightTokens.add(baseToken.getCoveredText());
+      }
+    }
+    String rightAsString = String.join(" ", rightTokens).replaceAll("[\r\n]", 
" ");
+    
+    return leftAsString + "|" + arg1AsString + "|" + betweenAsString + "|" + 
arg2AsString + "|" + rightAsString;
+  }
+  
+  /**
+   * Return tokens between arg1 and arg2 as string 
+   * @param contextSize number of tokens to include on the left of arg1 and on 
the right of arg2
+   */
+  public static String getTokensBetween(
+      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.getCoveredText()); 
+      }
+    }
+    tokens.add("<" + leftType + ">");
+    tokens.add(left.getCoveredText());
+    tokens.add("</" + leftType + ">");
+    for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, 
left, right)) {
+      tokens.add(baseToken.getCoveredText());
+    }
+    tokens.add("<" + rightType + ">");
+    tokens.add(right.getCoveredText());
+    tokens.add("</" + rightType + ">");
+    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, 
right, contextSize)) {
+      if(baseToken.getEnd() <= sent.getEnd()) {
+        tokens.add(baseToken.getCoveredText());
+      }
+    }
+
+    return String.join(" ", tokens).replaceAll("[\r\n]", " ");
+  }
+}

Modified: 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
URL: 
http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java?rev=1765297&r1=1765296&r2=1765297&view=diff
==============================================================================
--- 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
 (original)
+++ 
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
 Mon Oct 17 14:34:09 2016
@@ -202,7 +202,7 @@ public class EventEventRelPrinter {
               continue; // skip this negative example
             }
             
-            String context = getRegions(systemView, sentence, mention1, 
mention2, 2);
+            String context = ArgContextProvider.getRegions(systemView, 
sentence, mention1, mention2, 2);
             // String context = getTokensBetween(systemView, sentence, 
mention1, "e1", mention2, "e2", 2);
             String text = String.format("%s|%s", label, context);
             eventEventRelationsInSentence.add(text.toLowerCase());
@@ -217,90 +217,4 @@ public class EventEventRelPrinter {
       }
     }
   }
-
-  /**
-   * Return tokens between arg1 and arg2 as string 
-   * @param contextSize number of tokens to include on the left of arg1 and on 
the right of arg2
-   */
-  public static String getRegions(JCas jCas, Sentence sent, Annotation left, 
Annotation right, int contextSize) {
-
-    
-    // tokens to the left from the left argument
-    List<String> leftTokens = new ArrayList<>();
-    for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, 
left, contextSize)) {
-      if(sent.getBegin() <= baseToken.getBegin()) {
-        leftTokens.add(baseToken.getCoveredText()); 
-      }
-    }
-    String leftAsString = String.join(" ", leftTokens).replaceAll("[\r\n]", " 
");
-    
-    // left arg tokens
-    List<String> arg1Tokens = new ArrayList<>(); 
-    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, 
left)) {
-      arg1Tokens.add(baseToken.getCoveredText());
-    }
-    String arg1AsString = String.join(" ", arg1Tokens).replaceAll("[\r\n]", " 
");
-    
-    // tokens between the arguments
-    List<String> betweenTokens = new ArrayList<>();
-    for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, 
left, right)) {
-      betweenTokens.add(baseToken.getCoveredText());
-    }
-    String betweenAsString = String.join(" ", 
betweenTokens).replaceAll("[\r\n]", " ");
-    
-    // right arg tokens
-    List<String> arg2Tokens = new ArrayList<>(); 
-    for(BaseToken baseToken : JCasUtil.selectCovered(jCas, BaseToken.class, 
right)) {
-      arg2Tokens.add(baseToken.getCoveredText());
-    }
-    String arg2AsString = String.join(" ", arg2Tokens).replaceAll("[\r\n]", " 
");
-    
-    // tokens to the right from the right argument
-    List<String> rightTokens = new ArrayList<>();
-    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, 
right, contextSize)) {
-      if(baseToken.getEnd() <= sent.getEnd()) {
-        rightTokens.add(baseToken.getCoveredText());
-      }
-    }
-    String rightAsString = String.join(" ", rightTokens).replaceAll("[\r\n]", 
" ");
-    
-    return leftAsString + "|" + arg1AsString + "|" + betweenAsString + "|" + 
arg2AsString + "|" + rightAsString;
-  }
-  
-  /**
-   * Return tokens between arg1 and arg2 as string 
-   * @param contextSize number of tokens to include on the left of arg1 and on 
the right of arg2
-   */
-  public static String getTokensBetween(
-      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.getCoveredText()); 
-      }
-    }
-    tokens.add("<" + leftType + ">");
-    tokens.add(left.getCoveredText());
-    tokens.add("</" + leftType + ">");
-    for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, 
left, right)) {
-      tokens.add(baseToken.getCoveredText());
-    }
-    tokens.add("<" + rightType + ">");
-    tokens.add(right.getCoveredText());
-    tokens.add("</" + rightType + ">");
-    for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, 
right, contextSize)) {
-      if(baseToken.getEnd() <= sent.getEnd()) {
-        tokens.add(baseToken.getCoveredText());
-      }
-    }
-
-    return String.join(" ", tokens).replaceAll("[\r\n]", " ");
-  }
 }


Reply via email to