ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1510955 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/ContextualModalityAnnotator.java eval/EvaluationOfEventProperties.java
Date Tue, 06 Aug 2013 13:15:50 GMT
Author: tmill
Date: Tue Aug  6 13:15:50 2013
New Revision: 1510955

URL: http://svn.apache.org/r1510955
Log:
Added contextualmodalityannotator for events.

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java
  (with props)
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java?rev=1510955&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java
Tue Aug  6 13:15:50 2013
@@ -0,0 +1,87 @@
+package org.apache.ctakes.temporal.ae;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.cleartk.classifier.CleartkAnnotator;
+import org.cleartk.classifier.DataWriter;
+import org.cleartk.classifier.Feature;
+import org.cleartk.classifier.Instance;
+import org.cleartk.classifier.feature.extractor.CleartkExtractor;
+import org.cleartk.classifier.feature.extractor.CleartkExtractor.Covered;
+import org.cleartk.classifier.feature.extractor.CleartkExtractor.Following;
+import org.cleartk.classifier.feature.extractor.CleartkExtractor.Preceding;
+import org.cleartk.classifier.feature.extractor.simple.CombinedExtractor;
+import org.cleartk.classifier.feature.extractor.simple.CoveredTextExtractor;
+import org.cleartk.classifier.feature.extractor.simple.TypePathExtractor;
+import org.cleartk.classifier.jar.DefaultDataWriterFactory;
+import org.cleartk.classifier.jar.DirectoryDataWriterFactory;
+import org.cleartk.classifier.jar.GenericJarClassifierFactory;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.util.JCasUtil;
+
+public class ContextualModalityAnnotator extends CleartkAnnotator<String> {
+  public static AnalysisEngineDescription createDataWriterDescription(
+      Class<? extends DataWriter<String>> dataWriterClass,
+      File outputDirectory) throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        ContextualModalityAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        true,
+        DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
+        dataWriterClass,
+        DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
+        outputDirectory);
+  }
+
+  public static AnalysisEngineDescription createAnnotatorDescription(File modelDirectory)
+      throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        ContextualModalityAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        false,
+        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+        new File(modelDirectory, "model.jar"));
+  }
+
+  private CleartkExtractor contextExtractor;
+
+  @Override
+  public void initialize(UimaContext context) throws ResourceInitializationException {
+    super.initialize(context);
+    CombinedExtractor baseExtractor = new CombinedExtractor(
+        new CoveredTextExtractor(),
+        new TypePathExtractor(BaseToken.class, "partOfSpeech"));
+
+    this.contextExtractor = new CleartkExtractor(
+        BaseToken.class,
+        baseExtractor,
+        new Preceding(3),
+        new Covered(),
+        new Following(3));
+
+  }
+  
+  @Override
+  public void process(JCas jCas) throws AnalysisEngineProcessException {
+    for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
+      if (eventMention.getEvent() != null) {
+        List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
+        if (this.isTraining()) {
+          String outcome = eventMention.getEvent().getProperties().getContextualModality();
+          this.dataWriter.write(new Instance<String>(outcome, features));
+        } else {
+          String outcome = this.classifier.classify(features);
+          eventMention.getEvent().getProperties().setContextualModality(outcome);
+        }
+      }
+    }
+  }
+}

Propchange: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ContextualModalityAnnotator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java?rev=1510955&r1=1510954&r2=1510955&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
Tue Aug  6 13:15:50 2013
@@ -30,6 +30,7 @@ import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
+import org.apache.ctakes.temporal.ae.ContextualModalityAnnotator;
 import org.apache.ctakes.temporal.ae.DocTimeRelAnnotator;
 import org.apache.ctakes.typesystem.type.refsem.EventProperties;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
@@ -59,8 +60,9 @@ public class EvaluationOfEventProperties
     Evaluation_ImplBase<Map<String, AnnotationStatistics<String>>> {
 
   private static final String DOC_TIME_REL = "docTimeRel";
-
-  private static final List<String> PROPERTY_NAMES = Arrays.asList(DOC_TIME_REL);
+  private static final String CONTEXTUAL_MODALITY = "contextualModality";
+  
+  private static final List<String> PROPERTY_NAMES = Arrays.asList(DOC_TIME_REL, CONTEXTUAL_MODALITY);
 
   public static void main(String[] args) throws Exception {
     Options options = CliFactory.parseArguments(Options.class, args);
@@ -105,9 +107,12 @@ public class EvaluationOfEventProperties
     aggregateBuilder.add(CopyFromGold.getDescription(TimeMention.class));
     aggregateBuilder.add(DocTimeRelAnnotator.createDataWriterDescription(
     		LIBSVMStringOutcomeDataWriter.class,
-        directory));
+        new File(directory, DOC_TIME_REL)));
+    aggregateBuilder.add(ContextualModalityAnnotator.createDataWriterDescription(LIBSVMStringOutcomeDataWriter.class,
new File(directory, CONTEXTUAL_MODALITY)));
     SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
-    JarClassifierBuilder.trainAndPackage(directory, "-h","0","-c", "1000");
+    for(String propertyName : PROPERTY_NAMES){
+      JarClassifierBuilder.trainAndPackage(new File(directory, propertyName), "-h","0","-c",
"1000");
+    }
   }
 
   @Override
@@ -118,8 +123,9 @@ public class EvaluationOfEventProperties
     aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class));
     aggregateBuilder.add(CopyFromGold.getDescription(TimeMention.class));
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(ClearEventProperties.class));
-    aggregateBuilder.add(DocTimeRelAnnotator.createAnnotatorDescription(directory));
-
+    aggregateBuilder.add(DocTimeRelAnnotator.createAnnotatorDescription(new File(directory,
DOC_TIME_REL)));
+    aggregateBuilder.add(ContextualModalityAnnotator.createAnnotatorDescription(new File(directory,
CONTEXTUAL_MODALITY)));
+    
     Function<EventMention, ?> eventMentionToSpan = AnnotationStatistics.annotationToSpan();
     Map<String, Function<EventMention, String>> propertyGetters;
     propertyGetters = new HashMap<String, Function<EventMention, String>>();
@@ -128,7 +134,11 @@ public class EvaluationOfEventProperties
     }
 
     Map<String, AnnotationStatistics<String>> statsMap = new HashMap<String,
AnnotationStatistics<String>>();
-    statsMap.put(DOC_TIME_REL, new AnnotationStatistics<String>());
+    
+    for(String propertyName : PROPERTY_NAMES){
+      statsMap.put(propertyName, new AnnotationStatistics<String>());
+    }
+    
     for (JCas jCas : new JCasIterable(collectionReader, aggregateBuilder.createAggregate()))
{
       JCas goldView = jCas.getView(GOLD_VIEW_NAME);
       JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);



Mime
View raw message