ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1596051 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/EventAdmissionTimeAnnotator.java ae/EventDischargeTimeAnnotator.java eval/EvaluationOfTemporalRelations.java
Date Mon, 19 May 2014 20:41:48 GMT
Author: clin
Date: Mon May 19 20:41:48 2014
New Revision: 1596051

URL: http://svn.apache.org/r1596051
Log:
added event to section time annotators for i2b2 data;
add null check for arguments because several i2b2 notes (e.g. 47, 492) marked discharge Time
as null among TLINKS.  

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

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventAdmissionTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventAdmissionTimeAnnotator.java?rev=1596051&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventAdmissionTimeAnnotator.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventAdmissionTimeAnnotator.java
Mon May 19 20:41:48 2014
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ctakes.temporal.ae;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+//import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+//import java.util.Map;
+
+import org.apache.ctakes.temporal.ae.feature.ClosestVerbExtractor;
+//import org.apache.ctakes.temporal.ae.feature.CoveredTextToValuesExtractor;
+import org.apache.ctakes.temporal.ae.feature.DateAndMeasurementExtractor;
+import org.apache.ctakes.temporal.ae.feature.EventPropertyExtractor;
+import org.apache.ctakes.temporal.ae.feature.NearbyVerbTenseXExtractor;
+import org.apache.ctakes.temporal.ae.feature.SectionHeaderExtractor;
+import org.apache.ctakes.temporal.ae.feature.TimeXExtractor;
+import org.apache.ctakes.temporal.ae.feature.UmlsSingleFeatureExtractor;
+import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.relation.RelationArgument;
+//import org.apache.ctakes.temporal.ae.feature.duration.DurationExpectationFeatureExtractor;
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+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.jcas.tcas.Annotation;
+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;
+
+//import com.google.common.base.Charsets;
+
+public class EventAdmissionTimeAnnotator extends CleartkAnnotator<String> {
+
+	public static AnalysisEngineDescription createDataWriterDescription(
+			Class<? extends DataWriter<String>> dataWriterClass,
+					File outputDirectory) throws ResourceInitializationException {
+		return AnalysisEngineFactory.createPrimitiveDescription(
+				EventAdmissionTimeAnnotator.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(
+				EventAdmissionTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING,
+				false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				new File(modelDirectory, "model.jar"));
+	}
+
+	private CleartkExtractor contextExtractor;
+	private NearbyVerbTenseXExtractor verbTensePatternExtractor;
+	private SectionHeaderExtractor sectionIDExtractor;
+	private ClosestVerbExtractor closestVerbExtractor;
+	private TimeXExtractor timeXExtractor;
+	private EventPropertyExtractor genericExtractor;
+	private DateAndMeasurementExtractor dateExtractor;
+	private UmlsSingleFeatureExtractor umlsExtractor;
+	//  private CoveredTextToValuesExtractor disSemExtractor;
+	//  private DurationExpectationFeatureExtractor durationExtractor;
+
+	@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));
+		this.verbTensePatternExtractor = new NearbyVerbTenseXExtractor();
+		this.sectionIDExtractor = new SectionHeaderExtractor();
+		this.closestVerbExtractor = new ClosestVerbExtractor();
+		this.timeXExtractor = new TimeXExtractor();
+		this.genericExtractor = new EventPropertyExtractor();
+		this.dateExtractor = new DateAndMeasurementExtractor();
+		this.umlsExtractor = new UmlsSingleFeatureExtractor();
+	}
+
+	@Override
+	public void process(JCas jCas) throws AnalysisEngineProcessException {
+		//get discharge Time id: T1:
+		TimeMention admissionTime = null;
+		//TODO
+		//may need better way to identify Discharge Time other than relative span information:
+		for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, 15, 30)) {
+			if(time.getTimeClass().equals("DATE")){
+				admissionTime = time;
+				break;
+			}
+		}
+		if (admissionTime != null){
+			//get event-time1 relations:
+			Map<List<Annotation>, BinaryTextRelation> dischargeTimeRelationLookup;
+		    dischargeTimeRelationLookup = new HashMap<>();
+		    if (this.isTraining()) {
+		      dischargeTimeRelationLookup = new HashMap<>();
+		      for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class))
{
+		        Annotation arg1 = relation.getArg1().getArgument();
+		        Annotation arg2 = relation.getArg2().getArgument();
+		        // The key is a list of args so we can do bi-directional lookup
+		        if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
+		        	if( arg1==admissionTime){
+		        		dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
+		        		continue;
+		        	}
+		        }else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
+		        	if( arg2==admissionTime ){
+		        		dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
+		        		continue;
+		        	}
+		        }
+		        
+		      }
+		    }
+		    
+			for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
+				if (eventMention.getEvent() != null) {
+					List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
+					features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add nearby
verb POS pattern feature
+					features.addAll(this.sectionIDExtractor.extract(jCas, eventMention)); //add section
heading
+					features.addAll(this.closestVerbExtractor.extract(jCas, eventMention)); //add closest
verb
+					features.addAll(this.timeXExtractor.extract(jCas, eventMention)); //add the closest
time expression types
+					features.addAll(this.genericExtractor.extract(jCas, eventMention)); //add the closest
time expression types
+					features.addAll(this.dateExtractor.extract(jCas, eventMention)); //add the closest NE
type
+					features.addAll(this.umlsExtractor.extract(jCas, eventMention)); //add umls features
+					//        features.addAll(this.durationExtractor.extract(jCas, eventMention)); //add
duration feature
+					//        features.addAll(this.disSemExtractor.extract(jCas, eventMention)); //add distributional
semantic features
+					if (this.isTraining()) {
+						BinaryTextRelation relation = dischargeTimeRelationLookup.get(Arrays.asList(eventMention,
admissionTime));
+						String category = null;
+						if (relation != null) {
+							category = relation.getCategory();
+						} else {
+							relation = dischargeTimeRelationLookup.get(Arrays.asList(admissionTime, eventMention));
+							if (relation != null) {
+								if(relation.getCategory().equals("OVERLAP")){
+									category = relation.getCategory();
+								}else if (relation.getCategory().equals("BEFORE")){
+									category = "AFTER";
+								}else if (relation.getCategory().equals("AFTER")){
+									category = "BEFORE";
+								}
+							}else{
+								category = "OVERLAP";
+							}
+						}
+
+						this.dataWriter.write(new Instance<>(category, features));
+					} else {
+						String outcome = this.classifier.classify(features);
+						// add the relation to the CAS
+					    RelationArgument relArg1 = new RelationArgument(jCas);
+					    relArg1.setArgument(eventMention);
+					    relArg1.setRole("Argument");
+					    relArg1.addToIndexes();
+					    RelationArgument relArg2 = new RelationArgument(jCas);
+					    relArg2.setArgument(admissionTime);
+					    relArg2.setRole("Related_to");
+					    relArg2.addToIndexes();
+					    BinaryTextRelation relation = new BinaryTextRelation(jCas);
+					    relation.setArg1(relArg1);
+					    relation.setArg2(relArg2);
+					    relation.setCategory(outcome);
+					    relation.addToIndexes();
+					}
+				}
+			}
+		}
+	}
+}

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

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventDischargeTimeAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventDischargeTimeAnnotator.java?rev=1596051&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventDischargeTimeAnnotator.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventDischargeTimeAnnotator.java
Mon May 19 20:41:48 2014
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ctakes.temporal.ae;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+//import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+//import java.util.Map;
+
+import org.apache.ctakes.temporal.ae.feature.ClosestVerbExtractor;
+//import org.apache.ctakes.temporal.ae.feature.CoveredTextToValuesExtractor;
+import org.apache.ctakes.temporal.ae.feature.DateAndMeasurementExtractor;
+import org.apache.ctakes.temporal.ae.feature.EventPropertyExtractor;
+import org.apache.ctakes.temporal.ae.feature.NearbyVerbTenseXExtractor;
+import org.apache.ctakes.temporal.ae.feature.SectionHeaderExtractor;
+import org.apache.ctakes.temporal.ae.feature.TimeXExtractor;
+import org.apache.ctakes.temporal.ae.feature.UmlsSingleFeatureExtractor;
+import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.relation.RelationArgument;
+//import org.apache.ctakes.temporal.ae.feature.duration.DurationExpectationFeatureExtractor;
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+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.jcas.tcas.Annotation;
+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;
+
+//import com.google.common.base.Charsets;
+
+public class EventDischargeTimeAnnotator extends CleartkAnnotator<String> {
+
+	public static AnalysisEngineDescription createDataWriterDescription(
+			Class<? extends DataWriter<String>> dataWriterClass,
+					File outputDirectory) throws ResourceInitializationException {
+		return AnalysisEngineFactory.createPrimitiveDescription(
+				EventDischargeTimeAnnotator.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(
+				EventDischargeTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING,
+				false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				new File(modelDirectory, "model.jar"));
+	}
+
+	private CleartkExtractor contextExtractor;
+	private NearbyVerbTenseXExtractor verbTensePatternExtractor;
+	private SectionHeaderExtractor sectionIDExtractor;
+	private ClosestVerbExtractor closestVerbExtractor;
+	private TimeXExtractor timeXExtractor;
+	private EventPropertyExtractor genericExtractor;
+	private DateAndMeasurementExtractor dateExtractor;
+	private UmlsSingleFeatureExtractor umlsExtractor;
+	//  private CoveredTextToValuesExtractor disSemExtractor;
+	//  private DurationExpectationFeatureExtractor durationExtractor;
+
+	@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));
+		this.verbTensePatternExtractor = new NearbyVerbTenseXExtractor();
+		this.sectionIDExtractor = new SectionHeaderExtractor();
+		this.closestVerbExtractor = new ClosestVerbExtractor();
+		this.timeXExtractor = new TimeXExtractor();
+		this.genericExtractor = new EventPropertyExtractor();
+		this.dateExtractor = new DateAndMeasurementExtractor();
+		this.umlsExtractor = new UmlsSingleFeatureExtractor();
+	}
+
+	@Override
+	public void process(JCas jCas) throws AnalysisEngineProcessException {
+		//get discharge Time id: T1:
+		TimeMention dischargeTime = null;
+		//TODO
+		//may need better way to identify Discharge Time other than relative span information:
+		for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, 40, 60)) {
+			if(time.getTimeClass().equals("DATE")){
+				dischargeTime = time;
+				break;
+			}
+		}
+		if (dischargeTime != null){
+			//get event-time1 relations:
+			Map<List<Annotation>, BinaryTextRelation> dischargeTimeRelationLookup;
+		    dischargeTimeRelationLookup = new HashMap<>();
+		    if (this.isTraining()) {
+		      dischargeTimeRelationLookup = new HashMap<>();
+		      for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class))
{
+		        Annotation arg1 = relation.getArg1().getArgument();
+		        Annotation arg2 = relation.getArg2().getArgument();
+		        // The key is a list of args so we can do bi-directional lookup
+		        if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
+		        	if( arg1==dischargeTime){
+		        		dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
+		        		continue;
+		        	}
+		        }else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
+		        	if( arg2==dischargeTime ){
+		        		dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
+		        		continue;
+		        	}
+		        }
+		        
+		      }
+		    }
+		    
+			for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
+				if (eventMention.getEvent() != null) {
+					List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
+					features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add nearby
verb POS pattern feature
+					features.addAll(this.sectionIDExtractor.extract(jCas, eventMention)); //add section
heading
+					features.addAll(this.closestVerbExtractor.extract(jCas, eventMention)); //add closest
verb
+					features.addAll(this.timeXExtractor.extract(jCas, eventMention)); //add the closest
time expression types
+					features.addAll(this.genericExtractor.extract(jCas, eventMention)); //add the closest
time expression types
+					features.addAll(this.dateExtractor.extract(jCas, eventMention)); //add the closest NE
type
+					features.addAll(this.umlsExtractor.extract(jCas, eventMention)); //add umls features
+					//        features.addAll(this.durationExtractor.extract(jCas, eventMention)); //add
duration feature
+					//        features.addAll(this.disSemExtractor.extract(jCas, eventMention)); //add distributional
semantic features
+					if (this.isTraining()) {
+						BinaryTextRelation relation = dischargeTimeRelationLookup.get(Arrays.asList(eventMention,
dischargeTime));
+						String category = null;
+						if (relation != null) {
+							category = relation.getCategory();
+						} else {
+							relation = dischargeTimeRelationLookup.get(Arrays.asList(dischargeTime, eventMention));
+							if (relation != null) {
+								if(relation.getCategory().equals("OVERLAP")){
+									category = relation.getCategory();
+								}else if (relation.getCategory().equals("BEFORE")){
+									category = "AFTER";
+								}else if (relation.getCategory().equals("AFTER")){
+									category = "BEFORE";
+								}
+							}else{
+								category = "OVERLAP";
+							}
+						}
+
+						this.dataWriter.write(new Instance<>(category, features));
+					} else {
+						String outcome = this.classifier.classify(features);
+						// add the relation to the CAS
+					    RelationArgument relArg1 = new RelationArgument(jCas);
+					    relArg1.setArgument(eventMention);
+					    relArg1.setRole("Argument");
+					    relArg1.addToIndexes();
+					    RelationArgument relArg2 = new RelationArgument(jCas);
+					    relArg2.setArgument(dischargeTime);
+					    relArg2.setRole("Related_to");
+					    relArg2.addToIndexes();
+					    BinaryTextRelation relation = new BinaryTextRelation(jCas);
+					    relation.setArg1(relArg1);
+					    relation.setArg2(relArg2);
+					    relation.setCategory(outcome);
+					    relation.addToIndexes();
+					}
+				}
+			}
+		}
+	}
+}

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

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=1596051&r1=1596050&r2=1596051&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 May 19 20:41:48 2014
@@ -31,6 +31,8 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ctakes.relationextractor.eval.RelationExtractorEvaluation.HashableArguments;
+import org.apache.ctakes.temporal.ae.EventAdmissionTimeAnnotator;
+import org.apache.ctakes.temporal.ae.EventDischargeTimeAnnotator;
 import org.apache.ctakes.temporal.ae.EventTimeRelationAnnotator;
 import org.apache.ctakes.temporal.ae.EventEventRelationAnnotator;
 import org.apache.ctakes.temporal.ae.baselines.RecallBaselineEventTimeRelationAnnotator;
