ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1624321 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
Date Thu, 11 Sep 2014 15:53:13 GMT
Author: tmill
Date: Thu Sep 11 15:53:13 2014
New Revision: 1624321

URL: http://svn.apache.org/r1624321
Log:
Allow for training/testing only a subset of time annotation models.

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java?rev=1624321&r1=1624320&r2=1624321&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
Thu Sep 11 15:53:13 2014
@@ -34,6 +34,7 @@ import org.apache.ctakes.temporal.ae.fea
 import org.apache.ctakes.typesystem.type.textsem.TimeMention;
 import org.apache.ctakes.typesystem.type.textspan.Segment;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -69,6 +70,21 @@ public class EvaluationOfTimeSpans exten
 		
 		@Option(longName = "SMOTENeighborNumber", defaultValue = "0")
 	    public float getSMOTENeighborNumber();
+		
+		@Option(shortName="b")
+		public boolean getRunBackwards();
+		
+		@Option(shortName="f")
+		public boolean getRunForwards();
+		
+		@Option(shortName="p")
+		public boolean getRunParserBased();
+		
+		@Option(shortName="c")
+		public boolean getRunCrfBased();
+		
+		@Option
+		public boolean getSkipTrain();
 	}
 
 	public static void main(String[] args) throws Exception {
@@ -100,17 +116,26 @@ public class EvaluationOfTimeSpans exten
 		
 		// specify the annotator classes to use
 		List<Class<? extends JCasAnnotator_ImplBase>> annotatorClasses = Lists.newArrayList();
-		annotatorClasses.add(BackwardsTimeAnnotator.class);
-		annotatorClasses.add(TimeAnnotator.class);
-		annotatorClasses.add(ConstituencyBasedTimeAnnotator.class);
-		annotatorClasses.add(CRFTimeAnnotator.class);
-//		annotatorClasses.add(MetaTimeAnnotator.class);
+		if(options.getRunBackwards())	annotatorClasses.add(BackwardsTimeAnnotator.class);
+		if(options.getRunForwards()) annotatorClasses.add(TimeAnnotator.class);
+		if(options.getRunParserBased()) annotatorClasses.add(ConstituencyBasedTimeAnnotator.class);
+		if(options.getRunCrfBased()) annotatorClasses.add(CRFTimeAnnotator.class);
+		if(annotatorClasses.size() == 0){
+		  // run all
+		  annotatorClasses.add(BackwardsTimeAnnotator.class);
+		  annotatorClasses.add(TimeAnnotator.class);
+		  annotatorClasses.add(ConstituencyBasedTimeAnnotator.class);
+		  annotatorClasses.add(CRFTimeAnnotator.class);
+		}
 		Map<Class<? extends JCasAnnotator_ImplBase>, String[]> annotatorTrainingArguments
= Maps.newHashMap();
-		annotatorTrainingArguments.put(BackwardsTimeAnnotator.class, new String[]{"-c", "0.3"});
+		
+		// THYME best params: Backwards: 0.1, CRF 0.3, Time 0.1, Constituency 0.3
+		// i2b2 best params: Backwards 0.1, CRF 3.0, Time 0.1, Constituency 0.3
+		String gridParam = "0.01";
+		annotatorTrainingArguments.put(BackwardsTimeAnnotator.class, new String[]{"-c", "0.1"});
 		annotatorTrainingArguments.put(TimeAnnotator.class, new String[]{"-c", "0.1"});
 		annotatorTrainingArguments.put(ConstituencyBasedTimeAnnotator.class, new String[]{"-c",
"0.3"});
-		annotatorTrainingArguments.put(CRFTimeAnnotator.class, new String[]{"-p", "c2=0.03"});
-//		annotatorTrainingArguments.put(MetaTimeAnnotator.class, new String[]{"-p", "c2=0.3"});
+		annotatorTrainingArguments.put(CRFTimeAnnotator.class, new String[]{"-p", "c2=" + "0.3"});
 
 		// run one evaluation per annotator class
 		final Map<Class<?>, AnnotationStatistics<?>> annotatorStats = Maps.newHashMap();
@@ -128,6 +153,8 @@ public class EvaluationOfTimeSpans exten
 					options.getPrintOverlappingSpans(),
 					annotatorTrainingArguments.get(annotatorClass));
 			evaluation.prepareXMIsFor(patientSets);
+			evaluation.setSkipTrain(options.getSkipTrain());
+			evaluation.printErrors = options.getPrintErrors();
 			if(options.getI2B2Output()!=null) evaluation.setI2B2Output(options.getI2B2Output() + "/"
+ annotatorClass.getSimpleName());
 			String name = String.format("%s.errors", annotatorClass.getSimpleName());
 			evaluation.setLogging(Level.FINE, new File("target/eval", name));
@@ -160,6 +187,8 @@ public class EvaluationOfTimeSpans exten
 	
 	private float smoteNeighborNumber;
 
+	private boolean skipTrain = false;
+	
 	public EvaluationOfTimeSpans(
 			File baseDirectory,
 			File rawTextDirectory,
@@ -180,6 +209,17 @@ public class EvaluationOfTimeSpans exten
 		this.smoteNeighborNumber = numOfSmoteNeighbors;
 	}
 
+	public void setSkipTrain(boolean val){
+	  this.skipTrain = val;
+	}
+	
+	@Override
+	public void train(CollectionReader reader, File directory) throws Exception{
+	  if(!skipTrain){
+	    super.train(reader, directory);
+	  }
+	}
+	
 	@Override
 	protected AnalysisEngineDescription getDataWriterDescription(File directory)
 			throws ResourceInitializationException {



Mime
View raw message