ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1493804 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/EventTimeRelationAnnotator.java data/analysis/TimexTreeAlignmentStatistics.java eval/EvaluationOfTemporalRelations.java eval/THYMEData.java
Date Mon, 17 Jun 2013 15:17:48 GMT
Author: tmill
Date: Mon Jun 17 15:17:47 2013
New Revision: 1493804

URL: http://svn.apache.org/r1493804
Log:
Check in tree kernel version of event-time annotator/eval used in bionlp paper.

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/TimexTreeAlignmentStatistics.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/THYMEData.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.java?rev=1493804&r1=1493803&r2=1493804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.java
Mon Jun 17 15:17:47 2013
@@ -9,6 +9,7 @@ import org.apache.ctakes.relationextract
 import org.apache.ctakes.relationextractor.ae.features.PartOfSpeechFeaturesExtractor;
 import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
 import org.apache.ctakes.relationextractor.ae.features.TokenFeaturesExtractor;
+import org.apache.ctakes.temporal.ae.feature.TemporalAttributeFeatureExtractor;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
@@ -60,9 +61,14 @@ public class EventTimeRelationAnnotator 
   @Override
   protected List<RelationFeaturesExtractor> getFeatureExtractors() {
     return Lists.newArrayList(
-        new TokenFeaturesExtractor(), 
-        new PartOfSpeechFeaturesExtractor()
-        );
+    						  new TokenFeaturesExtractor()
+    						, new PartOfSpeechFeaturesExtractor()
+    						, new TemporalAttributeFeatureExtractor()
+//    						, new EventTimeFlatTreeFeatureExtractor()
+//    						, new TemporalPETExtractor()
+//    						, new TemporalPathExtractor()
+//    						, new TemporalFTExtractor()
+    						);
   }
 
   @Override

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/TimexTreeAlignmentStatistics.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/TimexTreeAlignmentStatistics.java?rev=1493804&r1=1493803&r2=1493804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/TimexTreeAlignmentStatistics.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/TimexTreeAlignmentStatistics.java
Mon Jun 17 15:17:47 2013
@@ -53,7 +53,7 @@ public class TimexTreeAlignmentStatistic
     //List<Integer> devItems = THYMEData.getDevPatientSets(patientSets);
     //List<Integer> testItems = THYMEData.getTestPatientSets(patientSets);
 
-    CollectionReader reader = UriCollectionReader.getCollectionReaderFromFiles(getFilesFor(trainItems,
options.getRawTextDirectory()));
+    CollectionReader reader = UriCollectionReader.getCollectionReaderFromFiles(THYMEData.getFilesFor(trainItems,
options.getRawTextDirectory()));
     AggregateBuilder aggregateBuilder = new AggregateBuilder();
     aggregateBuilder.add(UriToDocumentTextAnnotator.getDescription());
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
@@ -103,24 +103,5 @@ public class TimexTreeAlignmentStatistic
     System.out.printf("Found %d mentions, %d match with node spans\n", numMentions, numMatches);
   }
 
-  private static List<File> getFilesFor(List<Integer> patientSets, File rawTextDirectory)
{
-    if ( !rawTextDirectory.exists() ) {
-      return Collections.emptyList();
-    }
-    List<File> files = new ArrayList<File>();
-    for (Integer set : patientSets) {
-      final int setNum = set;
-      for (File file : rawTextDirectory.listFiles(new FilenameFilter(){
-        @Override
-        public boolean accept(File dir, String name) {
-          return name.contains(String.format("ID%03d", setNum));
-        }})) {
-        // skip hidden files like .svn
-        if (!file.isHidden()) {
-          files.add(file);
-        } 
-      }
-    }
-    return files;
-  }
+
 }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations.java?rev=1493804&r1=1493803&r2=1493804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations.java
Mon Jun 17 15:17:47 2013
@@ -20,9 +20,12 @@ package org.apache.ctakes.temporal.eval;
 
 import java.io.File;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.ArrayDeque;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Deque;
 import java.util.List;
 import java.util.Map;
