ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1482521 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines: EventExtractionPipeline.java EventPrintingPipeline.java
Date Tue, 14 May 2013 18:54:55 GMT
Author: dligach
Date: Tue May 14 18:54:55 2013
New Revision: 1482521

URL: http://svn.apache.org/r1482521
Log:
Added a class to print event annotations in xmi files

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventPrintingPipeline.java
      - copied, changed from r1481857, ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationAnnotationAnalysis.java
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventExtractionPipeline.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventExtractionPipeline.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventExtractionPipeline.java?rev=1482521&r1=1482520&r2=1482521&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventExtractionPipeline.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventExtractionPipeline.java
Tue May 14 18:54:55 2013
@@ -68,7 +68,6 @@ import org.uimafit.pipeline.SimplePipeli
 import org.uimafit.util.JCasUtil;
 
 /**
- * 
  * Given a trained event extraction model, run the event extractor on files in a directory.
  * Save the resulting annotations in XMI files. 
  * 
@@ -118,7 +117,6 @@ public class EventExtractionPipeline {
     SimplePipeline.runPipeline(
         collectionReader,
         aggregateBuilder.createAggregate(),
-        AnalysisEngineFactory.createPrimitive(PrintEventAnnotations.class),
         xWriter);
 	}
 	
@@ -307,19 +305,4 @@ public class EventExtractionPipeline {
     
     return aggregateBuilder;
   }
-
-  public static class PrintEventAnnotations extends JCasAnnotator_ImplBase {
-
-    public static AnalysisEngineDescription getDescription() throws ResourceInitializationException
{
-      return AnalysisEngineFactory.createPrimitiveDescription(PrintEventAnnotations.class);
-    }
-
-    @Override
-    public void process(JCas jCas) throws AnalysisEngineProcessException {
-     
-      for(EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
-        System.out.println(eventMention.getCoveredText());
-      }
-    }
-  }
 }

Copied: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventPrintingPipeline.java
(from r1481857, ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationAnnotationAnalysis.java)
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventPrintingPipeline.java?p2=ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventPrintingPipeline.java&p1=ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationAnnotationAnalysis.java&r1=1481857&r2=1482521&rev=1482521&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationAnnotationAnalysis.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/pipelines/EventPrintingPipeline.java
Tue May 14 18:54:55 2013
@@ -16,36 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.ctakes.relationextractor.pipelines;
+package org.apache.ctakes.temporal.pipelines;
 
 import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 
 import org.apache.ctakes.relationextractor.eval.XMIReader;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.collection.CollectionReader;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
 import org.cleartk.util.Options_ImplBase;
 import org.kohsuke.args4j.Option;
+import org.uimafit.component.JCasAnnotator_ImplBase;
 import org.uimafit.factory.AnalysisEngineFactory;
 import org.uimafit.factory.CollectionReaderFactory;
 import org.uimafit.pipeline.SimplePipeline;
+import org.uimafit.util.JCasUtil;
 
 /**
- * 
- * Analyze the annotations obtained by running the relation extractor on clinical notes.
- * The results of running the relation extractor are expected to be saved in xmi files.
- * 
+ * Print event annotations and their context.
+ *  
  * @author dmitriy dligach
  *
  */
-public class RelationAnnotationAnalysis {
+public class EventPrintingPipeline {
 
   public static class Options extends Options_ImplBase {
 
     @Option(
         name = "--input-dir",
-        usage = "specify the path to the directory containing the clinical notes to be processed",
+        usage = "specify the path to the directory containing xmi files containing event
annotations",
         required = true)
     public File inputDirectory;
   }
@@ -55,27 +60,40 @@ public class RelationAnnotationAnalysis 
 		Options options = new Options();
 		options.parseOptions(args);
 
-		List<File> trainFiles = Arrays.asList(options.inputDirectory.listFiles());
-    CollectionReader collectionReader = getCollectionReader(trainFiles);
-		
-    AnalysisEngine relationExtractorConsumer = AnalysisEngineFactory.createPrimitive(
-    		RelationExtractorConsumer.class);
-    		
-		SimplePipeline.runPipeline(collectionReader, relationExtractorConsumer);
+		SimplePipeline.runPipeline(
+		    getCollectionReader(Arrays.asList(options.inputDirectory.listFiles())), 
+		    PrintEventAnnotations.getDescription());
 	}
 	
   private static CollectionReader getCollectionReader(List<File> items) throws Exception
{
 
-  	// convert the List<File> to a String[]
     String[] paths = new String[items.size()];
     for (int i = 0; i < paths.length; ++i) {
       paths[i] = items.get(i).getPath();
     }
     
-    // return a reader that will load each of the XMI files
     return CollectionReaderFactory.createCollectionReader(
         XMIReader.class,
         XMIReader.PARAM_FILES,
         paths);
   }
+  
+  public static class PrintEventAnnotations extends JCasAnnotator_ImplBase {
+
+    public static AnalysisEngine getDescription() throws ResourceInitializationException
{
+      return AnalysisEngineFactory.createPrimitive(PrintEventAnnotations.class);
+    }
+
+    @Override
+    public void process(JCas jCas) throws AnalysisEngineProcessException {
+     
+      for(EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
+        if(eventMention.getClass().getSimpleName().equals("EventMention")) {
+          List<Sentence> sentences = JCasUtil.selectCovering(jCas, Sentence.class,
eventMention.getBegin(), eventMention.getEnd());
+          System.out.println(eventMention.getCoveredText() + "|" + sentences.get(0).getCoveredText());
+        }
+      }
+    }
+  }
+
 }



Mime
View raw message