Commit 37e6a5b2 authored by Javi Corvi's avatar Javi Corvi
Browse files

new version of relation extraction, dose_sex

parent 7355366e
Pipeline #25732 passed with stage
in 1 minute and 47 seconds
......@@ -189,167 +189,216 @@ public class App {
* @throws InvalidOffsetException
*/
private static void processDocumentandaWithStudyAsFinding(File inputFile, File outputGATEFile, String annotationSet, String annotationSetRelationExtraction) throws ResourceInstantiationException, JsonGenerationException, IOException{
gate.Document doc = Factory.newDocument(inputFile.toURI().toURL(), "UTF-8");
AnnotationSet as = doc.getAnnotations(annotationSet);
System.out.println("**********************************************rule_finding_init************************************************************");
RelationSet relSet = as.getRelations();
List<Annotation> findings_to_process = getFindings(as);
//for (Annotation finding : findings.inDocumentOrder()){
Integer finding_id = 1;
for (Annotation finding : findings_to_process){
String str_finding = gate.Utils.stringFor(doc, finding);
AnnotationSet sentences = as.get("Sentence", finding.getStartNode().getOffset(), finding.getEndNode().getOffset());
System.out.println("FINDING: " + str_finding);
for (Annotation sentence : sentences){
String str_sentence = gate.Utils.stringFor(doc, sentence);
System.out.println("Sentencia:");
System.out.println(str_sentence);
finding.getFeatures().put("ANNOTATION_TYPE",finding.getType());
finding.getFeatures().put(template_value_name, getSendCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_code_name, getOnlySendCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_codelist_name, getOnlySENDCodeList(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_domain_code_name, getOnlySendDomainCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
doc.getAnnotations(annotationSetRelationExtraction).add(finding.getStartNode(), finding.getEndNode(), "FINDING_"+finding_id, finding.getFeatures());
AnnotationSet sentenceFields = as.get(sentence.getStartNode().getOffset(), sentence.getEndNode().getOffset());
sentence.getFeatures().put("ANNOTATION_TYPE", "RELEVANT_TEXT");
doc.getAnnotations(annotationSetRelationExtraction).add(sentence.getStartNode(), sentence.getEndNode(), "FINDING_"+finding_id, sentence.getFeatures());
//verify if is treatment related or not
Annotation ann = isTreatmentRelatedFinding(doc, finding, sentenceFields);
if(ann!=null) {
System.out.println("TREATMENT_RELATED: " + gate.Utils.stringFor(doc, ann));
ann.getFeatures().put("ANNOTATION_TYPE", "IS_TREATMENT_RELATED");
doc.getAnnotations(annotationSetRelationExtraction).add(ann.getStartNode(), ann.getEndNode(), "FINDING_"+finding_id, ann.getFeatures());
}else {
FeatureMap features_uncertain = Factory.newFeatureMap();
features_uncertain.put(template_value_name, "Y");//TODO Podría poner por defecto que es Y
features_uncertain.put("ANNOTATION_TYPE", "IS_TREATMENT_RELATED");
doc.getAnnotations(annotationSetRelationExtraction).add(sentence.getStartNode(), sentence.getEndNode(), "FINDING_"+finding_id, features_uncertain);
}
if(finding.getType().equals("FINDING")) {
//TODO REVISAR SI ES NECESARIO UN MANIFESTATION OF FINDING
Annotation manifestation_finding = getClosestAnnotation(doc, sentenceFields, finding, "MANIFESTATION_FINDING", 10, 5, ";" );
if(manifestation_finding!=null) {
System.out.println("MANIFESTATION OF FINDING: " + gate.Utils.stringFor(doc, manifestation_finding));
manifestation_finding.getFeatures().put(template_value_name, getSendCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put(send_code_name, getOnlySENDCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put("ANNOTATION_TYPE",manifestation_finding.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(manifestation_finding.getStartNode(), manifestation_finding.getEndNode(), "FINDING_"+finding_id, manifestation_finding.getFeatures());
try {
gate.Document doc = Factory.newDocument(inputFile.toURI().toURL(), "UTF-8");
AnnotationSet as = doc.getAnnotations(annotationSet);
System.out.println("**********************************************rule_finding_init************************************************************");
RelationSet relSet = as.getRelations();
List<Annotation> findings_to_process = getFindings(as);
//for (Annotation finding : findings.inDocumentOrder()){
Integer finding_id = 1;
for (Annotation finding : findings_to_process){
String str_finding = gate.Utils.stringFor(doc, finding);
AnnotationSet sentences = as.get("Sentence", finding.getStartNode().getOffset(), finding.getEndNode().getOffset());
System.out.println("FINDING: " + str_finding);
for (Annotation sentence : sentences){
String str_sentence = gate.Utils.stringFor(doc, sentence);
System.out.println("Sentencia:");
System.out.println(str_sentence);
finding.getFeatures().put("ANNOTATION_TYPE",finding.getType());
finding.getFeatures().put(template_value_name, getSendCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_code_name, getOnlySendCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_codelist_name, getOnlySENDCodeList(finding, gate.Utils.stringFor(doc, finding)));
finding.getFeatures().put(send_domain_code_name, getOnlySendDomainCodeFinding(finding, gate.Utils.stringFor(doc, finding)));
doc.getAnnotations(annotationSetRelationExtraction).add(finding.getStartNode(), finding.getEndNode(), "FINDING_"+finding_id, finding.getFeatures());
AnnotationSet sentenceFields = as.get(sentence.getStartNode().getOffset(), sentence.getEndNode().getOffset());
sentence.getFeatures().put("ANNOTATION_TYPE", "RELEVANT_TEXT");
doc.getAnnotations(annotationSetRelationExtraction).add(sentence.getStartNode(), sentence.getEndNode(), "FINDING_"+finding_id, sentence.getFeatures());
//verify if is treatment related or not
Annotation ann = isTreatmentRelatedFinding(doc, finding, sentenceFields);
if(ann!=null) {
System.out.println("TREATMENT_RELATED: " + gate.Utils.stringFor(doc, ann));
ann.getFeatures().put("ANNOTATION_TYPE", "IS_TREATMENT_RELATED");
doc.getAnnotations(annotationSetRelationExtraction).add(ann.getStartNode(), ann.getEndNode(), "FINDING_"+finding_id, ann.getFeatures());
}else {
FeatureMap features_uncertain = Factory.newFeatureMap();
features_uncertain.put(template_value_name, "Y");
features_uncertain.put("ANNOTATION_TYPE", "IS_TREATMENT_RELATED");
doc.getAnnotations(annotationSetRelationExtraction).add(sentence.getStartNode(), sentence.getEndNode(), "FINDING_"+finding_id, features_uncertain);
}
}else if (finding.getType().equals("STUDY_TESTCD")){
Annotation manifestation_finding = getManifestationOfFindingAnnotation(doc, sentenceFields, finding, ";" );
if(manifestation_finding!=null) {
System.out.println("MANIFESTATION OF FINDING: " + gate.Utils.stringFor(doc, manifestation_finding));
manifestation_finding.getFeatures().put(template_value_name, getSendCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put(send_code_name, getOnlySENDCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put("ANNOTATION_TYPE",manifestation_finding.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(manifestation_finding.getStartNode(), manifestation_finding.getEndNode(), "FINDING_"+finding_id, manifestation_finding.getFeatures());
if(finding.getType().equals("FINDING")) {
//TODO REVISAR SI ES NECESARIO UN MANIFESTATION OF FINDING
Annotation manifestation_finding = getClosestAnnotation(doc, sentenceFields, finding, "MANIFESTATION_FINDING", 10, 5, ";" );
if(manifestation_finding!=null) {
System.out.println("MANIFESTATION OF FINDING: " + gate.Utils.stringFor(doc, manifestation_finding));
manifestation_finding.getFeatures().put(template_value_name, getSendCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put(send_code_name, getOnlySENDCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put("ANNOTATION_TYPE",manifestation_finding.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(manifestation_finding.getStartNode(), manifestation_finding.getEndNode(), "FINDING_"+finding_id, manifestation_finding.getFeatures());
}
}else if (finding.getType().equals("STUDY_TESTCD")){
Annotation manifestation_finding = getManifestationOfFindingAnnotation(doc, sentenceFields, finding, ";" );
if(manifestation_finding!=null) {
System.out.println("MANIFESTATION OF FINDING: " + gate.Utils.stringFor(doc, manifestation_finding));
manifestation_finding.getFeatures().put(template_value_name, getSendCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put(send_code_name, getOnlySENDCode(manifestation_finding, gate.Utils.stringFor(doc, manifestation_finding)));
manifestation_finding.getFeatures().put("ANNOTATION_TYPE",manifestation_finding.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(manifestation_finding.getStartNode(), manifestation_finding.getEndNode(), "FINDING_"+finding_id, manifestation_finding.getFeatures());
}
}
}
Annotation DOSE = getClosestAnnotation(doc, sentenceFields, finding, "DOSE", right_limit, left_limit, null);
if(DOSE!=null) {
System.out.println("DOSE: " + gate.Utils.stringFor(doc, DOSE));
DOSE.getFeatures().put("ANNOTATION_TYPE",DOSE.getType());
DOSE.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, DOSE));
DOSE.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, DOSE));
doc.getAnnotations(annotationSetRelationExtraction).add(DOSE.getStartNode(), DOSE.getEndNode(), "FINDING_"+finding_id, DOSE.getFeatures());
}
Annotation sex = getClosestAnnotation(doc, sentenceFields, finding, "SEX", right_limit, left_limit, null);
if(sex!=null) {
System.out.println("SEX: " + gate.Utils.stringFor(doc, sex));
String send_code = getSendCode(sex, gate.Utils.stringFor(doc, sex));
sex.getFeatures().put(template_value_name, send_code);
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures());
}
Annotation group = getClosestAnnotation(doc, sentenceFields, finding, "GROUP", right_limit, left_limit, null);
if(group!=null) {
System.out.println("GROUP: " + gate.Utils.stringFor(doc, group));
group.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, group));
group.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, group));
group.getFeatures().put("ANNOTATION_TYPE",group.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(group.getStartNode(), group.getEndNode(), "FINDING_"+finding_id, group.getFeatures());
}
Annotation specimen = getClosestAnnotation(doc, sentenceFields, finding, "SPECIMEN", 15, 15, ";");
if(specimen!=null) {
System.out.println("SPECIMEN: " + gate.Utils.stringFor(doc, specimen));
specimen.getFeatures().put(template_value_name, getSendCode(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put(send_code_name, getOnlySENDCode(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put(send_codelist_name, getOnlySENDCodeList(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put("ANNOTATION_TYPE",specimen.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(specimen.getStartNode(), specimen.getEndNode(), "FINDING_"+finding_id, specimen.getFeatures());
}
Annotation STUDY_DOMAIN = getClosestAnnotation(doc, sentenceFields, finding, "STUDY_DOMAIN", right_limit, left_limit, null);
if(STUDY_DOMAIN!=null) {
System.out.println("STUDY_DOMAIN: " + gate.Utils.stringFor(doc, STUDY_DOMAIN));
STUDY_DOMAIN.getFeatures().put("ANNOTATION_TYPE",STUDY_DOMAIN.getType());
STUDY_DOMAIN.getFeatures().put(template_value_name, getSendCode(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
STUDY_DOMAIN.getFeatures().put(send_code_name, getOnlySENDCode(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
STUDY_DOMAIN.getFeatures().put(send_codelist_name, getOnlySENDCodeList(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
doc.getAnnotations(annotationSetRelationExtraction).add(STUDY_DOMAIN.getStartNode(), STUDY_DOMAIN.getEndNode(), "FINDING_"+finding_id, STUDY_DOMAIN.getFeatures());
}
Annotation risk_level = getClosestAnnotation(doc, sentenceFields, finding, "RISK_LEVEL", right_limit, left_limit, null);
if(risk_level!=null) {
System.out.println("RISK_LEVEL: " + gate.Utils.stringFor(doc, risk_level));
//risk_level.getFeatures().put(template_value_name, getSendCode(risk_level, gate.Utils.stringFor(doc, risk_level)));
risk_level.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, risk_level));
risk_level.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, risk_level));
risk_level.getFeatures().put("ANNOTATION_TYPE",risk_level.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(risk_level.getStartNode(), risk_level.getEndNode(), "FINDING_"+finding_id, risk_level.getFeatures());
}
Annotation group = getClosestAnnotation(doc, sentenceFields, finding, "GROUP", right_limit, left_limit, null);
if(group!=null) {
System.out.println("GROUP: " + gate.Utils.stringFor(doc, group));
group.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, group));
group.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, group));
group.getFeatures().put("ANNOTATION_TYPE",group.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(group.getStartNode(), group.getEndNode(), "FINDING_"+finding_id, group.getFeatures());
}
Annotation specimen = getClosestAnnotation(doc, sentenceFields, finding, "SPECIMEN", 15, 15, ";");
if(specimen!=null) {
System.out.println("SPECIMEN: " + gate.Utils.stringFor(doc, specimen));
specimen.getFeatures().put(template_value_name, getSendCode(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put(send_code_name, getOnlySENDCode(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put(send_codelist_name, getOnlySENDCodeList(specimen, gate.Utils.stringFor(doc, specimen)));
specimen.getFeatures().put("ANNOTATION_TYPE",specimen.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(specimen.getStartNode(), specimen.getEndNode(), "FINDING_"+finding_id, specimen.getFeatures());
}
Annotation STUDY_DOMAIN = getClosestAnnotation(doc, sentenceFields, finding, "STUDY_DOMAIN", right_limit, left_limit, null);
if(STUDY_DOMAIN!=null) {
System.out.println("STUDY_DOMAIN: " + gate.Utils.stringFor(doc, STUDY_DOMAIN));
STUDY_DOMAIN.getFeatures().put("ANNOTATION_TYPE",STUDY_DOMAIN.getType());
STUDY_DOMAIN.getFeatures().put(template_value_name, getSendCode(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
STUDY_DOMAIN.getFeatures().put(send_code_name, getOnlySENDCode(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
STUDY_DOMAIN.getFeatures().put(send_codelist_name, getOnlySENDCodeList(STUDY_DOMAIN, gate.Utils.stringFor(doc, STUDY_DOMAIN)));
doc.getAnnotations(annotationSetRelationExtraction).add(STUDY_DOMAIN.getStartNode(), STUDY_DOMAIN.getEndNode(), "FINDING_"+finding_id, STUDY_DOMAIN.getFeatures());
}
Annotation risk_level = getClosestAnnotation(doc, sentenceFields, finding, "RISK_LEVEL", right_limit, left_limit, null);
if(risk_level!=null) {
System.out.println("RISK_LEVEL: " + gate.Utils.stringFor(doc, risk_level));
//risk_level.getFeatures().put(template_value_name, getSendCode(risk_level, gate.Utils.stringFor(doc, risk_level)));
risk_level.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, risk_level));
risk_level.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, risk_level));
risk_level.getFeatures().put("ANNOTATION_TYPE",risk_level.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(risk_level.getStartNode(), risk_level.getEndNode(), "FINDING_"+finding_id, risk_level.getFeatures());
}
Annotation STUDY_DAY_FINDING = getClosestAnnotation(doc, sentenceFields, finding, "STUDY_DAY_FINDING", right_limit, left_limit, null);
if(STUDY_DAY_FINDING!=null) {
System.out.println("STUDY_DAY_FINDING: " + gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
STUDY_DAY_FINDING.getFeatures().put("ANNOTATION_TYPE",STUDY_DAY_FINDING.getType());
STUDY_DAY_FINDING.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
STUDY_DAY_FINDING.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
doc.getAnnotations(annotationSetRelationExtraction).add(STUDY_DAY_FINDING.getStartNode(), STUDY_DAY_FINDING.getEndNode(), "FINDING_"+finding_id, STUDY_DAY_FINDING.getFeatures());
}
// Annotation ROUTE_OF_ADMINISTRATION = getClosestAnnotation(doc, sentenceFields, finding, "ROUTE_OF_ADMINISTRATION", right_limit, left_limit, null);
// if(ROUTE_OF_ADMINISTRATION!=null) {
// System.out.println("ROUTE_OF_ADMINISTRATION: " + gate.Utils.stringFor(doc, ROUTE_OF_ADMINISTRATION));
// ROUTE_OF_ADMINISTRATION.getFeatures().put(template_value_name, getSendCode(ROUTE_OF_ADMINISTRATION, gate.Utils.stringFor(doc, ROUTE_OF_ADMINISTRATION)));
// ROUTE_OF_ADMINISTRATION.getFeatures().put("ANNOTATION_TYPE",ROUTE_OF_ADMINISTRATION.getType());
// doc.getAnnotations(annotationSetRelationExtraction).add(ROUTE_OF_ADgetOnlySendCodeListMINISTRATION.getStartNode(), ROUTE_OF_ADMINISTRATION.getEndNode(), "FINDING_"+finding_id, ROUTE_OF_ADMINISTRATION.getFeatures());
// }
// Annotation MODE_OF_ACTION = getClosestAnnotation(doc, sentenceFields, finding, "MODE_OF_ACTION", right_limit, left_limit, null);
// if(MODE_OF_ACTION!=null) {
// System.out.println("MODE_OF_ACTION: " + gate.Utils.stringFor(doc, MODE_OF_ACTION));
// MODE_OF_ACTION.getFeatures().put("ANNOTATION_TYPE",MODE_OF_ACTION.getType());
// MODE_OF_ACTION.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, MODE_OF_ACTION));
// doc.getAnnotations(annotationSetRelationExtraction).add(MODE_OF_ACTION.getStartNode(), MODE_OF_ACTION.getEndNode(), "FINDING_"+finding_id, MODE_OF_ACTION.getFeatures());
// }
// Annotation CYPS = getClosestAnnotation(doc, sentenceFields, finding, "CYPS", right_limit, left_limit, null);
// if(CYPS!=null) {
// System.out.println("CYPS: " + gate.Utils.stringFor(doc, CYPS));
// CYPS.getFeatures().put("ANNOTATION_TYPE",CYPS.getType());
// CYPS.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, CYPS));
// doc.getAnnotations(annotationSetRelationExtraction).add(CYPS.getStartNode(), CYPS.getEndNode(), "FINDING_"+finding_id, CYPS.getFeatures());
// }
}
finding_id = finding_id + 1;
}
System.out.println("**********************************************rule_finding_end************************************************************");
Annotation STUDY_DAY_FINDING = getClosestAnnotation(doc, sentenceFields, finding, "STUDY_DAY_FINDING", right_limit, left_limit, null);
if(STUDY_DAY_FINDING!=null) {
System.out.println("STUDY_DAY_FINDING: " + gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
STUDY_DAY_FINDING.getFeatures().put("ANNOTATION_TYPE",STUDY_DAY_FINDING.getType());
STUDY_DAY_FINDING.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
STUDY_DAY_FINDING.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, STUDY_DAY_FINDING));
doc.getAnnotations(annotationSetRelationExtraction).add(STUDY_DAY_FINDING.getStartNode(), STUDY_DAY_FINDING.getEndNode(), "FINDING_"+finding_id, STUDY_DAY_FINDING.getFeatures());
}
//if there is already a finding related to a dose_sex then
if(finding.getFeatures().get("DOSE_SEX")!=null || finding.getFeatures().get("DOSE_SEX_MULTI")!=null ) {
if(finding.getFeatures().get("DOSE_SEX_MULTI")!=null && !finding.getFeatures().get("DOSE_SEX_MULTI").toString().equals("")) {
//multi analysis
Annotation dose_sex_multi = as.get(new Integer(finding.getFeatures().get("DOSE_SEX_MULTI").toString()));
AnnotationSet dose_sex_set = as.get("DOSE_SEX", dose_sex_multi.getStartNode().getOffset(), dose_sex_multi.getEndNode().getOffset());
//por cada dosis y sexo relaciono
Boolean first =true;
for (Annotation dose_sex : dose_sex_set) {
Annotation dose = as.get("DOSE", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
Annotation sex = as.get("SEX", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
if(first) {
first = false;
}else {
//Need to make copy of FINDING and increment finding id
int finding_ant = finding_id;
finding_id = finding_id + 1;
//get all atributes from actual finding and replicate annotations
AnnotationSet finding_atributes = doc.getAnnotations(annotationSetRelationExtraction).get("FINDING_"+finding_ant);
for (Annotation annotation : finding_atributes) {
if(!annotation.getFeatures().get("ANNOTATION_TYPE").toString().equals("SEX") && !annotation.getFeatures().get("ANNOTATION_TYPE").toString().equals("DOSE")) {
doc.getAnnotations(annotationSetRelationExtraction).add(annotation.getStartNode(), annotation.getEndNode(), "FINDING_"+finding_id, annotation.getFeatures());
}
}
}
dose.getFeatures().put("ANNOTATION_TYPE",dose.getType());
dose.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose));
dose.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, dose));
doc.getAnnotations(annotationSetRelationExtraction).add(dose.getStartNode(), dose.getEndNode(), "FINDING_"+finding_id, dose.getFeatures());
String send_code = getSendCode(sex, gate.Utils.stringFor(doc, sex));
sex.getFeatures().put(template_value_name, send_code);
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures());
}
}else if (finding.getFeatures().get("DOSE_SEX")!=null && !finding.getFeatures().get("DOSE_SEX").toString().equals("")) {
// dose sex analysis
Annotation dose_sex = as.get(new Integer(finding.getFeatures().get("DOSE_SEX").toString()));
Annotation dose = as.get("DOSE", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
Annotation sex = as.get("SEX", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
dose.getFeatures().put("ANNOTATION_TYPE",dose.getType());
dose.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose));
dose.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, dose));
doc.getAnnotations(annotationSetRelationExtraction).add(dose.getStartNode(), dose.getEndNode(), "FINDING_"+finding_id, dose.getFeatures());
String send_code = getSendCode(sex, gate.Utils.stringFor(doc, sex));
sex.getFeatures().put(template_value_name, send_code);
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures());
}
}else { // if not common analysis with closest annotation.
Annotation DOSE = getClosestAnnotation(doc, sentenceFields, finding, "DOSE", right_limit, left_limit, null);
if(DOSE!=null) {
System.out.println("DOSE: " + gate.Utils.stringFor(doc, DOSE));
DOSE.getFeatures().put("ANNOTATION_TYPE",DOSE.getType());
DOSE.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, DOSE));
DOSE.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, DOSE));
doc.getAnnotations(annotationSetRelationExtraction).add(DOSE.getStartNode(), DOSE.getEndNode(), "FINDING_"+finding_id, DOSE.getFeatures());
}else {
Annotation DOSE_QUALIFICATION = getClosestAnnotation(doc, sentenceFields, finding, "DOSE_QUALIFICATION", right_limit, left_limit, null);
if(DOSE_QUALIFICATION!=null) {
System.out.println("DOSE: " + gate.Utils.stringFor(doc, DOSE_QUALIFICATION));
DOSE_QUALIFICATION.getFeatures().put("ANNOTATION_TYPE","DOSE");
DOSE_QUALIFICATION.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, DOSE_QUALIFICATION));
DOSE_QUALIFICATION.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, DOSE_QUALIFICATION));
doc.getAnnotations(annotationSetRelationExtraction).add(DOSE_QUALIFICATION.getStartNode(), DOSE_QUALIFICATION.getEndNode(), "FINDING_"+finding_id, DOSE_QUALIFICATION.getFeatures());
}
}
Annotation sex = getClosestAnnotation(doc, sentenceFields, finding, "SEX", right_limit, left_limit, null);
if(sex!=null) {
System.out.println("SEX: " + gate.Utils.stringFor(doc, sex));
String send_code = getSendCode(sex, gate.Utils.stringFor(doc, sex));
sex.getFeatures().put(template_value_name, send_code);
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures());
}
}
}
finding_id = finding_id + 1;
}
System.out.println("**********************************************rule_finding_end************************************************************");
java.io.Writer out = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new FileOutputStream(outputGATEFile, false)));
out.write(doc.toXml());
out.close();
}catch(Exception e) {
e.printStackTrace();
}
java.io.Writer out = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new FileOutputStream(outputGATEFile, false)));
out.write(doc.toXml());
out.close();
}
/**
......@@ -579,7 +628,10 @@ public class App {
}else if(annotation.getFeatures().get("ETOX_SEND_DOMAIN_CODE")!=null) {
send_code = annotation.getFeatures().get("ETOX_SEND_DOMAIN_CODE").toString();
}
return send_code+"("+text+")";
if(!send_code.equals("")) {
return text+"("+send_code+")";
}
return text;
}
private static String getSendCodeFinding(Annotation annotation, String text) {
......@@ -592,10 +644,19 @@ public class App {
}else if(annotation.getFeatures().get("ETOX_SEND_CODE")!=null) {
send_code = annotation.getFeatures().get("ETOX_SEND_CODE").toString();
}
return send_code+"("+text+")";
if(!send_code.equals("")) {
return text+"("+send_code+")";
}
return text;
}
/**
* Return only the SEND CODE from the DOMAIN of the finding.
* Example: CL, LB, MA, MI, OM, PP and TF
* @param annotation
* @param text
* @return
*/
private static String getOnlySendDomainCodeFinding(Annotation annotation, String text) {
//String send_code = "UNCERTAIN("+(text)+")";
String send_code = "";
......@@ -608,7 +669,13 @@ public class App {
}
return send_code;
}
/**
* Return only the SEND CODE of the FINDING OR STUDY_TESTCD
* Example: GLUC,INSULIN
* @param annotation
* @param text
* @return
*/
private static String getOnlySendCodeFinding(Annotation annotation, String text) {
//String send_code = "UNCERTAIN("+(text)+")";
String send_code = "";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment