}
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
//get discharge Time id: T1:
TimeMention admissionTime = null;
//TODO
//may need better way to identify Discharge Time other than relative span information:
for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, 15, 30)) {
if(time.getTimeClass().equals("DATE")){
admissionTime = time;
break;
}
}
if (admissionTime != null){
//get event-time1 relations:
Map<List<Annotation>, TemporalTextRelation> dischargeTimeRelationLookup;
dischargeTimeRelationLookup = new HashMap<>();
if (this.isTraining()) {
dischargeTimeRelationLookup = new HashMap<>();
for (TemporalTextRelation relation : JCasUtil.select(jCas, TemporalTextRelation.class)) {
Annotation arg1 = relation.getArg1().getArgument();
Annotation arg2 = relation.getArg2().getArgument();
// The key is a list of args so we can do bi-directional lookup
if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
if( arg1==admissionTime){
dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
continue;
}
}else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
if( arg2==admissionTime ){
dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
continue;
}
}
}
}
for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
if (eventMention.getEvent() != null) {
List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add nearby verb POS pattern feature
features.addAll(this.sectionIDExtractor.extract(jCas, eventMention)); //add section heading
features.addAll(this.closestVerbExtractor.extract(jCas, eventMention)); //add closest verb
features.addAll(this.timeXExtractor.extract(jCas, eventMention)); //add the closest time expression types
features.addAll(this.genericExtractor.extract(jCas, eventMention)); //add the closest time expression types
features.addAll(this.dateExtractor.extract(jCas, eventMention)); //add the closest NE type
features.addAll(this.umlsExtractor.extract(jCas, eventMention)); //add umls features
// features.addAll(this.durationExtractor.extract(jCas, eventMention)); //add duration feature
// features.addAll(this.disSemExtractor.extract(jCas, eventMention)); //add distributional semantic features
if (this.isTraining()) {
TemporalTextRelation relation = dischargeTimeRelationLookup.get(Arrays.asList(eventMention, admissionTime));
String category = null;
if (relation != null) {
category = relation.getCategory();
} else {
relation = dischargeTimeRelationLookup.get(Arrays.asList(admissionTime, eventMention));
if (relation != null) {
if(relation.getCategory().equals("OVERLAP")){
category = relation.getCategory();
}else if (relation.getCategory().equals("BEFORE")){
category = "AFTER";
}else if (relation.getCategory().equals("AFTER")){
category = "BEFORE";
}
}
}
if(category!=null){
this.dataWriter.write(new Instance<>(category, features));
}
} else {
String outcome = this.classifier.classify(features);
if(outcome!=null){
// add the relation to the CAS
RelationArgument relArg1 = new RelationArgument(jCas);
relArg1.setArgument(eventMention);
relArg1.setRole("Argument");
relArg1.addToIndexes();
RelationArgument relArg2 = new RelationArgument(jCas);
relArg2.setArgument(admissionTime);
relArg2.setRole("Related_to");
relArg2.addToIndexes();
TemporalTextRelation relation = new TemporalTextRelation(jCas);
relation.setArg1(relArg1);
relation.setArg2(relArg2);
relation.setCategory(outcome);
relation.addToIndexes();
}else{
System.out.println("cannot classify "+ eventMention.getCoveredText()+" and " + admissionTime.getCoveredText());
}
}
}
}
}