@@ -115,6 +117,10 @@ EvaluationOfTemporalRelations_ImplBase{
 	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);
 
+	private static final String EVENT_TIME = "event_time";
+	private static final String EVENT_EVENT = "event_event";
+	private static final String EVENT_DISCHARGE = "event_dischargeTime";
+	private static final String EVENT_ADMISSION = "event_admissionTime";
 	public static void main(String[] args) throws Exception {
 		TempRelOptions options = CliFactory.parseArguments(TempRelOptions.class, args);
     List<Integer> trainItems = null;
@@ -238,7 +244,7 @@ EvaluationOfTemporalRelations_ImplBase{
 	  if(this.skipTrain) return;
 		AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
 		aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class,
BinaryTextRelation.class));
-		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveCrossSentenceRelations.class));
+//		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveCrossSentenceRelations.class));
 		if(!this.useGoldAttributes){
 			aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveGoldAttributes.class));
 		}
@@ -256,12 +262,18 @@ EvaluationOfTemporalRelations_ImplBase{
 				TKSVMlightStringOutcomeDataWriter.class,
 				//        TKLIBSVMStringOutcomeDataWriter.class,
 				//        SVMlightStringOutcomeDataWriter.class,        
-				new File(directory,"event-time"),
+				new File(directory,EVENT_TIME),
 				params.probabilityOfKeepingANegativeExample));
 		aggregateBuilder.add(EventEventRelationAnnotator.createDataWriterDescription(
 				LIBSVMStringOutcomeDataWriter.class,
-				new File(directory,"event-event"), 
+				new File(directory,EVENT_EVENT), 
 				params.probabilityOfKeepingANegativeExample));
