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;
 
extract the nearby nearest time, date information for any event

Author(s):
CH151862
 
 
 	private String name="EventRelaionPosition";
 
 	public List<Feature> extract(JCas jCasIdentifiedAnnotation arg1,
 		List<Feature> features = Lists.newArrayList();
 
 		List<EventMentionevents = Lists.newArrayList();
 		if(arg1 instanceof EventMentionevents.add((EventMention)arg1);
 		if(arg2 instanceof EventMentionevents.add((EventMention)arg2);
 		
 		Collection<Sentencesentences = JCasUtil.select(jCasSentence.class);
 		List<SentencesentList = Lists.newArrayList();
 		sentList.addAll(sentences);
 		int sentSize = sentList.size();
 		
 		//get covering segment:
 		Map<EventMentionCollection<Segment>> coveringMap =
 				JCasUtil.indexCovering(jCasEventMention.classSegment.class);
 		
 		Collection<EventMentionallevents = JCasUtil.select(jCasEventMention.class);
 		List<EventMentioneventList = Lists.newArrayList();
 		//filter events
 		for(EventMention eventa : allevents){
 			// filter out ctakes events
 			if(eventa.getClass().equals(EventMention.class)){
 				eventList.add(eventa);
 			}
 		}
 		int eventSize = eventList.size();
 
 		for(EventMention eventevents){
 			//check if it within the last/first 5 sentences			
 			ifsentSize >= 5){
 				ifcontainEvent(sentList.get(0), sentList.get(4), event)){
 					Feature feature = new Feature(this."Within_Top_5_sentences");
 					features.add(feature);
 				}
 				ifcontainEvent(sentList.get(sentSize-5), sentList.get(sentSize-1), event)){
 					Feature feature = new Feature(this."Within_Last_5_sentences");
 					features.add(feature);
 				}
 			}
 
 			//check if it within the last/first 5 events
 			if(eventSize >= 5){
 				ifcontainEvent(eventList.get(0), eventList.get(4), event)){
 					Feature feature = new Feature(this."Within_Top_5_events");
 					features.add(feature);
 				}
 				ifcontainEvent(eventList.get(eventSize-5), eventList.get(eventSize-1), event)){
 					Feature feature = new Feature(this."Within_Last_5_events");
 					features.add(feature);
 				}
 			}
 
			Collection<SegmentsegList = coveringMap.get(event);
			//if an event is the first/last 3 events in its section
			for(Segment seg : segList) {
				String segname = seg.getId();
				if (!segname.equals("SIMPLE_SEGMENT")){//remove simple segment
					List<EventMentionsegEvents = JCasUtil.selectCovered(jCasEventMention.classseg);
					List<EventMentionrealEvents = new ArrayList<>();
					//filtering events
					for(EventMention segevent : segEvents){
						// filter out ctakes events
						if(segevent.getClass().equals(EventMention.class)){
							realEvents.add(segevent);
						}
					}
					segEvents = realEvents;
					int segEventSize = segEvents.size();
					if(segEventSize >= 3){
						ifcontainEvent(segEvents.get(0), segEvents.get(2), event)){
							Feature feature = new Feature(this."Within_Top_3_events_of"+segname);
							features.add(feature);
						}
						ifcontainEvent(segEvents.get(segEventSize-3), segEvents.get(segEventSize-1), event)){
							Feature feature = new Feature(this."Within_Last_3_events_of"+segname);
							features.add(feature);
						}
					}
				}
			}
		}
		return features;
	}
	private static boolean containEvent(Annotation arg1Annotation arg2,
			Annotation target) {
		if(target.getBegin()>=arg1.getBegin() && target.getEnd()<= arg2.getEnd())
			return true;
		return false;
	}
New to GrepCode? Check out our FAQ X