ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1516507 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae: BackwardsTimeAnnotator.java CRFTimeAnnotator.java ConstituencyBasedTimeAnnotator.java MetaTimeAnnotator.java TimeAnnotator.java
Date Thu, 22 Aug 2013 16:36:17 GMT
Author: tmill
Date: Thu Aug 22 16:36:17 2013
New Revision: 1516507

URL: http://svn.apache.org/r1516507
Log:
Made timex annotators have a default view to make it easier for outside projects to instantiate.

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/BackwardsTimeAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/CRFTimeAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ConstituencyBasedTimeAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/MetaTimeAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TimeAnnotator.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/BackwardsTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/BackwardsTimeAnnotator.java?rev=1516507&r1=1516506&r2=1516507&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/BackwardsTimeAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/BackwardsTimeAnnotator.java
Thu Aug 22 16:36:17 2013
@@ -13,6 +13,7 @@ import org.apache.ctakes.typesystem.type
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -33,6 +34,7 @@ import org.cleartk.classifier.feature.ex
 import org.cleartk.classifier.jar.DefaultDataWriterFactory;
 import org.cleartk.classifier.jar.DirectoryDataWriterFactory;
 import org.cleartk.classifier.jar.GenericJarClassifierFactory;
+import org.uimafit.descriptor.ConfigurationParameter;
 import org.uimafit.factory.AnalysisEngineFactory;
 import org.uimafit.util.JCasUtil;
 
@@ -41,6 +43,13 @@ import com.google.common.collect.Lists;
 
 public class BackwardsTimeAnnotator extends TemporalEntityAnnotator_ImplBase {
 
+  public static final String PARAM_TIMEX_VIEW = "TimexView";
+  @ConfigurationParameter(
+      name = PARAM_TIMEX_VIEW,
+      mandatory = false,
+      description = "View to write timexes to (used for ensemble methods)")
+  protected String timexView = CAS.NAME_DEFAULT_SOFA;
+
   public static AnalysisEngineDescription createDataWriterDescription(
       Class<? extends DataWriter<String>> dataWriterClass, File outputDirectory)
       throws ResourceInitializationException {
@@ -64,6 +73,17 @@ public class BackwardsTimeAnnotator exte
         new File(modelDirectory, "model.jar"));
   }
 
+  public static AnalysisEngineDescription createEnsembleDescription(File modelDirectory,
+      String viewName) throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        BackwardsTimeAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        false,
+        BackwardsTimeAnnotator.PARAM_TIMEX_VIEW,
+        viewName,
+        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+        new File(modelDirectory, "model.jar"));
+  }
 
   protected List<SimpleFeatureExtractor> tokenFeatureExtractors;
 
@@ -176,7 +196,7 @@ public class BackwardsTimeAnnotator exte
         outcomes = Lists.reverse(outcomes);
         JCas timexCas;
         try{
-          timexCas = jCas.getView(TimeAnnotator.TIMEX_VIEW);
+          timexCas = jCas.getView(timexView);
         }catch(CASException e){
           throw new AnalysisEngineProcessException(e);
         }
@@ -184,4 +204,5 @@ public class BackwardsTimeAnnotator exte
       }
     }
   }
+
 }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/CRFTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/CRFTimeAnnotator.java?rev=1516507&r1=1516506&r2=1516507&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/CRFTimeAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/CRFTimeAnnotator.java
Thu Aug 22 16:36:17 2013
@@ -13,6 +13,7 @@ import org.apache.ctakes.typesystem.type
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -28,10 +29,18 @@ import org.cleartk.classifier.feature.ex
 import org.cleartk.classifier.feature.extractor.simple.SimpleFeatureExtractor;
 import org.cleartk.classifier.feature.extractor.simple.TypePathExtractor;
 import org.cleartk.classifier.jar.GenericJarClassifierFactory;
