Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 import java.util.List;
 import java.util.Set;
 public class EventArgumentPropertyExtractor implements
 	public List<Feature> extract(JCas jCasIdentifiedAnnotation arg1,
 		List<Feature> feats = new ArrayList<>();
 		Set<SentencecoveringSents = new HashSet<>();
 		ifarg1 instanceof EventMention){
 			coveringSents.addAll(JCasUtil.selectCovering(jCasSentence.classarg1.getBegin(), arg1.getEnd()));
 		}else if(arg2 instanceof EventMention){
 			coveringSents.addAll(JCasUtil.selectCovering(jCasSentence.classarg2.getBegin(), arg2.getEnd()));
 			return feats;
 		for(Sentence coveringSent : coveringSents){
 			List<EventMentionevents = JCasUtil.selectCovered(EventMention.classcoveringSent);
 			List<EventMentionrealEvents = new ArrayList<>();
 			for(EventMention event : events){
 				// filter out ctakes events
 			events = realEvents;
 				EventMention anchor = events.get(0);
 				if(arg1 == anchor){
 					feats.add(new Feature("Arg1LeftmostEvent"));
 				}else if(arg2 == anchor){
 					feats.add(new Feature("Arg2LeftmostEvent"));
 		if(arg1 instanceof EventMention){
 			feats.addAll(getEventFeats("mention1property", (EventMention)arg1));
 		if(arg2 instanceof EventMention){
 			feats.addAll(getEventFeats("mention2property", (EventMention)arg2));
 		return feats;
 	private static Collection<? extends Feature> getEventFeats(String nameEventMention 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));
 		//    feats.add(new Feature(name + "_aspect", mention.getEvent().getProperties().getContextualAspect()));//null
 		//    feats.add(new Feature(name + "_permanence", mention.getEvent().getProperties().getPermanence()));//null
 		Integer 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
		String docTimeRel = mention.getEvent().getProperties().getDocTimeRel();
			feats.add(new Feature(name + "_doctimerel"docTimeRel));
		Integer typeId = mention.getEvent().getProperties().getTypeIndexID();
		if(typeId != null)
			feats.add(new Feature(name + "_typeId"typeId));
		return feats;
New to GrepCode? Check out our FAQ X