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 List<Feature> extract(JCas jcasIdentifiedAnnotation arg1,
 		List<Feature> feats = new ArrayList<>();
 		EventMention eventA = null;
 		EventMention eventB = null;
 
 		//find event
 		if(arg1 instanceof EventMention){
 			eventA = (EventMentionarg1;
 		}else if(arg2 instanceof EventMention){
 			eventB = (EventMentionarg2;
 		}else{
 			return feats;
 		}
 
 		//1 get covering sentence:
 		Map<EventMentionCollection<Sentence>> coveringMap =
 				JCasUtil.indexCovering(jcasEventMention.classSentence.class);
 
 		Sentence sentenceA = getCoveringSentence(eventAcoveringMap);
 		Sentence sentenceB = getCoveringSentence(eventBcoveringMap);
 
 		//get all special annotation that is in sentence A
 		List<RangeAnnotationrangeInA = new ArrayList<>();
 		List<FractionAnnotationfracInA = new ArrayList<>();
 		List<RomanNumeralAnnotationromanInA = new ArrayList<>();
 		List<MeasurementAnnotationmeasureInA = new ArrayList<>();
 		if(sentenceA != null){
 			rangeInA.addAll(JCasUtil.selectCovered(jcasRangeAnnotation.classsentenceA));
 			if(!rangeInA.isEmpty()) feats.add(new Feature("arg1_has_nearby_""RangeAnnotation"));
 			fracInA.addAll(JCasUtil.selectCovered(jcasFractionAnnotation.classsentenceA));
 			if(!fracInA.isEmpty()) feats.add(new Feature("arg1_has_nearby_""FractionAnnotation"));
 			romanInA.addAll(JCasUtil.selectCovered(jcasRomanNumeralAnnotation.classsentenceA));
 			if(!romanInA.isEmpty()) feats.add(new Feature("arg1_has_nearby_""RomanNumeralAnnotation"));
 			measureInA.addAll(JCasUtil.selectCovered(jcasMeasurementAnnotation.classsentenceA));
 			if(!measureInA.isEmpty()) feats.add(new Feature("arg1_has_nearby_""MeasurementAnnotation"));
 		}
 
 		//get all special annotation that is in sentence B
 		List<RangeAnnotationrangeInB = new ArrayList<>();
 		List<FractionAnnotationfracInB = new ArrayList<>();
 		List<RomanNumeralAnnotationromanInB = new ArrayList<>();
 		List<MeasurementAnnotationmeasureInB = new ArrayList<>();
 		if(sentenceB != null){
 			rangeInB.addAll(JCasUtil.selectCovered(jcasRangeAnnotation.classsentenceB));
 			if(!rangeInB.isEmpty()) feats.add(new Feature("arg2_has_nearby_""RangeAnnotation"));
 			fracInB.addAll(JCasUtil.selectCovered(jcasFractionAnnotation.classsentenceB));
 			if(!fracInB.isEmpty()) feats.add(new Feature("arg2_has_nearby_""FractionAnnotation"));
 			romanInB.addAll(JCasUtil.selectCovered(jcasRomanNumeralAnnotation.classsentenceB));
 			if(!romanInB.isEmpty()) feats.add(new Feature("arg2_has_nearby_""RomanNumeralAnnotation"));
 			measureInB.addAll(JCasUtil.selectCovered(jcasMeasurementAnnotation.classsentenceB));
 			if(!measureInB.isEmpty()) feats.add(new Feature("arg2_has_nearby_""MeasurementAnnotation"));
 		}
 
 		//check if annotation matches
 		if(sentenceA != null && sentenceB != null && sentenceA != sentenceB){
 			range:
 			for(RangeAnnotation rangeArangeInA){
				for(RangeAnnotation rangeBrangeInB){
						feats.add(new Feature("shareCommonRange_"rangeB.getCoveredText().toLowerCase()));
						break range;
					}
				}
			}
		    fraction:
			for(FractionAnnotation fracAfracInA){
				for(FractionAnnotation fracBfracInB){
						feats.add(new Feature("shareCommonFraction_"fracB.getCoveredText().toLowerCase()));
						break fraction;
					}
				}
			}
		    number:
			for(RomanNumeralAnnotation numAromanInA){
				for(RomanNumeralAnnotation numBromanInB){
						feats.add(new Feature("shareCommonFraction_"numB.getCoveredText().toLowerCase()));
						break number;
					}
				}
			}
			measure:
			for(MeasurementAnnotation meaAmeasureInA){
				for(MeasurementAnnotation meaBmeasureInB){
						feats.add(new Feature("shareCommonFraction_"meaB.getCoveredText().toLowerCase()));
						break measure;
					}
				}
			}
		}
		return feats;
	}
	private static Sentence getCoveringSentence(EventMention event,
			Map<EventMentionCollection<Sentence>> coveringMap) {
		List<SentencesentList = new ArrayList<>();
		if(event != null){
			sentList.addAll(coveringMap.get(event));			
			if(!sentList.isEmpty()){
				return(sentList.get(0));
			}
		}
		return null;
	}
New to GrepCode? Check out our FAQ X