+import org.uimafit.descriptor.ConfigurationParameter;
 import org.uimafit.factory.AnalysisEngineFactory;
 import org.uimafit.util.JCasUtil;
 
 public class CRFTimeAnnotator extends TemporalSequenceAnnotator_ImplBase {
+  public static final String PARAM_TIMEX_VIEW = "TimexView";
+  @ConfigurationParameter(
+      name = PARAM_TIMEX_VIEW,
+      mandatory = false,
+      description = "View to write timexes to (used for ensemble methods)")
+  protected String timexView = CAS.NAME_DEFAULT_SOFA;
+
 //  public static AnalysisEngineDescription createDataWriterDescription(
 //      Class<? extends DataWriter<String>> dataWriterClass,
 //      File outputDirectory) throws ResourceInitializationException {
@@ -54,7 +63,19 @@ public class CRFTimeAnnotator extends Te
         GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
         new File(modelDirectory, "model.jar"));
   }
-  
+
+  public static AnalysisEngineDescription createEnsembleDescription(File modelDirectory,
+      String viewName) throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        CRFTimeAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        false,
+        CRFTimeAnnotator.PARAM_TIMEX_VIEW,
+        viewName,
+        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+        new File(modelDirectory, "model.jar"));
+  }
+
   protected List<SimpleFeatureExtractor> tokenFeatureExtractors;
 
   protected List<CleartkExtractor> contextFeatureExtractors;
@@ -162,7 +183,7 @@ public class CRFTimeAnnotator extends Te
         outcomes = this.classifier.classify(allFeatures);
         JCas timexCas;
         try {
-          timexCas = jCas.getView(TimeAnnotator.TIMEX_VIEW);
+          timexCas = jCas.getView(timexView);
         } catch (CASException e) {
           throw new AnalysisEngineProcessException(e);
         }
@@ -171,4 +192,5 @@ public class CRFTimeAnnotator extends Te
     }
   }
 
+
 }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ConstituencyBasedTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ConstituencyBasedTimeAnnotator.java?rev=1516507&r1=1516506&r2=1516507&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ConstituencyBasedTimeAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/ConstituencyBasedTimeAnnotator.java
Thu Aug 22 16:36:17 2013
@@ -19,6 +19,7 @@ import org.apache.log4j.Logger;
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -39,6 +40,7 @@ import org.cleartk.classifier.jar.Defaul
 import org.cleartk.classifier.jar.DirectoryDataWriterFactory;
 import org.cleartk.classifier.jar.GenericJarClassifierFactory;
 import org.cleartk.timeml.util.TimeWordsExtractor;
+import org.uimafit.descriptor.ConfigurationParameter;
 import org.uimafit.factory.AnalysisEngineFactory;
 import org.uimafit.util.JCasUtil;
 
@@ -54,6 +56,13 @@ TemporalEntityAnnotator_ImplBase {
   private static Logger logger = Logger.getLogger(ConstituencyBasedTimeAnnotator.class);
   private static final int	SPAN_LIMIT = 12;
 
+  public static final String PARAM_TIMEX_VIEW = "TimexView";
+  @ConfigurationParameter(
+      name = PARAM_TIMEX_VIEW,
+      mandatory = false,
+      description = "View to write timexes to (used for ensemble methods)")
+  protected String timexView = CAS.NAME_DEFAULT_SOFA;
+
   public static AnalysisEngineDescription createDataWriterDescription(
       Class<? extends DataWriter<String>> dataWriterClass,
           File outputDirectory) throws ResourceInitializationException {
@@ -77,6 +86,18 @@ TemporalEntityAnnotator_ImplBase {
         new File(modelDirectory, "model.jar"));
   }
 
+  public static AnalysisEngineDescription createEnsembleDescription(File modelDirectory,
+      String viewName) throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        ConstituencyBasedTimeAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        false,
+        ConstituencyBasedTimeAnnotator.PARAM_TIMEX_VIEW,
+        viewName,
+        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+        new File(modelDirectory, "model.jar"));
+  }
+
   protected List<SimpleFeatureExtractor> featureExtractors;
   
   protected SimpleFeatureExtractor wordTypeExtractor;
