ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1598649 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature: NumberOfEventTimeBetweenCandidatesExtractor.java TemporalAttributeFeatureExtractor.java TemporalAttributeForMixEventTimeExtractor.java
Date Fri, 30 May 2014 15:56:42 GMT
Author: clin
Date: Fri May 30 15:56:41 2014
New Revision: 1598649

URL: http://svn.apache.org/r1598649
Log:
add three feature extractors for temporal relation discovery:
1. TemporalAttributeFE: for event-time pairs, get the attributes of event and time, disregard
argument order.
2. TemporalAttributeForMixEventTimeExtractor: get attributes for both event-time and event-event
pairs.
3. NumberOfEventTimeBetweenCandidatesFE: count how many events or times are between two candidates.

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NumberOfEventTimeBetweenCandidatesExtractor.java
  (with props)
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeForMixEventTimeExtractor.java
  (with props)
Modified:
    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/NumberOfEventTimeBetweenCandidatesExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NumberOfEventTimeBetweenCandidatesExtractor.java?rev=1598649&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NumberOfEventTimeBetweenCandidatesExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NumberOfEventTimeBetweenCandidatesExtractor.java
Fri May 30 15:56:41 2014
@@ -0,0 +1,52 @@
+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;
+import org.uimafit.util.JCasUtil;
+
+public class NumberOfEventTimeBetweenCandidatesExtractor implements
+RelationFeaturesExtractor {
+
+	@SuppressWarnings("null")
+	@Override
+	public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
+			IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
+		ArrayList<Feature> feats = new ArrayList<>();
+		
+		//suppose arg1 is before arg2
+		int begin = arg1.getEnd();
+		int end   = arg2.getBegin();
+		
+		//if arg1 is after arg2
+		if (begin > end ){
+			begin = arg2.getEnd();
+			end   = arg1.getBegin();
+		}
+		
+		if(begin > end){
+			return feats;
+		}
+		
+		int eventsInBetween = 0;
+		int timesInBetween  = 0;
+		
+		List<EventMention> events = JCasUtil.selectCovered(jCas, EventMention.class, begin,
end);
+		List<TimeMention> times   = JCasUtil.selectCovered(jCas, TimeMention.class, begin,
end);
+		eventsInBetween = events==null? 0: events.size();
+		timesInBetween  = times==null? 0: times.size();
+		feats.add(new Feature("NumOfEvents_InBetween", eventsInBetween));
+		feats.add(new Feature("NumOfTimes_InBetween", timesInBetween));
+		feats.add(new Feature("NumOfEventsAndTimes_InBetween", timesInBetween+eventsInBetween));
+
+		return feats;
+	}
+
+}

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

Modified: 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=1598649&r1=1598648&r2=1598649&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeFeatureExtractor.java
Fri May 30 15:56:41 2014
@@ -6,9 +6,11 @@ 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;
+import org.uimafit.util.JCasUtil;
 
 public class TemporalAttributeFeatureExtractor implements
 		RelationFeaturesExtractor {
@@ -16,27 +18,29 @@ public class TemporalAttributeFeatureExt
 	@Override
 	public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
 			IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
-		ArrayList<Feature> feats = new ArrayList<Feature>();
+		ArrayList<Feature> feats = new ArrayList<>();
 		EventMention event = null;
-		IdentifiedAnnotation time = 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(arg2.getBegin() <= arg1.getBegin() && arg2.getEnd() <= arg1.getEnd()){
+//			IdentifiedAnnotation temp = arg1;
+//			arg1 = arg2;
+//			arg2 = temp;
+//		}
 
-		if(arg1 instanceof EventMention){
-			event = (EventMention) arg1;
-			time = arg2;
-			feats.add(new Feature("Arg1-Event-Modality", event.getEvent().getProperties().getContextualModality()));
-			feats.add(new Feature("Arg2-Time-Class-" + time.getClass()));
-		}else{
-			time = arg1;
-			event = (EventMention) arg2;
-			feats.add(new Feature("Arg1-Timex-", time.getClass()));
-			feats.add(new Feature("Arg2-Event-", event.getEvent().getProperties().getContextualModality()));
+		if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
+			event = JCasUtil.selectCovering(jCas, EventMention.class, arg1.getBegin(), arg1.getEnd()).get(0);
+			time = (TimeMention)arg2;
+			if(event!=null && event.getEvent()!=null)
+				feats.add(new Feature("Event-Modality-", event.getEvent().getProperties().getContextualModality()));
+			feats.add(new Feature("Time-Class-", time.getTimeClass()));
+		}else if(arg2 instanceof EventMention && arg1 instanceof TimeMention){
+			time = (TimeMention)arg1;
+			event = JCasUtil.selectCovering(jCas, EventMention.class, arg2.getBegin(), arg2.getEnd()).get(0);
+			feats.add(new Feature("Timex-Class-", time.getTimeClass()));
+			if(event!=null && event.getEvent()!=null)
+				feats.add(new Feature("Event-Modality-", event.getEvent().getProperties().getContextualModality()));
 		}
 		
 		

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeForMixEventTimeExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeForMixEventTimeExtractor.java?rev=1598649&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeForMixEventTimeExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/TemporalAttributeForMixEventTimeExtractor.java
Fri May 30 15:56:41 2014
@@ -0,0 +1,53 @@
+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;
+import org.uimafit.util.JCasUtil;
+
+public class TemporalAttributeForMixEventTimeExtractor implements
+RelationFeaturesExtractor {
+
+	@SuppressWarnings("null")
+	@Override
+	public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
+			IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
+		ArrayList<Feature> feats = new ArrayList<>();
+		EventMention event = null;
+		TimeMention time = null;
+
+		if(arg1 instanceof EventMention){
+			event = JCasUtil.selectCovering(jCas, EventMention.class, arg1.getBegin(), arg1.getEnd()).get(0);
+			if( event != null && event.getEvent() !=null ){
+				feats.add(new Feature("Arg1-Event-Modality", event.getEvent().getProperties().getContextualModality()));
+			}
+		}else if(arg1 instanceof TimeMention){
+			time = (TimeMention) arg1;
+			if( time != null){
+				feats.add(new Feature("Arg1-Timex-", time.getTimeClass()));
+			}			
+		}
+
+		if(arg2 instanceof TimeMention){
+			time = (TimeMention) arg2;
+			if(time != null){
+				feats.add(new Feature("Arg2-Timex-", time.getTimeClass()));
+			}
+		}else if(arg2 instanceof EventMention){
+			event = JCasUtil.selectCovering(jCas, EventMention.class, arg2.getBegin(), arg2.getEnd()).get(0);
+			if(event !=null && event.getEvent() !=null ){
+				feats.add(new Feature("Arg2-Event-Modality", event.getEvent().getProperties().getContextualModality()));
+			}
+		}
+
+		return feats;
+	}
+
+}

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



Mime
View raw message