package main;
/***************************************************************************
Clinical Named Entity Recognizer and Normalizer(Clinical NERC), (v0.1).
Copyright (C) 2013 Azad Dehghan
Contact: a.dehghan@manchester.ac.uk
*****************************************************************************/
import gate.Annotation;
import gate.Factory;
import gate.FeatureMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* class to extract temporal expressions from TEid-pipline annotated text;
* Format:
* <StartOffsets>\\t<EndOffset>||text=<identifiedEvent>||type=<EventClass>
* conceptId=<...>||semType=<...>||conceptName=<...>
*/
public class Event {
/**
* extracts Events as annotated by MLPipeline
* @param gateDoc
* @return formatted temporal identifier output (see class description)
*/
public static String getEvents(gate.Document gateDoc)
{
String result = "";
List<Annotation> as_problem = new ArrayList<Annotation>( gateDoc.getAnnotations().get("problem") );
Collections.sort(as_problem, gate.Utils.OFFSET_COMPARATOR);
for(Annotation s: as_problem)
{
String str = gate.Utils.stringFor(gateDoc, s);
result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=problem" + "\n";
//get attributes get them,
FeatureMap tAttributes = s.getFeatures();
if(!tAttributes.isEmpty())
result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";
}
List<Annotation> as_treatment = new ArrayList<Annotation>( gateDoc.getAnnotations().get("treatment") );
Collections.sort(as_treatment, gate.Utils.OFFSET_COMPARATOR);
for(Annotation s: as_treatment)
{
String str = gate.Utils.stringFor(gateDoc, s);
result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=treatment" + "\n";
//get attributes get them,
FeatureMap tAttributes = s.getFeatures();
if(!tAttributes.isEmpty())
result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";
}
List<Annotation> as_test = new ArrayList<Annotation>( gateDoc.getAnnotations().get("test") );
Collections.sort(as_test, gate.Utils.OFFSET_COMPARATOR);
for(Annotation s: as_test)
{
String str = gate.Utils.stringFor(gateDoc, s);
result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=test" + "\n";
//get attributes get them,
FeatureMap tAttributes = s.getFeatures();
if(!tAttributes.isEmpty())
result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";
}
Factory.deleteResource(gateDoc); //N.B.!!
return result;
}
}