ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chen...@apache.org
Subject svn commit: r1545864 - in /ctakes/sandbox/groovy: ./ input/ input/test.txt parser.groovy
Date Tue, 26 Nov 2013 22:10:08 GMT
Author: chenpei
Date: Tue Nov 26 22:10:08 2013
New Revision: 1545864

URL: http://svn.apache.org/r1545864
Log:
CTAKES-273 - Groovy Integration

Added:
    ctakes/sandbox/groovy/
    ctakes/sandbox/groovy/input/
    ctakes/sandbox/groovy/input/test.txt   (with props)
    ctakes/sandbox/groovy/parser.groovy

Added: ctakes/sandbox/groovy/input/test.txt
URL: http://svn.apache.org/viewvc/ctakes/sandbox/groovy/input/test.txt?rev=1545864&view=auto
==============================================================================
--- ctakes/sandbox/groovy/input/test.txt (added)
+++ ctakes/sandbox/groovy/input/test.txt Tue Nov 26 22:10:08 2013
@@ -0,0 +1 @@
+patient took 50mg of aspirin for pain in knee.

Propchange: ctakes/sandbox/groovy/input/test.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ctakes/sandbox/groovy/parser.groovy
URL: http://svn.apache.org/viewvc/ctakes/sandbox/groovy/parser.groovy?rev=1545864&view=auto
==============================================================================
--- ctakes/sandbox/groovy/parser.groovy (added)
+++ ctakes/sandbox/groovy/parser.groovy Tue Nov 26 22:10:08 2013
@@ -0,0 +1,69 @@
+#!/usr/bin/env groovy
+@Grab(group='org.apache.ctakes',
+      module='ctakes-constituency-parser',
+            version='3.1.0')
+@Grab(group='org.apache.ctakes',
+      module='ctakes-constituency-parser-res',
+            version='3.1.0')		
+@Grab(group='org.apache.ctakes',
+      module='ctakes-pos-tagger',
+            version='3.1.0')	
+@Grab(group='org.apache.ctakes',
+      module='ctakes-pos-tagger-res',
+            version='3.1.0')			
+@Grab(group='org.apache.ctakes',
+      module='ctakes-clinical-pipeline',
+            version='3.1.0')
+			
+import java.io.File;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.collection.CollectionReader;
+import org.cleartk.util.cr.FilesCollectionReader;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.AggregateBuilder;
+import org.uimafit.pipeline.SimplePipeline;	
+import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.factory.TypeSystemDescriptionFactory;
+import org.uimafit.factory.TypePrioritiesFactory;
+import static org.uimafit.util.JCasUtil.*;
+
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textspan.Segment;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.ctakes.core.ae.SentenceDetector;
+import org.apache.ctakes.core.ae.SimpleSegmentAnnotator;
+import org.apache.ctakes.core.ae.TokenizerAnnotatorPTB;
+import org.apache.ctakes.postagger.POSTagger;
+import org.apache.ctakes.constituency.parser.ae.ConstituencyParser;
+
+		CollectionReader collectionReader = FilesCollectionReader.getCollectionReader(args[0]);
+		System.out.println("Reading from directory: " + args[0]);
+		
+		AggregateBuilder aggregateBuilder = new AggregateBuilder();
+		
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(SimpleSegmentAnnotator.class));
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(TokenizerAnnotatorPTB.class));
+		
+		/*  Need to resolve zip resoures from inside a jar first...
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
+			POSTagger.class,
+			TypeSystemDescriptionFactory.createTypeSystemDescription(),
+			TypePrioritiesFactory.createTypePriorities(Segment.class, Sentence.class, BaseToken.class),
+			POSTagger.POS_MODEL_FILE_PARAM,
+			"org/apache/ctakes/postagger/models/mayo-pos.zip"));		
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
+            SentenceDetector.class,
+            SentenceDetector.SD_MODEL_FILE_PARAM,
+            "org/apache/ctakes/core/sentdetect/sd-med-model.zip"));			
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(ConstituencyParser.class));
+		*/
+		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(Writer.class));
+		SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
+
+// Custom writer class used at the end of the pipeline to write results to screen
+class Writer extends org.uimafit.component.JCasAnnotator_ImplBase {
+  void process(JCas jcas) {
+    select(jcas, Segment).each { println "${it.coveredText} begin:${it.begin} end:${it.end}"
 }
+  }
+}
\ No newline at end of file



Mime
View raw message