ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1480643 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/NEPredicateEventAnnotator.java eval/EvaluationOfNEPredicateEventSpans.java
Date Thu, 09 May 2013 14:07:18 GMT
Author: clin
Date: Thu May  9 14:07:18 2013
New Revision: 1480643

URL: http://svn.apache.org/r1480643
Log:
Add a baseline for event detection: Add selected NEs and Predicates to events. Evalutate:
EvaluationOfNEPredicateEventSpans  

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/NEPredicateEventAnnotator.java
  (with props)
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
  (with props)

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/NEPredicateEventAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/NEPredicateEventAnnotator.java?rev=1480643&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/NEPredicateEventAnnotator.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/NEPredicateEventAnnotator.java
Thu May  9 14:07:18 2013
@@ -0,0 +1,82 @@
+package org.apache.ctakes.temporal.ae;
+
+import java.io.File;
+
+import org.apache.ctakes.typesystem.type.refsem.Event;
+import org.apache.ctakes.typesystem.type.textsem.EntityMention;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.Predicate;
+import org.apache.ctakes.typesystem.type.textspan.Segment;
+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.jar.GenericJarClassifierFactory;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.util.JCasUtil;
+
+public class NEPredicateEventAnnotator extends TemporalEntityAnnotator_ImplBase {
+
+	public NEPredicateEventAnnotator() {
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	public void process(JCas jCas, Segment segment)
+			throws AnalysisEngineProcessException {
+		for (EntityMention neMention : JCasUtil.select(jCas, EntityMention.class)) {
+			// create the event object
+			Event event = new Event(jCas);
+			event.setConfidence(1.0f);
+
+			// create the event mention
+			EventMention eventMention = new EventMention(jCas, neMention.getBegin(), neMention.getEnd());
+			eventMention.setConfidence(1.0f);
+
+			// add the links between event, mention and properties
+			//  		  event.setProperties(eventProperties);
+			//  		  event.setMentions(neMention.getOntologyConceptArr());
+			eventMention.setEvent(event);
+			eventMention.setOntologyConceptArr(neMention.getOntologyConceptArr());
+
+			// add the annotations to the indexes
+			//  		  eventProperties.addToIndexes();
+			event.addToIndexes();
+			eventMention.addToIndexes();
+		}
+
+		//add predicates
+		for (Predicate predicate : JCasUtil.select(jCas, Predicate.class)) {
+			// create the event object
+			Event event = new Event(jCas);
+			event.setConfidence(1.0f);
+
+			// create the event mention
+			EventMention eventMention = new EventMention(jCas, predicate.getBegin(), predicate.getEnd());
+			eventMention.setConfidence(1.0f);
+
+			// add the links between event, mention and properties
+			//	  		  event.setProperties(eventProperties);
+			//	  		  event.setMentions(neMention.getOntologyConceptArr());
+			eventMention.setEvent(event);
+
+			// add the annotations to the indexes
+			//	  		  eventProperties.addToIndexes();
+			event.addToIndexes();
+			eventMention.addToIndexes();
+		}
+
+	}
+
+	public static AnalysisEngineDescription createAnnotatorDescription(File modelDirectory)
+		      throws ResourceInitializationException {
+		    return AnalysisEngineFactory.createPrimitiveDescription(
+		    	NEPredicateEventAnnotator.class,
+		    	CleartkAnnotator.PARAM_IS_TRAINING,
+		        false,
+		        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+		        new File(modelDirectory, "model.jar"));
+	}
+
+}

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

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java?rev=1480643&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
Thu May  9 14:07:18 2013
@@ -0,0 +1,91 @@
+package org.apache.ctakes.temporal.eval;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.apache.ctakes.temporal.ae.NEPredicateEventAnnotator;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.cleartk.eval.AnnotationStatistics;
+import org.uimafit.component.NoOpAnnotator;
+import org.uimafit.factory.AnalysisEngineFactory;
+
+import com.lexicalscope.jewel.cli.CliFactory;
+
+public class EvaluationOfNEPredicateEventSpans extends
+		EvaluationOfAnnotationSpans_ImplBase {
+
+	public EvaluationOfNEPredicateEventSpans(File baseDirectory,
+			File rawTextDirectory, File knowtatorXMLDirectory,
+			File xmiDirectory, File treebankDirectory,
+			Class<? extends Annotation> annotationClass) {
+		super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory,
+				xmiDirectory, treebankDirectory, annotationClass);
+		// TODO Auto-generated constructor stub
+	}
+
+	public EvaluationOfNEPredicateEventSpans(File baseDirectory,
+			File rawTextDirectory, File knowtatorXMLDirectory,
+			File xmiDirectory) {
+		super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory,
+				xmiDirectory, EventMention.class);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	protected AnalysisEngineDescription getDataWriterDescription(File directory)
+			throws ResourceInitializationException {
+		// not training a model - just using the NEs and predicates
+	    return AnalysisEngineFactory.createPrimitiveDescription(NoOpAnnotator.class);
+	}
+
+	@Override
+	protected void trainAndPackage(File directory) throws Exception {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected AnalysisEngineDescription getAnnotatorDescription(File directory)
+			throws ResourceInitializationException {
+		// not training a model - just using the NEs and predicates
+//		return AnalysisEngineFactory.createPrimitiveDescription(NoOpAnnotator.class);
+	    return NEPredicateEventAnnotator.createAnnotatorDescription(directory);
+	}
+
+	@Override
+	protected Collection<? extends Annotation> getGoldAnnotations(JCas jCas) {
+		return selectExact(jCas, EventMention.class);
+	}
+
+	@Override
+	protected Collection<? extends Annotation> getSystemAnnotations(JCas jCas) {
+		return selectExact(jCas, EventMention.class);
+	}
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception{
+		Options options = CliFactory.parseArguments(Options.class, args);
+	    List<Integer> patientSets = options.getPatients().getList();
+	    List<Integer> trainItems = THYMEData.getTrainPatientSets(patientSets);
+	    List<Integer> devItems = THYMEData.getDevPatientSets(patientSets);
+	    EvaluationOfNEPredicateEventSpans evaluation = new EvaluationOfNEPredicateEventSpans(
+	        new File("target/eval/event-spans"),
+	        options.getRawTextDirectory(),
+	        options.getKnowtatorXMLDirectory(),
+	        options.getXMIDirectory());
+	    evaluation.prepareXMIsFor(patientSets);
+	    evaluation.setLogging(Level.FINE, new File("target/eval/ctakes-event-errors.log"));
+	    AnnotationStatistics<String> stats = evaluation.trainAndTest(trainItems, devItems);
+	    System.err.println(stats);
+
+	}
+
+}

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



Mime
View raw message