+		aggregateBuilder.add(EventDischargeTimeAnnotator.createDataWriterDescription(
+				LIBSVMStringOutcomeDataWriter.class,
+				new File(directory,EVENT_DISCHARGE)));
+		aggregateBuilder.add(EventAdmissionTimeAnnotator.createDataWriterDescription(
+				LIBSVMStringOutcomeDataWriter.class,
+				new File(directory,EVENT_ADMISSION)));
 		SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
 		String[] optArray;
 
@@ -288,8 +300,10 @@ EvaluationOfTemporalRelations_ImplBase{
 		}
 
 		//    HideOutput hider = new HideOutput();
-		JarClassifierBuilder.trainAndPackage(new File(directory,"event-time"), optArray);
-		JarClassifierBuilder.trainAndPackage(new File(directory,"event-event"), "-h","0","-c",
"1000");
+		JarClassifierBuilder.trainAndPackage(new File(directory,EVENT_TIME), optArray);
+		JarClassifierBuilder.trainAndPackage(new File(directory,EVENT_EVENT), "-h","0","-c", "1000");
+		JarClassifierBuilder.trainAndPackage(new File(directory,EVENT_DISCHARGE), "-h","0","-c",
"1000");
+		JarClassifierBuilder.trainAndPackage(new File(directory,EVENT_ADMISSION), "-h","0","-c",
"1000");
 		//    hider.restoreOutput();
 		//    hider.close();
 	}
