ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1464969 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature: EventTimeFlatTreeFeatureExtractor.java TemporalPETExtractor.java TemporalPathExtractor.java
Date Fri, 05 Apr 2013 13:18:04 GMT
Author: tmill
Date: Fri Apr  5 13:18:04 2013
New Revision: 1464969

URL: http://svn.apache.org/r1464969
Log:
Code for tree kernel features in temporal.

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPETExtractor.java
  (with props)
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPathExtractor.java
  (with props)
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventTimeFlatTreeFeatureExtractor.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventTimeFlatTreeFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventTimeFlatTreeFeatureExtractor.java?rev=1464969&r1=1464968&r2=1464969&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventTimeFlatTreeFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventTimeFlatTreeFeatureExtractor.java
Fri Apr  5 13:18:04 2013
@@ -7,6 +7,7 @@ import org.apache.ctakes.relationextract
 import org.apache.ctakes.typesystem.type.syntax.BaseToken;
 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;
@@ -32,14 +33,22 @@ public class EventTimeFlatTreeFeatureExt
 		
 		SimpleTree arg1Tree = null;
 		SimpleTree arg2Tree = null;
-		
+		String eventModality="";
+		String timeClass;
+	
 		// make sure we have the right classes
 		if(arg1 instanceof EventMention){
-			arg1Tree = new SimpleTree("EVENT");
-			arg2Tree = new SimpleTree("TIMEX");
+			eventModality = ((EventMention)arg1).getEvent().getProperties().getContextualModality();
+			timeClass = ((TimeMention)arg2).getTimeClass();
+
+			arg1Tree = new SimpleTree("EVENT-"+eventModality);
+			arg2Tree = new SimpleTree("TIMEX-"+timeClass);
 		}else{
-			arg1Tree = new SimpleTree("TIMEX");
-			arg2Tree = new SimpleTree("EVENT");
+			eventModality = ((EventMention)arg2).getEvent().getProperties().getContextualModality();
+			timeClass = ((TimeMention)arg1).getTimeClass();
+
+			arg1Tree = new SimpleTree("TIMEX-"+timeClass);
+			arg2Tree = new SimpleTree("EVENT-"+eventModality);
 		}
 		
 		List<BaseToken> tokens = JCasUtil.selectCovered(jcas, BaseToken.class, arg1.getBegin(),
arg2.getEnd());

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPETExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPETExtractor.java?rev=1464969&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPETExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPETExtractor.java
Fri Apr  5 13:18:04 2013
@@ -0,0 +1,114 @@
+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;
+import org.uimafit.util.JCasUtil;
+
+public class TemporalPETExtractor implements RelationFeaturesExtractor {
+
+	@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));
+		
+		// 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);
+		}
+
+		moveTimexDownToNP(tree);
+		
+		features.add(new Feature("TK_PET", tree.toString()));
+		return features;
+	}
+
+	private static void addOtherTimes(JCas jcas, TopTreebankNode root, IdentifiedAnnotation
arg1, IdentifiedAnnotation arg2) {
+		List<TimeMention> timexes = JCasUtil.selectCovered(TimeMention.class, root);
+		
+		for(TimeMention timex : timexes){
+			// don't want the same timex that we are looking at the argument for...
+			if(timex.getBegin() == arg1.getBegin() && timex.getEnd() == arg1.getEnd() ||
+			   timex.getBegin() == arg2.getBegin() && timex.getEnd() == arg2.getEnd()) continue;
+			// but make sure it is in the correct span...
+			if(timex.getBegin() > arg1.getBegin() && timex.getEnd() <= arg2.getBegin()){
+				AnnotationTreeUtils.insertAnnotationNode(jcas, root, timex, "TIMEX");
+			}
+		}
+	}
+
+	private static void moveTimexDownToNP(SimpleTree tree) {
+		if(tree.cat.contains("-TIMEX-")){
+			SimpleTree child = tree.children.get(0);
+			// we've found the correct node: only correct clear violations: PP -> IN NP
+			if(child.cat.contains("PP") && child.children.size() == 2 && child.children.get(0).cat.equals("IN")
&& child.children.get(1).cat.startsWith("NP")){
+				// swap labels
+				String fullCat = tree.cat;
+				tree.cat = "PP";
+				child.cat = fullCat;
+				
+				// now point the new PP at the preposition and stop the new TIMEX from pointing at it:
+				tree.children.add(0, child.children.get(0));
+				child.children.remove(0);
+			}
+			return;
+		}else if(tree.children == null || tree.children.size() == 0){
+			return;
+		}
+		// if we are not there we have to return
+		for(SimpleTree child : tree.children){
+			moveTimexDownToNP(child);
+		}
+	}
+
+}

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

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPathExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPathExtractor.java?rev=1464969&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPathExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalPathExtractor.java
Fri Apr  5 13:18:04 2013
@@ -0,0 +1,68 @@
+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 TemporalPathExtractor implements RelationFeaturesExtractor {
+
+	@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));
+		// 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);
+
+		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.extractPathTree(t1, t2);
+//		}
+
+		features.add(new Feature("TK_PATH", tree.toString()));
+		return features;
+	}
+
+}

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



Mime
View raw message