ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1734174 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java
Date Tue, 08 Mar 2016 22:34:21 GMT
Author: clin
Date: Tue Mar  8 22:34:21 2016
New Revision: 1734174

URL: http://svn.apache.org/viewvc?rev=1734174&view=rev
Log:
add more features for an event, those features will benefit DocTimeRel:
*if this event is the left-most or right-most in a sentence.
*the modality and polarity of this event.

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java?rev=1734174&r1=1734173&r2=1734174&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventPropertyExtractor.java
Tue Mar  8 22:34:21 2016
@@ -19,43 +19,96 @@
 package org.apache.ctakes.temporal.ae.feature;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 //import java.util.logging.Logger;
+import java.util.Set;
 
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 import org.cleartk.ml.Feature;
 import org.cleartk.ml.feature.extractor.CleartkExtractorException;
 import org.cleartk.ml.feature.extractor.FeatureExtractor1;
 
-public class EventPropertyExtractor implements FeatureExtractor1 {
+public class EventPropertyExtractor implements FeatureExtractor1<Annotation> {
 
-  private String name;
-  
-//  private Logger logger = Logger.getLogger(this.getClass().getName());
-
-  public EventPropertyExtractor() {
-    super();
-    this.name = "EventContextualModality";
-    
-  }
-
-  @Override
-  public List<Feature> extract(JCas view, Annotation annotation) throws CleartkExtractorException
{
-	  List<Feature> features = new ArrayList<>();
-	  
-	  //1 get event:
-	  EventMention event = (EventMention)annotation;
-	  if(event.getEvent()!= null && event.getEvent().getProperties() != null){
-	    String contextModal = event.getEvent().getProperties().getContextualModality();
-	    if ( "GENERIC".equals(contextModal) ){
-	      Feature contexmod = new Feature(this.name, contextModal);
-	      features.add(contexmod);
-	      //		  logger.info("found a event: "+ contextModal);
-	    }
-	  }
-	  return features;
-  }
+	//	private String name;
+	private static Integer polarity;
+
+	//  private Logger logger = Logger.getLogger(this.getClass().getName());
+
+	public EventPropertyExtractor() {
+		super();
+		//		this.name = "EventContextualModality";
+
+	}
+
+	@Override
+	public List<Feature> extract(JCas view, Annotation annotation) throws CleartkExtractorException
{
+		List<Feature> features = new ArrayList<>();
+
+		//1 get event:
+		EventMention event = (EventMention)annotation;
+		//		if(event.getEvent()!= null && event.getEvent().getProperties() != null){
+		//			String contextModal = event.getEvent().getProperties().getContextualModality();
+		//			if ( "GENERIC".equals(contextModal) ){
+		//				Feature contexmod = new Feature(this.name, contextModal);
+		//				features.add(contexmod);
+		//				//		  logger.info("found a event: "+ contextModal);
+		//			}
+		//		}
+
+		Set<Sentence> coveringSents = new HashSet<>();
+		coveringSents.addAll(JCasUtil.selectCovering(view, Sentence.class, event.getBegin(), event.getEnd()));
+
+
+		for(Sentence coveringSent : coveringSents){
+			List<EventMention> events = JCasUtil.selectCovered(EventMention.class, coveringSent);
+			List<EventMention> realEvents = new ArrayList<>();
+			for(EventMention eventa : events){
+				// filter out ctakes events
+				if(eventa.getClass().equals(EventMention.class)){
+					realEvents.add(eventa);
+				}
+			}
+			events = realEvents;
+			if( events.size()>0){
+				EventMention anchor = events.get(0);
+				EventMention end    = events.get(events.size()-1);
+				if(event == anchor){
+					features.add(new Feature("LeftMostEvent"));
+				}else if( event == end){
+					features.add(new Feature("RightMostEvent"));
+				}
+			}
+		}
+
+		features.addAll(getEventFeats("mentionProperty", event));
+
+		return features;
+	}
+
+	private static Collection<? extends Feature> getEventFeats(String name, EventMention
mention) {
+		List<Feature> feats = new ArrayList<>();
+		//add contextual modality as a feature
+		if(mention.getEvent()==null || mention.getEvent().getProperties() == null){
+			return feats;
+		}
+		String contextualModality = mention.getEvent().getProperties().getContextualModality();
+		if (contextualModality != null)
+			feats.add(new Feature(name + "_modality", contextualModality));
+
+		polarity = mention.getEvent().getProperties().getPolarity();
+		if(polarity!=null )
+			feats.add(new Feature(name + "_polarity", polarity));
+		//    feats.add(new Feature(name + "_category", mention.getEvent().getProperties().getCategory()));//null
+		//    feats.add(new Feature(name + "_degree", mention.getEvent().getProperties().getDegree()));//null
+		
+		return feats;
+	}
 
 }



Mime
View raw message