@@ -30,9 +33,9 @@ import java.util.Set;
 
 import org.apache.ctakes.relationextractor.eval.RelationExtractorEvaluation.HashableArguments;
 import org.apache.ctakes.temporal.ae.EventTimeRelationAnnotator;
+import org.apache.ctakes.temporal.ae.baselines.RecallBaselineEventTimeRelationAnnotator;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.RelationArgument;
-import org.apache.ctakes.typesystem.type.relation.TemporalTextRelation;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
 import org.apache.ctakes.typesystem.type.textsem.TimeMention;
@@ -43,8 +46,11 @@ import org.apache.uima.cas.CASException;
 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;
 import org.cleartk.classifier.jar.JarClassifierBuilder;
-import org.cleartk.classifier.libsvm.LIBSVMStringOutcomeDataWriter;
+import org.cleartk.classifier.tksvmlight.TKSVMlightStringOutcomeDataWriter;
+import org.cleartk.classifier.tksvmlight.model.CompositeKernel;
+import org.cleartk.classifier.tksvmlight.model.CompositeKernel.ComboOperator;
 import org.cleartk.eval.AnnotationStatistics;
 import org.cleartk.util.ViewURIUtil;
 import org.uimafit.component.JCasAnnotator_ImplBase;
@@ -53,62 +59,119 @@ import org.uimafit.factory.AggregateBuil
 import org.uimafit.factory.AnalysisEngineFactory;
 import org.uimafit.pipeline.JCasIterable;
 import org.uimafit.pipeline.SimplePipeline;
+import org.uimafit.testing.util.HideOutput;
 import org.uimafit.util.JCasUtil;
 
 import com.google.common.base.Function;
+import com.google.common.base.Functions;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Ordering;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 import com.lexicalscope.jewel.cli.CliFactory;
 import com.lexicalscope.jewel.cli.Option;
 
 public class EvaluationOfTemporalRelations extends
