ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1765301 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/ nn/ae/ nn/data/
Date Mon, 17 Oct 2016 14:58:10 GMT
Author: dligach
Date: Mon Oct 17 14:58:10 2016
New Revision: 1765301

URL: http://svn.apache.org/viewvc?rev=1765301&view=rev
Log:
moved all arg context printers to single place

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/ae/EventTimePosBasedAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenAndPosBasedAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenBasedAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventTimeRelPrinter.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=1765301&r1=1765300&r2=1765301&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:58:10 2016
@@ -9,7 +9,6 @@ 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;
 import org.apache.ctakes.typesystem.type.relation.TemporalTextRelation;
@@ -72,11 +71,11 @@ public class EventEventCNNAnnotator exte
 				String context;
 				if(arg2.getBegin() < arg1.getBegin()) {
 					// ... time ... event ... scenario
-					context = ArgContextProvider.getTokensBetween(jCas, sentence, arg2, "e", arg1, "e",
5); 
+					context = ArgContextProvider.getTokenContext(jCas, sentence, arg2, "e", arg1, "e", 5);

 //					context = getTokensBetweenExpanded(jCas, sentence, arg2, "e", arg1, "e", 5, coveringMap);
 				} else {
 					// ... event ... time ... scenario
-					context = ArgContextProvider.getTokensBetween(jCas, sentence, arg1, "e", arg2, "e",
5);
+					context = ArgContextProvider.getTokenContext(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=1765301&r1=1765300&r2=1765301&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:58:10 2016
@@ -69,10 +69,10 @@ public class EventEventTokenBasedAnnotat
         if(arg2.getBegin() < arg1.getBegin()) {
           // ... event2 ... event1 ... scenario
           System.out.println("\n-------------- THIS NEVER NAPPENS ------------\n");
-          context = ArgContextProvider.getTokensBetween(jCas, sentence, arg2, "e2", arg1,
"e1", 2); 
+          context = ArgContextProvider.getTokenContext(jCas, sentence, arg2, "e2", arg1,
"e1", 2); 
         } else {
           // ... event1 ... event2 ... scenario
-          context = ArgContextProvider.getTokensBetween(jCas, sentence, arg1, "e1", arg2,
"e2", 2);
+          context = ArgContextProvider.getTokenContext(jCas, sentence, arg1, "e1", arg2,
"e2", 2);
         }
 
         //derive features based on context:

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimePosBasedAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimePosBasedAnnotator.java?rev=1765301&r1=1765300&r2=1765301&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimePosBasedAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimePosBasedAnnotator.java
Mon Oct 17 14:58:10 2016
@@ -7,7 +7,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.ctakes.temporal.ae.TemporalRelationExtractorAnnotator.IdentifiedAnnotationPair;
-import org.apache.ctakes.temporal.nn.data.EventTimeRelPrinter;
+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;
@@ -71,10 +71,10 @@ public class EventTimePosBasedAnnotator
         String context;
         if (arg2.getBegin() < arg1.getBegin()) {
           // ... time ... event ... scenario
-          context = EventTimeRelPrinter.getPosContext(jCas, sentence, arg2, "t", arg1, "e",
2);
+          context = ArgContextProvider.getPosContext(jCas, sentence, arg2, "t", arg1, "e",
2);
         } else {
           // ... event ... time ... scenario
-          context = EventTimeRelPrinter.getPosContext(jCas, sentence, arg1, "e", arg2, "t",
2);
+          context = ArgContextProvider.getPosContext(jCas, sentence, arg1, "e", arg2, "t",
2);
         }
 
         // derive features based on context

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenAndPosBasedAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenAndPosBasedAnnotator.java?rev=1765301&r1=1765300&r2=1765301&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenAndPosBasedAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenAndPosBasedAnnotator.java
Mon Oct 17 14:58:10 2016
@@ -8,7 +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.EventTimeRelPrinter;
+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;
@@ -74,12 +74,12 @@ public class EventTimeTokenAndPosBasedAn
         String posContext;
         if(arg2.getBegin() < arg1.getBegin()) {
           // ... time ... event ... scenario
-          tokenContext = EventTimeRelPrinter.getTokenContext(jCas, sentence, arg2, "t", arg1,
"e", 2);
-          posContext = EventTimeRelPrinter.getPosContext(jCas, sentence, arg2, "t", arg1,
"e", 2);
+          tokenContext = ArgContextProvider.getTokenContext(jCas, sentence, arg2, "t", arg1,
"e", 2);
+          posContext = ArgContextProvider.getPosContext(jCas, sentence, arg2, "t", arg1,
"e", 2);
         } else {
           // ... event ... time ... scenario
-          tokenContext = EventTimeRelPrinter.getTokenContext(jCas, sentence, arg1, "e", arg2,
"t", 2);
-          posContext = EventTimeRelPrinter.getPosContext(jCas, sentence, arg1, "e", arg2,
"t", 2);
+          tokenContext = ArgContextProvider.getTokenContext(jCas, sentence, arg1, "e", arg2,
"t", 2);
+          posContext = ArgContextProvider.getPosContext(jCas, sentence, arg1, "e", arg2,
"t", 2);
         }
 
         //derive features based on context:

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenBasedAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenBasedAnnotator.java?rev=1765301&r1=1765300&r2=1765301&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenBasedAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventTimeTokenBasedAnnotator.java
Mon Oct 17 14:58:10 2016
@@ -7,7 +7,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.ctakes.temporal.ae.TemporalRelationExtractorAnnotator.IdentifiedAnnotationPair;
-import org.apache.ctakes.temporal.nn.data.EventTimeRelPrinter;
+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;
@@ -71,10 +71,10 @@ public class EventTimeTokenBasedAnnotato
         String context;
         if(arg2.getBegin() < arg1.getBegin()) {
           // ... time ... event ... scenario
-          context = EventTimeRelPrinter.getTokenContext(jCas, sentence, arg2, "t", arg1,
"e", 2);
+          context = ArgContextProvider.getTokenContext(jCas, sentence, arg2, "t", arg1, "e",
2);
         } else {
           // ... event ... time ... scenario
-          context = EventTimeRelPrinter.getTokenContext(jCas, sentence, arg1, "e", arg2,
"t", 2);
+          context = ArgContextProvider.getTokenContext(jCas, sentence, arg1, "e", arg2, "t",
2);
         }
 
         // derive features based on context

Modified: 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=1765301&r1=1765300&r2=1765301&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/ArgContextProvider.java
Mon Oct 17 14:58:10 2016
@@ -60,10 +60,10 @@ public class ArgContextProvider {
   }
   
   /**
-   * Return tokens between arg1 and arg2 as string 
+   * 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,
@@ -93,6 +93,47 @@ public class ArgContextProvider {
       }
     }
 
+    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]", " ");
   }
 }

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=1765301&r1=1765300&r2=1765301&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:58:10 2016
@@ -34,7 +34,6 @@ import org.apache.ctakes.temporal.durati
 import org.apache.ctakes.temporal.eval.CommandLine;
 import org.apache.ctakes.temporal.eval.THYMEData;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
-import org.apache.ctakes.typesystem.type.syntax.BaseToken;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.uima.analysis_engine.AnalysisEngine;
@@ -202,8 +201,9 @@ public class EventEventRelPrinter {
               continue; // skip this negative example
             }
             
-            String context = ArgContextProvider.getRegions(systemView, sentence, mention1,
mention2, 2);
-            // String context = getTokensBetween(systemView, sentence, mention1, "e1", mention2,
"e2", 2);
+            String context = ArgContextProvider.getTokenContext(systemView, sentence, mention1,
"e1", mention2, "e2", 2);
+            // String context = ArgContextProvider.getRegions(systemView, sentence, mention1,
mention2, 2);
+            
             String text = String.format("%s|%s", label, context);
             eventEventRelationsInSentence.add(text.toLowerCase());
           }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventTimeRelPrinter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventTimeRelPrinter.java?rev=1765301&r1=1765300&r2=1765301&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventTimeRelPrinter.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventTimeRelPrinter.java
Mon Oct 17 14:58:10 2016
@@ -35,7 +35,6 @@ import org.apache.ctakes.temporal.eval.C
 import org.apache.ctakes.temporal.eval.THYMEData;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.TemporalTextRelation;
-import org.apache.ctakes.typesystem.type.syntax.BaseToken;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textsem.TimeMention;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
@@ -211,10 +210,10 @@ public class EventTimeRelPrinter {
             String context;
             if(time.getBegin() < event.getBegin()) {
               // ... time ... event ... scenario
-              context = getTokenContext(systemView, sentence, time, "t", event, "e", 2);
 
+              context = ArgContextProvider.getTokenContext(systemView, sentence, time, "t",
event, "e", 2);  
             } else {
               // ... event ... time ... scenario
-              context = getTokenContext(systemView, sentence, event, "e", time, "t", 2);
+              context = ArgContextProvider.getTokenContext(systemView, sentence, event, "e",
time, "t", 2);
             }
 
             String text = String.format("%s|%s", label, context);
@@ -230,82 +229,4 @@ public class EventTimeRelPrinter {
       }
     }
   }
-
-  /**
-   * 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 getTokenContext(
-      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]", " ");
-  }
-
-  /**
-   * 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