ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1514895 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae: EventTimeRelationAnnotator.java feature/DependencyFeatureExtractor.java
Date Fri, 16 Aug 2013 21:04:57 GMT
Author: clin
Date: Fri Aug 16 21:04:57 2013
New Revision: 1514895

URL: http://svn.apache.org/r1514895
Log:
ctakes-temporal: add dependency features for event-time pairs

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyFeatureExtractor.java
  (with props)
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/EventTimeRelationAnnotator.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=1514895&r1=1514894&r2=1514895&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
Fri Aug 16 21:04:57 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.DependencyFeatureExtractor;
 import org.apache.ctakes.temporal.ae.feature.NearestFlagFeatureExtractor;
 //import org.apache.ctakes.temporal.ae.feature.TemporalAttributeFeatureExtractor;
 import org.apache.ctakes.temporal.ae.feature.treekernel.EventTimeFlatTreeFeatureExtractor;
@@ -35,85 +36,86 @@ import com.google.common.collect.Lists;
 
 public class EventTimeRelationAnnotator extends RelationExtractorAnnotator {
 
-  public static AnalysisEngineDescription createDataWriterDescription(
-      Class<? extends DataWriter<String>> dataWriterClass,
-      File outputDirectory,
-      double probabilityOfKeepingANegativeExample) throws ResourceInitializationException
{
-    return AnalysisEngineFactory.createPrimitiveDescription(
-        EventTimeRelationAnnotator.class,
-        CleartkAnnotator.PARAM_IS_TRAINING,
-        true,
-        DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
-        dataWriterClass,
-        DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
-        outputDirectory,
-        RelationExtractorAnnotator.PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE,
-        // not sure why this has to be cast; something funny going on in uimaFIT maybe?
-        (float) probabilityOfKeepingANegativeExample);
-  }
-
-  public static AnalysisEngineDescription createAnnotatorDescription(File modelDirectory)
-      throws ResourceInitializationException {
-    return AnalysisEngineFactory.createPrimitiveDescription(
-        EventTimeRelationAnnotator.class,
-        CleartkAnnotator.PARAM_IS_TRAINING,
-        false,
-        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
-        new File(modelDirectory, "model.jar"));
-  }
-
-  @Override
-  protected List<RelationFeaturesExtractor> getFeatureExtractors() {
-    return Lists.newArrayList(
-    						  new TokenFeaturesExtractor()
-    						, new PartOfSpeechFeaturesExtractor()
-//    						, new TemporalAttributeFeatureExtractor()
-    						, new EventTimeFlatTreeFeatureExtractor()
-    						, new TemporalPETExtractor()
-    						, new TemporalPathExtractor()
-    						, new NearestFlagFeatureExtractor()
-    						);
-  }
+	public static AnalysisEngineDescription createDataWriterDescription(
+			Class<? extends DataWriter<String>> dataWriterClass,
+					File outputDirectory,
+					double probabilityOfKeepingANegativeExample) throws ResourceInitializationException
{
+		return AnalysisEngineFactory.createPrimitiveDescription(
+				EventTimeRelationAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING,
+				true,
+				DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
+				dataWriterClass,
+				DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
+				outputDirectory,
+				RelationExtractorAnnotator.PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE,
+				// not sure why this has to be cast; something funny going on in uimaFIT maybe?
+				(float) probabilityOfKeepingANegativeExample);
+	}
+
+	public static AnalysisEngineDescription createAnnotatorDescription(File modelDirectory)
+			throws ResourceInitializationException {
+		return AnalysisEngineFactory.createPrimitiveDescription(
+				EventTimeRelationAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING,
+				false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				new File(modelDirectory, "model.jar"));
+	}
+
+	@Override
+	protected List<RelationFeaturesExtractor> getFeatureExtractors() {
+		return Lists.newArrayList(
+				new TokenFeaturesExtractor()
+				, new PartOfSpeechFeaturesExtractor()
+				//    						, new TemporalAttributeFeatureExtractor()
+				, new EventTimeFlatTreeFeatureExtractor()
+				, new TemporalPETExtractor()
+				, new TemporalPathExtractor()
+				, new NearestFlagFeatureExtractor()
+				, new DependencyFeatureExtractor()
+				);
+	}
 
-  @Override
+	@Override
 	protected Class<? extends Annotation> getCoveringClass() {
 		return Sentence.class;
 	}
-  
-  @Override
-  public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(
-      JCas jCas,
-      Annotation sentence) {
-    List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
-    for (EventMention event : JCasUtil.selectCovered(jCas, EventMention.class, sentence))
{
-      // ignore subclasses like Procedure and Disease/Disorder
-      if (event.getClass().equals(EventMention.class)) {
-        for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, sentence))
{
-          pairs.add(new IdentifiedAnnotationPair(event, time));
-        }
-      }
-    }
-    return pairs;
-  }
-
-  @Override
-  protected String getRelationCategory(
-      Map<List<Annotation>, BinaryTextRelation> relationLookup,
-      IdentifiedAnnotation arg1,
-      IdentifiedAnnotation arg2) {
-    BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
-    String category = null;
-    if (relation != null) {
-      category = relation.getCategory();
-    } else {
-      relation = relationLookup.get(Arrays.asList(arg2, arg1));
-      if (relation != null) {
-        category = relation.getCategory() + "-1";
-      }
-    }
-    if (category == null && coin.nextDouble() <= this.probabilityOfKeepingANegativeExample)
{
-      category = NO_RELATION_CATEGORY;
-    }
-    return category;
-  }
+
+	@Override
+	public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(
+			JCas jCas,
+			Annotation sentence) {
+		List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
+		for (EventMention event : JCasUtil.selectCovered(jCas, EventMention.class, sentence)) {
+			// ignore subclasses like Procedure and Disease/Disorder
+			if (event.getClass().equals(EventMention.class)) {
+				for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, sentence)) {
+					pairs.add(new IdentifiedAnnotationPair(event, time));
+				}
+			}
+		}
+		return pairs;
+	}
+
+	@Override
+	protected String getRelationCategory(
+			Map<List<Annotation>, BinaryTextRelation> relationLookup,
+			IdentifiedAnnotation arg1,
+			IdentifiedAnnotation arg2) {
+		BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
+		String category = null;
+		if (relation != null) {
+			category = relation.getCategory();
+		} else {
+			relation = relationLookup.get(Arrays.asList(arg2, arg1));
+			if (relation != null) {
+				category = relation.getCategory() + "-1";
+			}
+		}
+		if (category == null && coin.nextDouble() <= this.probabilityOfKeepingANegativeExample)
{
+			category = NO_RELATION_CATEGORY;
+		}
+		return category;
+	}
 }

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyFeatureExtractor.java?rev=1514895&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyFeatureExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyFeatureExtractor.java
Fri Aug 16 21:04:57 2013
@@ -0,0 +1,70 @@
+package org.apache.ctakes.temporal.ae.feature;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
+import org.apache.ctakes.typesystem.type.syntax.ConllDependencyNode;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.cleartk.classifier.Feature;
+import org.uimafit.util.JCasUtil;
+
+public class DependencyFeatureExtractor implements
+RelationFeaturesExtractor {
+
+	@Override
+	public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
+			IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
+		ArrayList<Feature> feats = new ArrayList<Feature>();
+		EventMention event = null;
+		TimeMention time = null;
+		
+		if(arg1 instanceof EventMention){
+			event = (EventMention) arg1;
+			time = (TimeMention) arg2;
+		}else{
+			time = (TimeMention) arg1;
+			event = (EventMention) arg2;
+		}		
+		//1 get covering ConllDependencyNode:
+		Map<IdentifiedAnnotation, Collection<ConllDependencyNode>> dependencyCoveringMap
=
+				JCasUtil.indexCovering(jCas, IdentifiedAnnotation.class, ConllDependencyNode.class);
+		Collection<ConllDependencyNode> eventDNodeList = dependencyCoveringMap.get(event);
+		Collection<ConllDependencyNode> timeDNodeList = dependencyCoveringMap.get(time);
+		
+		//2 get dependency relationship
+		if (timeDNodeList != null && !timeDNodeList.isEmpty() && eventDNodeList
!= null && !eventDNodeList.isEmpty()){
+			for(ConllDependencyNode timeNode : timeDNodeList) {
+				ConllDependencyNode headOfTime = timeNode.getHead();
+				for (ConllDependencyNode eventNode : eventDNodeList) {
+					if ( timeNode.getPostag() != null && eventNode.getPostag() != null){//make sure
the covering nodes are not root sentences
+						while( headOfTime != null ){
+							if (headOfTime.equals(eventNode)) {
+								Feature indicator = new Feature("DependentTo", "DependentTo");
+								feats.add(indicator);
+								return feats;
+//							}else if (headOfTime.getHead() == null){//if one of the node is dependent to the
root sentence
+//								Feature indicator = new Feature("OpenDependentTo", "OpenDependentTo");
+//								feats.add(indicator);
+//								return feats;
+							}
+							headOfTime = headOfTime.getHead();
+						}
+					}
+				}
+			}
+
+		}
+
+		Feature indicator = new Feature("NotDependent", "NotDependent");
+		feats.add(indicator);
+		return feats;
+	}
+
+}

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



Mime
View raw message