@Override
public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
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 = (EventMention) arg1;
time = (TimeMention) arg2;
}else{
time = (TimeMention) arg1;
event = (EventMention) arg2;
}
//1 get covering sentence:
Map<EventMention, Collection<Sentence>> eventCoveringMap =
JCasUtil.indexCovering(jCas, EventMention.class, Sentence.class);
Collection<Sentence> eventSentList = eventCoveringMap.get(event);
Map<TimeMention, Collection<Sentence>> timeCoveringMap =
JCasUtil.indexCovering(jCas, TimeMention.class, Sentence.class);
Collection<Sentence> timeSentList = timeCoveringMap.get(time);
//2 get TimeX
Map<Integer, TimeMention> timeDistMap = null;
Map<Integer, EventMention> eventDistMap = null;
if (eventSentList != null && !eventSentList.isEmpty()){
timeDistMap = new TreeMap<Integer, TimeMention>();
for(Sentence sent : eventSentList) {
for (TimeMention atime : JCasUtil.selectCovered(jCas, TimeMention.class, sent)) {
timeDistMap.put(Math.abs(atime.getBegin() - event.getBegin()), atime);
}
}
//get the closest Time Expression feature
for (Map.Entry<Integer, TimeMention> entry : timeDistMap.entrySet()) {