-    Evaluation_ImplBase<AnnotationStatistics<String>> {
-	
+	Evaluation_ImplBase<AnnotationStatistics<String>>{
   static interface TempRelOptions extends Evaluation_ImplBase.Options{
-    @Option
-    public boolean getTest();
-
-    @Option
-    public boolean getPrintFormattedRelations();
+	  @Option
+	  public boolean getTest();
+	  
+	  @Option
+	  public boolean getPrintFormattedRelations();
+	  
+	  @Option
+	  public boolean getBaseline();
     
     @Option
     public boolean getClosure();
   }
-
+  
+  protected static boolean DEFAULT_BOTH_DIRECTIONS = false;
+  protected static float DEFAULT_DOWNSAMPLE = 1.0f;
+  private static double DEFAULT_SVM_C = 1.0;
+  private static double DEFAULT_SVM_G = 1.0;
+  private static double DEFAULT_TK = 0.5;
+  private static double DEFAULT_LAMBDA = 0.5;
+  
+  protected static ParameterSettings defaultParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS,
DEFAULT_DOWNSAMPLE, "tk",
+  		  DEFAULT_SVM_C, DEFAULT_SVM_G, "polynomial", ComboOperator.SUM, DEFAULT_TK, DEFAULT_LAMBDA);
+  protected static ParameterSettings flatParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS,
DEFAULT_DOWNSAMPLE, "linear",
+		  10.0, 1.0, "linear", ComboOperator.VECTOR_ONLY, DEFAULT_TK, DEFAULT_LAMBDA);
+  protected static ParameterSettings allBagsParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS,
DEFAULT_DOWNSAMPLE, "tk", 
+		  100.0, 0.1, "radial basis function", ComboOperator.SUM, 0.5, 0.5);
+  protected static ParameterSettings allParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS,
DEFAULT_DOWNSAMPLE, "tk",
+		  10.0, 1.0, "polynomial", ComboOperator.SUM, 0.1, 0.5);
+  protected static ParameterSettings ftParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS,
DEFAULT_DOWNSAMPLE, "tk", 
+		  1.0, 0.1, "radial basis function", ComboOperator.SUM, 0.5, 0.5);
+  
   public static void main(String[] args) throws Exception {
     TempRelOptions options = CliFactory.parseArguments(TempRelOptions.class, args);
     List<Integer> patientSets = options.getPatients().getList();
     List<Integer> trainItems = THYMEData.getTrainPatientSets(patientSets);
     List<Integer> devItems = THYMEData.getDevPatientSets(patientSets);
     List<Integer> testItems = THYMEData.getTestPatientSets(patientSets);
-    
-    EvaluationOfTemporalRelations evaluation = new EvaluationOfTemporalRelations(
-        new File("target/eval/temporal-relations"),
-        options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
-        options.getXMIDirectory(),
-        options.getTreebankDirectory(),
-        options.getClosure(),
-        options.getPrintErrors(),
-        options.getPrintFormattedRelations());
-    evaluation.prepareXMIsFor(patientSets);
-    List<Integer> training = trainItems;
-    List<Integer> testing = null;
-    if(options.getTest()){
-      training.addAll(devItems);
-      testing = testItems;
-    }else{
-      testing = devItems;
-    }    
-    AnnotationStatistics<String> stats = evaluation.trainAndTest(training, testing);
-    System.err.println(stats);
+    ParameterSettings params = defaultParams;
+
+    //    List<ParameterSettings> possibleParams = Lists.newArrayList();
+    //    Map<ParameterSettings, Double> scoredParams = new HashMap<ParameterSettings,
Double>();
+
+
+    //    possibleParams.add(defaultParams);
+
+    //    for(ParameterSettings params : possibleParams){
+    try{
+      File workingDir = new File("target/eval/temporal-relations");
+      if(!workingDir.exists()) workingDir.mkdirs();
+      File tempModelDir = File.createTempFile("temporal", null, workingDir);
+      tempModelDir.delete();
+      tempModelDir.mkdir();
+      EvaluationOfTemporalRelations evaluation = new EvaluationOfTemporalRelations(
+          tempModelDir,
+          options.getRawTextDirectory(),
+          options.getKnowtatorXMLDirectory(),
+          options.getXMIDirectory(),
+          options.getTreebankDirectory(),
+          options.getClosure(),
+          options.getPrintErrors(),
+          options.getPrintFormattedRelations(),
+          options.getBaseline(),
+          options.getKernelParams(),
+          params);
+      evaluation.prepareXMIsFor(patientSets);
+      List<Integer> training = trainItems;
+      List<Integer> testing = null;
+      if(options.getTest()){
+        training.addAll(devItems);
+        testing = testItems;
+      }else{
+        testing = devItems;
+      }
+      params.stats = evaluation.trainAndTest(training, testing);
+      //      System.err.println(options.getKernelParams() == null ? params : options.getKernelParams());
+      //      System.err.println(params.stats);
+      tempModelDir.delete();
+    }catch(ResourceInitializationException e){
+      System.err.println("Error with parameter settings: " + params);
+      e.printStackTrace();
+    }
+
+    // print performance of each set of parameters
+    System.err.printf(
+        "F1=%.3f P=%.3f R=%.3f %s\n",
+        params.stats.f1(),
+        params.stats.precision(),
+        params.stats.recall(),
+        options.getKernelParams() == null ? params : options.getKernelParams());
+    System.err.println();
+
   }
 
