ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1748290 - /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
Date Mon, 13 Jun 2016 17:55:25 GMT
Author: dligach
Date: Mon Jun 13 17:55:25 2016
New Revision: 1748290

URL: http://svn.apache.org/viewvc?rev=1748290&view=rev
Log:
added event markers for non-argument events

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=1748290&r1=1748289&r2=1748290&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
Mon Jun 13 17:55:25 2016
@@ -171,7 +171,6 @@ public class PositiveAndNegativeExampleP
               label = relation.getCategory().toLowerCase();
             }
 
-            // String context = getSentenceWithMarkedArgs(systemView, sentence, mention1,
mention2);
             String context = getTokensBetween(systemView, sentence, mention1, mention2, 2);
             String text = String.format("%s|%s", label, context);
             eventEventRelationsInSentence.add(text.toLowerCase());
@@ -213,29 +212,50 @@ 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, Sentence sent, Annotation arg1, Annotation
arg2, int contextSize) {
+  public static String getTokensBetween(JCas jCas, Sentence sent, Annotation arg1, Annotation
arg2, int contextSize) throws AnalysisEngineProcessException {
     
     List<String> tokens = new ArrayList<>();
     for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, arg1, contextSize))
{
       if(sent.getBegin() <= baseToken.getBegin()) {
-        tokens.add(baseToken.getCoveredText()); 
+        tokens.add(convertToString(jCas, baseToken)); 
       }
     }
     tokens.add("<e1>");
     tokens.add(arg1.getCoveredText());
     tokens.add("</e1>");
     for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, arg1, arg2))
{
-      tokens.add(baseToken.getCoveredText());
+      tokens.add(convertToString(jCas, baseToken));
     }
     tokens.add("<e2>");
     tokens.add(arg2.getCoveredText());
     tokens.add("</e2>");
     for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, arg2, contextSize))
{
       if(baseToken.getEnd() <= sent.getEnd()) {
-        tokens.add(baseToken.getCoveredText());
+        tokens.add(convertToString(jCas, baseToken));
       }
     }
     
     return String.join(" ", tokens).replaceAll("[\r\n]", " ");
   }
+  
+  /**
+   * If token is an event, add event markers. Otherwise, return as is.
+   * @param baseToken token to be considered
+   */
+  public static String convertToString(JCas jCas, BaseToken baseToken) throws AnalysisEngineProcessException
{
+    
+    JCas goldView;
+    try {
+      goldView = jCas.getView("GoldView");
+    } catch (CASException e) {
+      throw new AnalysisEngineProcessException(e);
+    }
+    
+    List<EventMention> events = JCasUtil.selectCovering(goldView, EventMention.class,
baseToken.getBegin(), baseToken.getEnd());
+    if(events.size() > 0) {
+      return "<e> " + baseToken.getCoveredText() + " </e>";
+    } else {
+      return baseToken.getCoveredText();
+    }
+  }
 }



Mime
View raw message