ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1746740 - /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
Date Fri, 03 Jun 2016 17:08:31 GMT
Author: dligach
Date: Fri Jun  3 17:08:31 2016
New Revision: 1746740

URL: http://svn.apache.org/viewvc?rev=1746740&view=rev
Log:
made sure context before/after arg1/arg2 does not cross sentence boundaries

Modified:
    ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java

Modified: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java?rev=1746740&r1=1746739&r2=1746740&view=diff
==============================================================================
--- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
(original)
+++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
Fri Jun  3 17:08:31 2016
@@ -148,6 +148,7 @@ public class PositiveAndNegativeExampleP
         relationLookup.put(Arrays.asList(arg1, arg2), relation);
       }
 
+      // go over sentences, extracting event-event relation instances
       for(Sentence sentence : JCasUtil.select(systemView, Sentence.class)) {
         List<String> eventEventRelationsInSentence = new ArrayList<>();
         List<EventMention> eventMentionsInSentence = JCasUtil.selectCovered(goldView,
EventMention.class, sentence);
@@ -171,7 +172,7 @@ public class PositiveAndNegativeExampleP
             }
 
             // String context = getSentenceWithMarkedArgs(systemView, sentence, mention1,
mention2);
-            String context = getTokensBetween(systemView, mention1, mention2, 0);
+            String context = getTokensBetween(systemView, sentence, mention1, mention2, 2);
             String text = String.format("%s|%s", label, context);
             eventEventRelationsInSentence.add(text.toLowerCase());
           }
@@ -212,11 +213,13 @@ public class PositiveAndNegativeExampleP
    * 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, Annotation arg1, Annotation arg2, int
contextSize) {
+  public static String getTokensBetween(JCas jCas, Sentence sent, Annotation arg1, Annotation
arg2, int contextSize) {
     
     List<String> tokens = new ArrayList<>();
     for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, arg1, contextSize))
{
-      tokens.add(baseToken.getCoveredText());
+      if(sent.getBegin() <= baseToken.getBegin()) {
+        tokens.add(baseToken.getCoveredText()); 
+      }
     }
     tokens.add(arg1.getCoveredText());
     for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, arg1, arg2))
{
@@ -224,7 +227,9 @@ public class PositiveAndNegativeExampleP
     }
     tokens.add(arg2.getCoveredText());
     for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, arg2, contextSize))
{
-      tokens.add(baseToken.getCoveredText());
+      if(baseToken.getEnd() <= sent.getEnd()) {
+        tokens.add(baseToken.getCoveredText());
+      }
     }
     
     return String.join(" ", tokens).replaceAll("[\r\n]", " ");



Mime
View raw message