-  protected boolean useClosure;
-  
+  private ParameterSettings params;
+  private boolean baseline;
+  protected boolean useClosure; 
   protected boolean printRelations = false;
   
   public EvaluationOfTemporalRelations(
@@ -119,29 +182,78 @@ public class EvaluationOfTemporalRelatio
       File treebankDirectory,
       boolean useClosure,
       boolean printErrors,
-      boolean printRelations) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, treebankDirectory);
+      boolean printRelations,
+      boolean baseline,
+      String kernelParams,
+      ParameterSettings params){
+    super(
+        baseDirectory,
+        rawTextDirectory,
+        knowtatorXMLDirectory,
+        xmiDirectory,
+        treebankDirectory);
+    this.params = params;
     this.useClosure = useClosure;
     this.printErrors = printErrors;
     this.printRelations = printRelations;
+    this.baseline = baseline;
+    this.kernelParams = kernelParams == null ? null : kernelParams.split(" ");
+  }
+
+  public EvaluationOfTemporalRelations(File baseDirectory, File rawTextDirectory,
+      File knowtatorXMLDirectory, File xmiDirectory) {
+
+    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, null);
+    this.params = defaultParams;
+    this.printErrors = false;
   }
 
   @Override
   protected void train(CollectionReader collectionReader, File directory) throws Exception
{
+//	  if(this.baseline) return;
     AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
     aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class,
BinaryTextRelation.class));
-    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveNonTLINKRelations.class));
+//    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(MergeContainsOverlap.class));
+    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveNonContainsRelations.class));
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveCrossSentenceRelations.class));
     if (this.useClosure) {
       aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class));
     }
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveEventEventRelations.class));
     aggregateBuilder.add(EventTimeRelationAnnotator.createDataWriterDescription(
-        LIBSVMStringOutcomeDataWriter.class,
+//                LIBSVMStringOutcomeDataWriter.class,
+        TKSVMlightStringOutcomeDataWriter.class,
         directory,
-        1.0));
+        params.probabilityOfKeepingANegativeExample));
     SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
-    JarClassifierBuilder.trainAndPackage(directory, "-t", "2", "-d", "2", "-c", "10");
+    String[] optArray;
+    
+    if(this.kernelParams == null){
+    	ArrayList<String> svmOptions = new ArrayList<String>();
+    	svmOptions.add("-c"); svmOptions.add(""+params.svmCost);        // svm cost
+    	svmOptions.add("-t"); svmOptions.add(""+params.svmKernelIndex); // kernel index 
+    	svmOptions.add("-d"); svmOptions.add("3");                      // degree parameter
for polynomial
+    	svmOptions.add("-g"); svmOptions.add(""+params.svmGamma);
+    	if(params.svmKernelIndex==ParameterSettings.SVM_KERNELS.indexOf("tk")){
+    		svmOptions.add("-S"); svmOptions.add(""+params.secondKernelIndex);   // second kernel
index (similar to -t) for composite kernel
+    		String comboFlag = (params.comboOperator == ComboOperator.SUM ? "+" : params.comboOperator
== ComboOperator.PRODUCT ? "*" : params.comboOperator == ComboOperator.TREE_ONLY ? "T" : "V");
+    		svmOptions.add("-C"); svmOptions.add(comboFlag);
+    		svmOptions.add("-L"); svmOptions.add(""+params.lambda);
+    		svmOptions.add("-T"); svmOptions.add(""+params.tkWeight);
+    		svmOptions.add("-N"); svmOptions.add("3");   // normalize trees and features
+    	}
+    	optArray = svmOptions.toArray(new String[]{});
+    }else{
+    	optArray = this.kernelParams;
+    	for(int i = 0; i < optArray.length; i+=2){
+    		optArray[i] = "-" + optArray[i];
+    	}
+    }
+    
+    HideOutput hider = new HideOutput();
+    JarClassifierBuilder.trainAndPackage(directory, optArray);
+    hider.restoreOutput();
+    hider.close();
   }
 
   @Override
@@ -149,10 +261,13 @@ public class EvaluationOfTemporalRelatio
       throws Exception {
     AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
     aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class));
+//    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(MergeContainsOverlap.class,
+//    		MergeContainsOverlap.PARAM_RELATION_VIEW,
+//    		GOLD_VIEW_NAME));
     aggregateBuilder.add(
-        AnalysisEngineFactory.createPrimitiveDescription(RemoveNonTLINKRelations.class),
-        CAS.NAME_DEFAULT_SOFA,
-        GOLD_VIEW_NAME);
+        AnalysisEngineFactory.createPrimitiveDescription(RemoveNonContainsRelations.class,
+        RemoveNonContainsRelations.PARAM_RELATION_VIEW,
+        GOLD_VIEW_NAME));
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
         RemoveCrossSentenceRelations.class,
         RemoveCrossSentenceRelations.PARAM_SENTENCE_VIEW,
@@ -169,8 +284,10 @@ public class EvaluationOfTemporalRelatio
         AnalysisEngineFactory.createPrimitiveDescription(RemoveEventEventRelations.class),
         CAS.NAME_DEFAULT_SOFA,
         GOLD_VIEW_NAME);