@@ -205,7 +226,7 @@ TemporalEntityAnnotator_ImplBase {
         // add to cas
         JCas timexCas;
         try {
-          timexCas = jCas.getView(TimeAnnotator.TIMEX_VIEW);
+          timexCas = jCas.getView(timexView);
         } catch (CASException e) {
           throw new AnalysisEngineProcessException(e);
         }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/MetaTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/MetaTimeAnnotator.java?rev=1516507&r1=1516506&r2=1516507&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/MetaTimeAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/MetaTimeAnnotator.java
Thu Aug 22 16:36:17 2013
@@ -45,18 +45,19 @@ public class MetaTimeAnnotator extends T
       builder.add(AnalysisEngineFactory.createPrimitiveDescription(ViewCreatorAnnotator.class,
ViewCreatorAnnotator.PARAM_VIEW_NAME, component.getSimpleName()));
     }
     
-    builder.add(TimeAnnotator.createAnnotatorDescription(
-                      new File(directory, TimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, TimeAnnotator.class.getSimpleName());
-    builder.add(BackwardsTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, BackwardsTimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, BackwardsTimeAnnotator.class.getSimpleName());
-    builder.add(ConstituencyBasedTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, ConstituencyBasedTimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, ConstituencyBasedTimeAnnotator.class.getSimpleName());
-    builder.add(CRFTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, CRFTimeAnnotator.class.getSimpleName())), 
-                      TimeAnnotator.TIMEX_VIEW, CRFTimeAnnotator.class.getSimpleName());
+    builder.add(TimeAnnotator.createEnsembleDescription(
+                      new File(directory, TimeAnnotator.class.getSimpleName()), 
+                      TimeAnnotator.class.getSimpleName()));
+    builder.add(BackwardsTimeAnnotator.createEnsembleDescription(
+                      new File(directory, BackwardsTimeAnnotator.class.getSimpleName()),
+                      BackwardsTimeAnnotator.class.getSimpleName()));
+    builder.add(ConstituencyBasedTimeAnnotator.createEnsembleDescription(
+        new File(directory, ConstituencyBasedTimeAnnotator.class.getSimpleName()),
+        ConstituencyBasedTimeAnnotator.class.getSimpleName()));
+    builder.add(CRFTimeAnnotator.createEnsembleDescription(
+        new File(directory, CRFTimeAnnotator.class.getSimpleName()), 
+        CRFTimeAnnotator.class.getSimpleName()));
+    
 //    builder.add(AnalysisEngineFactory.createPrimitiveDescription(MetaTimeAnnotator.class,

 //        CleartkAnnotator.PARAM_IS_TRAINING,
 //        true,
@@ -80,18 +81,18 @@ public class MetaTimeAnnotator extends T
     for(Class<?> component : components){
       builder.add(AnalysisEngineFactory.createPrimitiveDescription(ViewCreatorAnnotator.class,
ViewCreatorAnnotator.PARAM_VIEW_NAME, component.getSimpleName()));
     }
