ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1745539 - /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/PositiveAndNegativeExamplePrinter.java
Date Wed, 25 May 2016 21:06:30 GMT
Author: dligach
Date: Wed May 25 21:06:30 2016
New Revision: 1745539

URL: http://svn.apache.org/viewvc?rev=1745539&view=rev
Log:
extracting text between mentions using base tokens

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=1745539&r1=1745538&r2=1745539&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
Wed May 25 21:06:30 2016
@@ -25,12 +25,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ctakes.relationextractor.ae.RelationExtractorAnnotator.IdentifiedAnnotationPair;
 import org.apache.ctakes.temporal.duration.Utils;
 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.textsem.TimeMention;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
@@ -68,12 +69,12 @@ public class PositiveAndNegativeExampleP
 
     List<Integer> patientSets = options.getPatients().getList();
     List<Integer> trainItems = THYMEData.getPatientSets(patientSets, THYMEData.TRAIN_REMAINDERS);
+    List<Integer> devItems = THYMEData.getPatientSets(patientSets, THYMEData.DEV_REMAINDERS);
     List<File> trainFiles = Utils.getFilesFor(trainItems, options.getInputDirectory());
-    CollectionReader collectionReader = Utils.getCollectionReader(trainFiles);
-
-    AnalysisEngine annotationConsumer = AnalysisEngineFactory.createEngine(
-        RelationSnippetPrinter.class);
-
+    List<File> devFiles = Utils.getFilesFor(devItems, options.getInputDirectory());
+    
+    CollectionReader collectionReader = Utils.getCollectionReader(devFiles);
+    AnalysisEngine annotationConsumer = AnalysisEngineFactory.createEngine(RelationSnippetPrinter.class);
     SimplePipeline.runPipeline(collectionReader, annotationConsumer);
   }
 
@@ -132,24 +133,35 @@ public class PositiveAndNegativeExampleP
               label = relation.getCategory().toLowerCase();
             }
 
-            String context = getTextBetweenAnnotations(systemView, mention1, mention2); 
+            String context = getTextBetween(systemView, mention1, mention2); 
             String text = String.format("%s|%s", label, context);
             eventEventRelationsInSentence.add(text.toLowerCase());
           }
         }
 
         if(eventEventRelationsInSentence.size() > 0) {
-          // String sentText = annotateEvents(eventMentionsInSentence, sentence);
-          // System.out.println(sentText);
           for(String text : eventEventRelationsInSentence) {
             System.out.println(text);
           }
-          // System.out.println();
         }
       }
     }
   }
 
+  public static String getTextBetween(JCas jCas, Annotation arg1, Annotation arg2)  {
+    
+    List<BaseToken> baseTokens = JCasUtil.selectBetween(jCas, BaseToken.class, arg1,
arg2);
+    StringBuilder tokens = new StringBuilder();
+    tokens.append("<arg1-start> " + arg1.getCoveredText() + " <arg1-end> ");
+    for(BaseToken baseToken : baseTokens) {
+      tokens.append(baseToken.getCoveredText() + " ");
+    }
+    tokens.append("<arg2-start> " + arg2.getCoveredText() + " <arg2-end>");
+    
+    return tokens.toString().replaceAll("[\r\n]", " ");
+  }
+  
+  @SuppressWarnings("unused")
   private static String annotateEvents(List<EventMention> eventMentions, Sentence sentence)
{
     
     String text = sentence.getCoveredText();
@@ -160,6 +172,7 @@ public class PositiveAndNegativeExampleP
     return text;
   }
   
+  @SuppressWarnings("unused")
   private static String getTextBetweenAnnotations(JCas jCas, Annotation arg1, Annotation
arg2) {
 
     final int windowSize = 0;



Mime
View raw message