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 http://www.apache.org/licenses/LICENSE-2.0 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.
 
 package org.apache.ctakes.temporal.ae.feature;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.cleartk.ml.Feature;
 
 public class NearestFlagFeatureExtractor implements
 
 	public List<Feature> extract(JCas jCasIdentifiedAnnotation arg1,
 		ArrayList<Feature> feats = new ArrayList<Feature>();
 		EventMention event = 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(arg1 instanceof EventMention){
 			event = (EventMentionarg1;
 			time = (TimeMentionarg2;
 		}else{
 			time = (TimeMentionarg1;
 			event = (EventMentionarg2;
 		}
 		
 		//1 get covering sentence:
 		Map<EventMentionCollection<Sentence>> eventCoveringMap =
 				JCasUtil.indexCovering(jCasEventMention.classSentence.class);
 		Collection<SentenceeventSentList = eventCoveringMap.get(event);
 		Map<TimeMentionCollection<Sentence>> timeCoveringMap =
 				JCasUtil.indexCovering(jCasTimeMention.classSentence.class);
 		Collection<SentencetimeSentList = timeCoveringMap.get(time);
 
 		//2 get TimeX
 		Map<IntegerTimeMentiontimeDistMap = null;
 		Map<IntegerEventMentioneventDistMap = null;
 		
 		if (eventSentList != null && !eventSentList.isEmpty()){
 			timeDistMap = new TreeMap<IntegerTimeMention>();
 
 			for(Sentence sent : eventSentList) {
 				for (TimeMention atime : JCasUtil.selectCovered(jCasTimeMention.classsent)) {
 					timeDistMap.put(Math.abs(atime.getBegin() - event.getBegin()), atime);
 				}
 			}
 
 			//get the closest Time Expression feature
 			for (Map.Entry<IntegerTimeMentionentry : timeDistMap.entrySet()) {
 				ifentry.getValue().equals(time)){
 					Feature indicator = new Feature("ClosestPair""ClosestPair");
 					feats.add(indicator);
 					return feats;
 				}
 				break;
 			}
 		}
 
 		if (timeSentList != null && !timeSentList.isEmpty()){
 			eventDistMap = new TreeMap<IntegerEventMention>();
 
 			for(Sentence sent : timeSentList) {
 				for (EventMention aEvent : JCasUtil.selectCovered(jCasEventMention.classsent)) {
 					eventDistMap.put(Math.abs(aEvent.getBegin() - time.getBegin()), aEvent);
				}
			}
			//get the closest Event feature
			for (Map.Entry<IntegerEventMentionentry : eventDistMap.entrySet()) {
				ifentry.getValue().equals(event)){
					Feature indicator = new Feature("ClosestPair""ClosestPair");
					feats.add(indicator);
				}
				break;
			}
		}
		return feats;
	}
New to GrepCode? Check out our FAQ X