-    builder.add(TimeAnnotator.createAnnotatorDescription(
-                      new File(directory, TimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, TimeAnnotator.class.getSimpleName());
-    builder.add(BackwardsTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, BackwardsTimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, BackwardsTimeAnnotator.class.getSimpleName());
-    builder.add(ConstituencyBasedTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, ConstituencyBasedTimeAnnotator.class.getSimpleName())),
-                      TimeAnnotator.TIMEX_VIEW, ConstituencyBasedTimeAnnotator.class.getSimpleName());
-    builder.add(CRFTimeAnnotator.createAnnotatorDescription(
-                      new File(directory, CRFTimeAnnotator.class.getSimpleName())), 
-                      TimeAnnotator.TIMEX_VIEW, CRFTimeAnnotator.class.getSimpleName());
+    builder.add(TimeAnnotator.createEnsembleDescription(
+                      new File(directory, TimeAnnotator.class.getSimpleName()),
+                      TimeAnnotator.class.getSimpleName()));
+    builder.add(BackwardsTimeAnnotator.createEnsembleDescription(
+                      new File(directory, BackwardsTimeAnnotator.class.getSimpleName()),
+                      BackwardsTimeAnnotator.class.getSimpleName()));
+    builder.add(ConstituencyBasedTimeAnnotator.createEnsembleDescription(
+                      new File(directory, ConstituencyBasedTimeAnnotator.class.getSimpleName()),
+                      ConstituencyBasedTimeAnnotator.class.getSimpleName()));
+    builder.add(CRFTimeAnnotator.createEnsembleDescription(
+                      new File(directory, CRFTimeAnnotator.class.getSimpleName()), 
+                      CRFTimeAnnotator.class.getSimpleName()));
     builder.add(AnalysisEngineFactory.createPrimitiveDescription(
         MetaTimeAnnotator.class,
         CleartkSequenceAnnotator.PARAM_IS_TRAINING,

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TimeAnnotator.java?rev=1516507&r1=1516506&r2=1516507&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TimeAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TimeAnnotator.java
Thu Aug 22 16:36:17 2013
@@ -36,11 +36,12 @@ import org.apache.ctakes.typesystem.type
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.CASRuntimeException;
 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.chunking.BIOChunking;
@@ -65,9 +66,9 @@ public class TimeAnnotator extends Tempo
 	public static final String PARAM_FEATURE_SELECTION_THRESHOLD = "WhetherToDoFeatureSelection";
 
 	@ConfigurationParameter(
-			name = PARAM_FEATURE_SELECTION_THRESHOLD,
-			mandatory = false,
-			description = "the Chi-squared threshold at which features should be removed")
+	    name = PARAM_FEATURE_SELECTION_THRESHOLD,
+	    mandatory = false,
+	    description = "the Chi-squared threshold at which features should be removed")
 	protected Float featureSelectionThreshold = 1f;
 	
 	public static final String PARAM_FEATURE_SELECTION_URI = "FeatureSelectionURI";
@@ -80,13 +81,18 @@ public class TimeAnnotator extends Tempo
 	
 	public static final String PARAM_SMOTE_NUM_NEIGHBORS = "NumOfNeighborForSMOTE";
 
-	  @ConfigurationParameter(
-			  name = PARAM_SMOTE_NUM_NEIGHBORS,
-			  mandatory = false,
-			  description = "the number of neighbors used for minority instances for SMOTE algorithm")
-	  protected Float smoteNumOfNeighbors = 0f;
+	@ConfigurationParameter(
+	    name = PARAM_SMOTE_NUM_NEIGHBORS,
+	    mandatory = false,
+	    description = "the number of neighbors used for minority instances for SMOTE algorithm")
+	protected Float smoteNumOfNeighbors = 0f;
 
-	public static final String TIMEX_VIEW = "TimexView";
+	public static final String PARAM_TIMEX_VIEW = "TimexView";
+	@ConfigurationParameter(
+	    name = PARAM_TIMEX_VIEW,
+	    mandatory = false,
+	    description = "View to write timexes to (used for ensemble methods)")
+	protected String timexView = CAS.NAME_DEFAULT_SOFA;
 
 	public static AnalysisEngineDescription createDataWriterDescription(
 			Class<?> dataWriterClass,
@@ -119,6 +125,20 @@ public class TimeAnnotator extends Tempo
 				TimeAnnotator.createFeatureSelectionURI(modelDirectory));
 	}
 
+	public static AnalysisEngineDescription createEnsembleDescription(File modelDirectory, String
mappedView)
+	    throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        TimeAnnotator.class,
+        CleartkAnnotator.PARAM_IS_TRAINING,
+        false,
+        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+        new File(modelDirectory, "model.jar"),
+        TimeAnnotator.PARAM_TIMEX_VIEW,
+        mappedView,
+        TimeAnnotator.PARAM_FEATURE_SELECTION_URI,
+        TimeAnnotator.createFeatureSelectionURI(modelDirectory));	  
+	}
+	
 	protected List<SimpleFeatureExtractor> tokenFeatureExtractors;
 
 	protected List<CleartkExtractor> contextFeatureExtractors;
@@ -269,9 +289,9 @@ public class TimeAnnotator extends Tempo
 			if (!this.isTraining()) {
 				JCas timexCas;
 				try {
-					timexCas = jCas.getView(TIMEX_VIEW);
+				  timexCas = jCas.getView(timexView);
 				} catch (CASException e) {
-					throw new AnalysisEngineProcessException(e);
+				  throw new AnalysisEngineProcessException(e);
 				}
 				this.timeChunking.createChunks(timexCas, tokens, outcomes);
 			}



Mime
View raw message