ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1743695 - /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
Date Fri, 13 May 2016 16:16:35 GMT
Author: dligach
Date: Fri May 13 16:16:35 2016
New Revision: 1743695

URL: http://svn.apache.org/viewvc?rev=1743695&view=rev
Log:
marking events in printed sentence

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=1743695&r1=1743694&r2=1743695&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 May 13 16:16:35 2016
@@ -18,10 +18,7 @@
  */
 package org.apache.ctakes.pipelines;
 
-import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -39,13 +36,12 @@ import org.apache.uima.analysis_engine.A
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.tcas.Annotation;
-import org.cleartk.util.ViewUriUtil;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.fit.pipeline.SimplePipeline;
 import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
 
 import com.lexicalscope.jewel.cli.CliFactory;
 import com.lexicalscope.jewel.cli.Option;
@@ -76,7 +72,7 @@ public class PositiveAndNegativeExampleP
     CollectionReader collectionReader = Utils.getCollectionReader(trainFiles);
 
     AnalysisEngine annotationConsumer = AnalysisEngineFactory.createEngine(
-        RelationContextPrinter.class);
+        RelationSnippetPrinter.class);
 
     SimplePipeline.runPipeline(collectionReader, annotationConsumer);
   }
@@ -86,7 +82,7 @@ public class PositiveAndNegativeExampleP
    * 
    * @author dmitriy dligach
    */
-  public static class RelationContextPrinter extends JCasAnnotator_ImplBase {
+  public static class RelationSnippetPrinter extends JCasAnnotator_ImplBase {
 
     @Override
     public void process(JCas jCas) throws AnalysisEngineProcessException {
@@ -114,32 +110,10 @@ public class PositiveAndNegativeExampleP
         relationLookup.put(Arrays.asList(arg1, arg2), relation);
       }
 
-      File noteFile = new File(ViewUriUtil.getURI(jCas).toString());
-      String fileName = noteFile.getName();
-
       for(Sentence sentence : JCasUtil.select(systemView, Sentence.class)) {
-        List<String> formattedRelationsInSentence = new ArrayList<>();
+        List<String> eventEventRelationsInSentence = new ArrayList<>();
         List<EventMention> eventMentionsInSentence = JCasUtil.selectCovered(goldView,
EventMention.class, sentence);
-        List<TimeMention> timeMentionsInSentence = JCasUtil.selectCovered(goldView,
TimeMention.class, sentence);
-
-        // retrieve event-time relations in this sentece
-        for(EventMention eventMention : eventMentionsInSentence) {
-          for(TimeMention timeMention : timeMentionsInSentence) {
-            // there are relations where arg1=time and arg2=event
-            BinaryTextRelation timeEventRel = relationLookup.get(Arrays.asList(timeMention,
eventMention));
-            if(timeEventRel != null) {
-              String text = String.format("%s(%s, %s)", timeEventRel.getCategory(), timeMention.getCoveredText(),
eventMention.getCoveredText());
-              // formattedRelationsInSentence.add(text);
-            } 
-            // and relations where arg1=event and arg2=time
-            BinaryTextRelation eventTimeRel = relationLookup.get(Arrays.asList(eventMention,
timeMention));
-            if(eventTimeRel != null) {
-              String text = String.format("%s(%s, %s)", eventTimeRel.getCategory(), eventMention.getCoveredText(),
timeMention.getCoveredText());
-              // formattedRelationsInSentence.add(text);
-            }
-          }
-        }
-        // TODO: in sentence or in entire document?
+        
         // retrieve event-event relations in this sentence
         for(EventMention mention1 : eventMentionsInSentence) {
           for(EventMention mention2 : eventMentionsInSentence) {
@@ -153,34 +127,46 @@ public class PositiveAndNegativeExampleP
               label = "0";    // no relation
             } else if(relation.getCategory().equals("CONTAINS")) {
               if(mention1.getBegin() < mention2.getBegin()) {
-                label = "1";  // forward relation
+                label = "1";  // arg1 left of arg2
               } else { 
-                label = "-1"; // reverse relation
+                label = "0"; // arg2 left of arg1; IGNORE THOSE FOR NOW
               }
             } else {    
               label = "0";    // non-contains relation
             }
-            
+
             String context = getTextBetweenAnnotations(systemView, mention1, mention2); 
             String text = String.format("%s|%s|%s|%s", 
                 label,
                 mention1.getCoveredText(), 
                 mention2.getCoveredText(), 
                 context);
-            formattedRelationsInSentence.add(text);
+            eventEventRelationsInSentence.add(text);
           }
         }
 
-        if(formattedRelationsInSentence.size() > 0) {
-          // System.out.println(fileName + ": " + sentence.getCoveredText());
-          for(String text : formattedRelationsInSentence) {
+        if(eventEventRelationsInSentence.size() > 0) {
+          String sentText = annotateEvents(eventMentionsInSentence, sentence);
+          System.out.println(sentText);
+          for(String text : eventEventRelationsInSentence) {
             System.out.println(text);
           }
+          System.out.println();
         }
       }
     }
   }
 
+  private static String annotateEvents(List<EventMention> eventMentions, Sentence sentence)
{
+    
+    String text = sentence.getCoveredText();
+    for(EventMention eventMention : eventMentions) {
+      text = text.replace(eventMention.getCoveredText(), "[" + eventMention.getCoveredText()
+ "]");
+    }
+    
+    return text;
+  }
+  
   private static String getTextBetweenAnnotations(JCas jCas, Annotation arg1, Annotation
arg2) {
 
     final int windowSize = 0;



Mime
View raw message