Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.ctakes.temporal.ae.feature;
  
  import java.util.List;
  import java.util.Map;
  
 import  org.cleartk.ml.Feature;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.Bag;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.Covered;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.FirstCovered;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.Following;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.LastCovered;
 import  org.cleartk.ml.feature.extractor.CleartkExtractor.Preceding;
 import  org.cleartk.ml.feature.extractor.DistanceExtractor;
 import  org.cleartk.ml.feature.extractor.CoveredTextExtractor;
 import  org.cleartk.ml.feature.extractor.NamingExtractor1;
 import  org.cleartk.ml.feature.extractor.FeatureExtractor1;
 import  org.cleartk.ml.feature.extractor.CombinedExtractor1;
 
 
 	private FeatureExtractor1 coveredText = new CoveredTextExtractor();

First word of the mention, last word of the mention, all words of the mention as a bag, the preceding 3 words, the following 3 words
 
 	private FeatureExtractor1 tokenContext = new CleartkExtractor(
 			BaseToken.class,
 			new FirstCovered(1),
 			new LastCovered(1),
 			new Bag(new Covered()),
 			new Preceding(3),
 			new Following(3));

All extractors for mention 1, with features named to distinguish them from mention 2
 
 	private FeatureExtractor1 mention1CoveredFeaturesExtractor = new NamingExtractor1(
 			"mention1",
 
 	private FeatureExtractor1 mention1ContextFeaturesExtractor = new NamingExtractor1(
 			"mention1",
All extractors for mention 2, with features named to distinguish them from mention 1
 
 	private FeatureExtractor1 mention2CoveredFeaturesExtractor = new NamingExtractor1(
 			"mention2",
 	
 	private FeatureExtractor1 mention2ContextFeaturesExtractor = new NamingExtractor1(
 			"mention2",
First word, last word, and all words between the mentions
 
 	private CleartkExtractor tokensBetween = new CleartkExtractor(
 			BaseToken.class,
 			new NamingExtractor1("BetweenMentions"),
 			new FirstCovered(1),
 			new LastCovered(1),
 			new Bag(new Covered()));

Number of words between the mentions
 
 	private DistanceExtractor nTokensBetween = new DistanceExtractor(nullBaseToken.class);
 
 	public List<Feature> extract(JCas jCasIdentifiedAnnotation mention1IdentifiedAnnotation mention2)
 		Map<EventMentionCollection<EventMention>> coveringMap =
 				JCasUtil.indexCovering(jCasEventMention.classEventMention.class);
 
 		List<Feature> features = new ArrayList<>();
 		Annotation arg1 = mention1;
 		Annotation arg2 = mention2;
 
 		if(mention1 instanceof EventMention){
 			Collection<EventMentioneventList = coveringMap.get(mention1);
 
 			//find the covering UMLS entity
 			for(EventMention covEvent : eventList){
 				features.addAll(this..extract(jCascovEvent));
 				features.addAll(this..extractBetween(jCascovEventarg2));
				features.addAll(this..extract(jCascovEventarg2));
			}
		}
		//find the longest covering UMLS span for mention1
		if(mention2 instanceof EventMention){
			Collection<EventMentioneventList = coveringMap.get(mention2);
			//find the longest span entity
			for(EventMention covEvent : eventList){
				features.addAll(this..extract(jCascovEvent));
				features.addAll(this..extractBetween(jCasarg1covEvent));
				features.addAll(this..extract(jCasarg1covEvent));
			}
		}
		features.addAll(this..extract(jCasarg1));
		features.addAll(this..extract(jCasarg2));
		features.addAll(this..extractBetween(jCasarg1arg2));
		features.addAll(this..extract(jCasarg1arg2));
		return features;
	}
New to GrepCode? Check out our FAQ X