ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1477352 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature: TemporalAttributeFeatureExtractor.java TemporalFTExtractor.java
Date Mon, 29 Apr 2013 21:27:40 GMT
Author: tmill
Date: Mon Apr 29 21:27:38 2013
New Revision: 1477352

URL: http://svn.apache.org/r1477352
Log:
Two new features for temporal relation extraction.

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
  (with props)
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalFTExtractor.java
  (with props)

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java?rev=1477352&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
Mon Apr 29 21:27:38 2013
@@ -0,0 +1,47 @@
+package org.apache.ctakes.temporal.ae.feature;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
+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;
+
+public class TemporalAttributeFeatureExtractor 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;
+
+		// swap the order if necessary:
+		if(arg2.getBegin() <= arg1.getBegin() && arg2.getEnd() <= arg1.getEnd()){
+			IdentifiedAnnotation temp = arg1;
+			arg1 = arg2;
+			arg2 = temp;
+		}
+
+		if(arg1 instanceof EventMention){
+			event = (EventMention) arg1;
+			time = (TimeMention) arg2;
+			feats.add(new Feature("ARG1-EVENT-" + event.getEvent().getProperties().getContextualModality()));
+			feats.add(new Feature("ARG2-TIMEX-" + time.getTimeClass()));
+		}else{
+			time = (TimeMention) arg1;
+			event = (EventMention) arg2;
+			feats.add(new Feature("ARG1-TIMEX-" + time.getTimeClass()));
+			feats.add(new Feature("ARG2-EVENT-" + event.getEvent().getProperties().getContextualModality()));
+		}
+		
+		
+		return feats;
+	}
+
+}

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

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalFTExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalFTExtractor.java?rev=1477352&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalFTExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalFTExtractor.java
Mon Apr 29 21:27:38 2013
@@ -0,0 +1,84 @@
+package org.apache.ctakes.temporal.ae.feature;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ctakes.constituency.parser.treekernel.TreeExtractor;
+import org.apache.ctakes.constituency.parser.util.AnnotationTreeUtils;
+import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
+import org.apache.ctakes.typesystem.type.syntax.TopTreebankNode;
+import org.apache.ctakes.typesystem.type.syntax.TreebankNode;
+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.ctakes.utils.tree.SimpleTree;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.cleartk.classifier.Feature;
+
+public class TemporalFTExtractor implements RelationFeaturesExtractor {
+
+	public static final String FEAT_NAME = "TK_FT";
+	
+	@Override
+	public List<Feature> extract(JCas jcas, IdentifiedAnnotation arg1,
+			IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
+		List<Feature> features = new ArrayList<Feature>();
+		// first get the root and print it out...
+		TopTreebankNode root = AnnotationTreeUtils.getTreeCopy(jcas, AnnotationTreeUtils.getAnnotationTree(jcas,
arg1));
+		
+		if(root == null){
+			SimpleTree fakeTree = new SimpleTree("(S (NN null))");
+			features.add(new Feature(FEAT_NAME, fakeTree.toString()));
+			return features;
+		}
+		
+		// swap the order if necessary:
+		if(arg2.getBegin() <= arg1.getBegin() && arg2.getEnd() <= arg1.getEnd()){
+			IdentifiedAnnotation temp = arg1;
+			arg1 = arg2;
+			arg2 = temp;
+		}
+		
+		String a1type, a2type;
+		String eventModality="";
+		String timeClass;
+		
+		if(arg1 instanceof EventMention){
+			eventModality = ((EventMention)arg1).getEvent().getProperties().getContextualModality();
+			timeClass = ((TimeMention)arg2).getTimeClass();
+			
+			a1type = "EVENT-"+eventModality;
+			a2type = "TIMEX-"+timeClass;
+		}else{
+			eventModality = ((EventMention)arg2).getEvent().getProperties().getContextualModality();
+			timeClass = ((TimeMention)arg1).getTimeClass();
+			
+			a1type = "TIMEX-"+timeClass;
+			a2type = "EVENT-"+eventModality;
+		}
+		
+		TreebankNode t1 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg1, "ARG1-"+a1type);
+		TreebankNode t2 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg2, "ARG2-"+a2type);
+
+//		addOtherTimes(jcas,root, arg1, arg2);
+				
+		SimpleTree tree = null;
+		if(t1.getBegin() <= t2.getBegin() && t1.getEnd() >= t2.getEnd()){
+			// t1 encloses t2
+			tree = TreeExtractor.getSimpleClone(t1);
+		}else if(t2.getBegin() <= t1.getBegin() && t2.getEnd() >= t1.getEnd()){
+			// t2 encloses t1
+			tree = TreeExtractor.getSimpleClone(t2);
+		}else{
+//			tree = TreeExtractor.extractPathEnclosedTree(t1, t2, jcas);
+			tree = TreeExtractor.getSimpleClone(root);
+		}
+
+		TemporalPETExtractor.moveTimexDownToNP(tree);
+		
+		features.add(new Feature(FEAT_NAME, tree.toString()));
+		return features;
+	}
+
+}

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



Mime
View raw message