@@ -300,12 +314,12 @@ EvaluationOfTemporalRelations_ImplBase{
 		AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
 		aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class));
 		
-		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
-				RemoveCrossSentenceRelations.class,
-				RemoveCrossSentenceRelations.PARAM_SENTENCE_VIEW,
-				CAS.NAME_DEFAULT_SOFA,
-				RemoveCrossSentenceRelations.PARAM_RELATION_VIEW,
-				GOLD_VIEW_NAME));
+//		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
+//				RemoveCrossSentenceRelations.class,
+//				RemoveCrossSentenceRelations.PARAM_SENTENCE_VIEW,
+//				CAS.NAME_DEFAULT_SOFA,
+//				RemoveCrossSentenceRelations.PARAM_RELATION_VIEW,
+//				GOLD_VIEW_NAME));
 		if (this.useClosure) {
 			aggregateBuilder.add(
 					AnalysisEngineFactory.createPrimitiveDescription(AddClosure.class),//AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class),
@@ -333,8 +347,10 @@ EvaluationOfTemporalRelations_ImplBase{
 
 		aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveRelations.class));
 		aggregateBuilder.add(this.baseline ? RecallBaselineEventTimeRelationAnnotator.createAnnotatorDescription(directory)
:
-			EventTimeRelationAnnotator.createAnnotatorDescription(new File(directory,"event-time")));
-		aggregateBuilder.add(EventEventRelationAnnotator.createAnnotatorDescription(new File(directory,"event-event")));
+			EventTimeRelationAnnotator.createAnnotatorDescription(new File(directory,EVENT_TIME)));
+		aggregateBuilder.add(EventEventRelationAnnotator.createAnnotatorDescription(new File(directory,EVENT_EVENT)));
+		aggregateBuilder.add(EventDischargeTimeAnnotator.createAnnotatorDescription(new File(directory,EVENT_DISCHARGE)));
+		aggregateBuilder.add(EventAdmissionTimeAnnotator.createAnnotatorDescription(new File(directory,EVENT_ADMISSION)));
     if(this.i2b2Output != null){
       aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(WriteI2B2XML.class,
WriteI2B2XML.PARAM_OUTPUT_DIR, this.i2b2Output), "TimexView", CAS.NAME_DEFAULT_SOFA);
     }