+    		
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveRelations.class));
-    aggregateBuilder.add(EventTimeRelationAnnotator.createAnnotatorDescription(directory));
+    aggregateBuilder.add(this.baseline ? RecallBaselineEventTimeRelationAnnotator.createAnnotatorDescription(directory)
:
+    	EventTimeRelationAnnotator.createAnnotatorDescription(directory));
 
     Function<BinaryTextRelation, ?> getSpan = new Function<BinaryTextRelation, HashableArguments>()
{
       public HashableArguments apply(BinaryTextRelation relation) {
@@ -180,7 +297,10 @@ public class EvaluationOfTemporalRelatio
     Function<BinaryTextRelation, String> getOutcome = AnnotationStatistics.annotationToFeatureValue("category");
 
     AnnotationStatistics<String> stats = new AnnotationStatistics<String>();
-    for (JCas jCas : new JCasIterable(collectionReader, aggregateBuilder.createAggregate()))
{
+   	JCasIterable jcasIter =new JCasIterable(collectionReader, aggregateBuilder.createAggregate());
+    JCas jCas = null;
+   	while(jcasIter.hasNext()) {
+      jCas = jcasIter.next();
       JCas goldView = jCas.getView(GOLD_VIEW_NAME);
       JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
       Collection<BinaryTextRelation> goldRelations = JCasUtil.select(
@@ -195,7 +315,6 @@ public class EvaluationOfTemporalRelatio
     	  String[] path = uri.getPath().split("/");
     	  printRelationAnnotations(path[path.length - 1], systemRelations);
       }
-
       if(this.printErrors){
     	  Map<HashableArguments, BinaryTextRelation> goldMap = Maps.newHashMap();
     	  for (BinaryTextRelation relation : goldRelations) {
@@ -217,7 +336,9 @@ public class EvaluationOfTemporalRelatio
     			  System.out.println("System dropped: " + formatRelation(goldRelation));
     		  } else if (!systemRelation.getCategory().equals(goldRelation.getCategory())) {
     			  String label = systemRelation.getCategory();
-    			  System.out.printf("System labeled %s for %s\n", label, formatRelation(systemRelation));
+    			  System.out.printf("System labeled %s for %s\n", label, formatRelation(goldRelation));
+    		  } else{
+    			  System.out.println("Nailed it! " + formatRelation(systemRelation));
     		  }
     	  }
       }
@@ -242,7 +363,7 @@ public class EvaluationOfTemporalRelatio
 			  arg2.getTypeID(),
 			  text.substring(begin, end).replaceAll("[\r\n]", " "));
   }
-
+  
   private static void printRelationAnnotations(String fileName, Collection<BinaryTextRelation>
relations) {
 
 	  for(BinaryTextRelation binaryTextRelation : relations) {
@@ -266,27 +387,94 @@ public class EvaluationOfTemporalRelatio
   }
 
   public static class RemoveEventEventRelations extends JCasAnnotator_ImplBase {
+    public static final String PARAM_RELATION_VIEW = "RelationView";
+	@ConfigurationParameter(name = PARAM_RELATION_VIEW)
+	private String relationViewName = CAS.NAME_DEFAULT_SOFA;
 
-	  @Override
-	  public void process(JCas jCas) throws AnalysisEngineProcessException {
-		  for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(jCas, BinaryTextRelation.class))){
-			  if(relation.getCategory().equals("CONTAINS")){
-				  RelationArgument arg1 = relation.getArg1();
-				  RelationArgument arg2 = relation.getArg2();
-				  if(arg1.getArgument() instanceof TimeMention && arg2.getArgument() instanceof
EventMention ||
-						  arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
TimeMention){
-					  // these are the kind we keep.
-					  continue;
+	@Override
+	public void process(JCas jCas) throws AnalysisEngineProcessException {
+	      JCas relationView;
+	      try {
+	        relationView = jCas.getView(this.relationViewName);
+	      } catch (CASException e) {
+	        throw new AnalysisEngineProcessException(e);
+	      }
+	     
+	      for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(relationView,
BinaryTextRelation.class))){
+	    	  if(relation.getCategory().equals("CONTAINS")){
+	    		  RelationArgument arg1 = relation.getArg1();
+	    		  RelationArgument arg2 = relation.getArg2();
+	    		  if(arg1.getArgument() instanceof TimeMention && arg2.getArgument() instanceof
EventMention ||
+	    				  arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
TimeMention){
+	    			  // these are the kind we keep.
+	    			  continue;
+	    		  }
+//	    		  if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
EventMention){
+	    		  arg1.removeFromIndexes();
+	    		  arg2.removeFromIndexes();
+	    		  relation.removeFromIndexes();
+	    	  }
+	      }
+	      
+	}
+  }
+ 
+  public static class PreserveEventEventRelations extends JCasAnnotator_ImplBase {
+	    public static final String PARAM_RELATION_VIEW = "RelationView";
+		@ConfigurationParameter(name = PARAM_RELATION_VIEW)
+		private String relationViewName = CAS.NAME_DEFAULT_SOFA;
+
+		@Override
+		public void process(JCas jCas) throws AnalysisEngineProcessException {
+		      JCas relationView;
+		      try {
+		        relationView = jCas.getView(this.relationViewName);
+		      } catch (CASException e) {
+		        throw new AnalysisEngineProcessException(e);
+		      }
+		     
+		      for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(relationView,
BinaryTextRelation.class))){
+		    	  if(relation.getCategory().equals("CONTAINS")){
+		    		  RelationArgument arg1 = relation.getArg1();
+		    		  RelationArgument arg2 = relation.getArg2();
+		    		  if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
EventMention){
+		    			  // these are the kind we keep.
+		    			  continue;
+		    		  }
+//		    		  if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
EventMention){
+		    		  arg1.removeFromIndexes();
+		    		  arg2.removeFromIndexes();
+		    		  relation.removeFromIndexes();
+		    	  }
+		      }
+		}
+  }
+  
+  public static class MergeContainsOverlap extends JCasAnnotator_ImplBase {
+	    public static final String PARAM_RELATION_VIEW = "RelationView";
+
+	    @ConfigurationParameter(name = PARAM_RELATION_VIEW)
+	    private String relationViewName = CAS.NAME_DEFAULT_SOFA;
+
+		@Override
+		public void process(JCas jCas) throws AnalysisEngineProcessException {
+	        JCas relationView;
+	        try {
+	          relationView = jCas.getView(this.relationViewName);
+	        } catch (CASException e) {
+	          throw new AnalysisEngineProcessException(e);
+	        }
+			  for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
+					  relationView,
+					  BinaryTextRelation.class))) {
+				  if(relation.getCategory().equals("OVERLAP")){
+					  relation.setCategory("CONTAINS");
 				  }
-				  arg1.removeFromIndexes();
-				  arg2.removeFromIndexes();
-				  relation.removeFromIndexes();
 			  }