@@ -892,13 +908,19 @@ EvaluationOfTemporalRelations_ImplBase{
 		@Override
 		public void process(JCas jCas) throws AnalysisEngineProcessException {
 			
+			String fileName = ViewURIUtil.getURI(jCas).toString();
+			
 			Multimap<List<Annotation>, BinaryTextRelation> annotationsToRelation = HashMultimap.create();
 			for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class)){
 				String relationType = relation.getCategory();
 				if(validTemporalType(relationType)){
 					Annotation arg1 = relation.getArg1().getArgument();
 			        Annotation arg2 = relation.getArg2().getArgument();
-			        annotationsToRelation.put(Arrays.asList(arg1, arg2), relation);
+			        if(arg1==null || arg2==null){
+			        	System.out.println("Null argument at Doc: "+ fileName);
+			        }else{
+			        	annotationsToRelation.put(Arrays.asList(arg1, arg2), relation);
+			        }
 				}
 			}
 			for (List<Annotation> span: Lists.newArrayList(annotationsToRelation.keySet())){
@@ -977,7 +999,7 @@ EvaluationOfTemporalRelations_ImplBase{
 		}
 
 		private static boolean validTemporalType(String relationType) {
-			if(relationType.equals("CONTAINS")||relationType.equals("OVERLAP")||relationType.equals("BEFORE")||relationType.equals("ENDS-ON")||relationType.equals("BEGINS-ON"))
+			if(relationType.equals("AFTER")||relationType.equals("OVERLAP")||relationType.equals("BEFORE"))
 				return true;
 			return false;
 		}



Mime
View raw message