-		  }
-	  }	  
+		}
   }
-
-  public static class RemoveNonTLINKRelations extends JCasAnnotator_ImplBase {
+  
+/*  public static class RemoveNonTLINKRelations extends JCasAnnotator_ImplBase {
     @Override
     public void process(JCas jCas) throws AnalysisEngineProcessException {
       for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
@@ -299,7 +487,7 @@ public class EvaluationOfTemporalRelatio
         }
       }
     }
-  }
+  }*/
 
   public static class RemoveCrossSentenceRelations extends JCasAnnotator_ImplBase {
 
@@ -352,6 +540,10 @@ public class EvaluationOfTemporalRelatio
   }
 
   public static class RemoveNonContainsRelations extends JCasAnnotator_ImplBase {
+	    public static final String PARAM_RELATION_VIEW = "RelationView";
+
+	    @ConfigurationParameter(name = PARAM_RELATION_VIEW)
+	    private String relationViewName = CAS.NAME_DEFAULT_SOFA;
 	  @Override
 	  public void process(JCas jCas) throws AnalysisEngineProcessException {
 		  for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
@@ -378,6 +570,90 @@ public class EvaluationOfTemporalRelatio
       }
     }
   }
+
+  /**
+   * Holds a set of parameters for a relation extraction model
+   */
+  public static class ParameterSettings {
+    public boolean classifyBothDirections;
+
+    public float probabilityOfKeepingANegativeExample;
+
+    public String svmKernel;
+
+    public int svmKernelIndex;
+
+    public double svmCost;
+
+    public double svmGamma;
+
+    public String secondKernel;
+    public int secondKernelIndex;
+    public CompositeKernel.ComboOperator comboOperator;
+    public double tkWeight;
+    public double lambda;
+
+    public AnnotationStatistics<String> stats;
+
+    static List<String> SVM_KERNELS = Arrays.asList(
+        "linear",
+        "polynomial",
+        "radial basis function",
+        "sigmoid",
+        "user",
+        "tk");
+
+    public ParameterSettings(
+        boolean classifyBothDirections,
+        float probabilityOfKeepingANegativeExample,
+        String svmKernel,
+        double svmCost,
+        double svmGamma,
+        String secondKernel,
+        CompositeKernel.ComboOperator comboOperator,
+        double tkWeight,
+        double lambda) {
+      super();
+      this.classifyBothDirections = classifyBothDirections;
+      this.probabilityOfKeepingANegativeExample = probabilityOfKeepingANegativeExample;
+      this.svmKernel = svmKernel;
+      this.svmKernelIndex = SVM_KERNELS.indexOf(this.svmKernel);
+      if (this.svmKernelIndex == -1) {
+        throw new IllegalArgumentException("Unrecognized kernel: " + this.svmKernel);
+      }
+      this.svmCost = svmCost;
+      this.svmGamma = svmGamma;
+      this.secondKernel = secondKernel;
+      this.secondKernelIndex = SVM_KERNELS.indexOf(this.secondKernel);
+      this.comboOperator = comboOperator;
+      this.tkWeight = tkWeight;
+      this.lambda = lambda;
+    }
+
+    @Override
+    public String toString() {
+      StringBuffer buff = new StringBuffer();
+//      buff.append("Bothdirections=");
+//      buff.append(classifyBothDirections);
+//      buff.append(",downsamplingratio=");
+//      buff.append(probabilityOfKeepingANegativeExample);
+      buff.append(",Kernel=");
+      buff.append(svmKernel);
+      buff.append(",Cost=");
+      buff.append(svmCost);
+      buff.append(",Gamma=");
+      buff.append(svmGamma);
+      buff.append(",secondKernel=");
+      buff.append(secondKernel);
+      buff.append(",operator=");
+      buff.append(comboOperator);
+      buff.append(",tkWeight=");
+      buff.append(tkWeight);
+      buff.append(",lambda=");
+      buff.append(lambda);
+      return buff.toString();
+    }
+  }
   
   public static class AddTransitiveContainsRelations extends JCasAnnotator_ImplBase {
 

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/THYMEData.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/THYMEData.java?rev=1493804&r1=1493803&r2=1493804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/THYMEData.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/THYMEData.java
Mon Jun 17 15:17:47 2013
@@ -1,6 +1,9 @@
 package org.apache.ctakes.temporal.eval;
 
+import java.io.File;
+import java.io.FilenameFilter;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -44,4 +47,25 @@ public class THYMEData {
     }
     return items;
   }
+  
+  public static List<File> getFilesFor(List<Integer> patientSets, File rawTextDirectory)
{
+	  if ( !rawTextDirectory.exists() ) {
+		  return Collections.emptyList();
+	  }
+	  List<File> files = new ArrayList<File>();
+	  for (Integer set : patientSets) {
+		  final int setNum = set;
+		  for (File file : rawTextDirectory.listFiles(new FilenameFilter(){
+			  @Override
+			  public boolean accept(File dir, String name) {
+				  return name.contains(String.format("ID%03d", setNum));
+			  }})) {
+			  // skip hidden files like .svn
+			  if (!file.isHidden()) {
+				  files.add(file);
+			  } 
+		  }
+	  }
+	  return files;
+  }
 }



Mime
View raw message