Commit 0f685197 authored by jcorvi's avatar jcorvi
Browse files

Merge branch 'develop' into 'master'

new version of relation extraction for finding - specimen

See merge request !9
parents 6385a6d7 19291df8
Pipeline #28633 failed with stage
in 28 seconds
...@@ -203,7 +203,7 @@ public class AnnotationUtil { ...@@ -203,7 +203,7 @@ public class AnnotationUtil {
token_between_closest = token_between.size(); token_between_closest = token_between.size();
} }
}else { }else {
System.out.println("testear"); //System.out.println("testear");
} }
} }
return closest; return closest;
...@@ -242,6 +242,7 @@ public class AnnotationUtil { ...@@ -242,6 +242,7 @@ public class AnnotationUtil {
if(!doc.getName().equals(aux_docName)) { if(!doc.getName().equals(aux_docName)) {
finding_id = 1; finding_id = 1;
aux_docName = doc.getName(); aux_docName = doc.getName();
System.out.println("processFindingRelation :: document : " + aux_docName);
} }
finding.getFeatures().put("ANNOTATION_TYPE",finding.getType()); finding.getFeatures().put("ANNOTATION_TYPE",finding.getType());
...@@ -296,16 +297,47 @@ public class AnnotationUtil { ...@@ -296,16 +297,47 @@ public class AnnotationUtil {
group.getFeatures().put("ANNOTATION_TYPE",group.getType()); group.getFeatures().put("ANNOTATION_TYPE",group.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(group.getStartNode(), group.getEndNode(), "FINDING_"+finding_id, group.getFeatures()); doc.getAnnotations(annotationSetRelationExtraction).add(group.getStartNode(), group.getEndNode(), "FINDING_"+finding_id, group.getFeatures());
} }
List<Integer> findings_id_copy = new ArrayList<>();
findings_id_copy.add(finding_id);
if (finding.getFeatures().get("SPECIMEN")!=null && !finding.getFeatures().get("SPECIMEN").toString().equals("")) { if (finding.getFeatures().get("SPECIMEN")!=null && !finding.getFeatures().get("SPECIMEN").toString().equals("")) {
Annotation specimen = as.get(new Integer(finding.getFeatures().get("SPECIMEN").toString())); //Specimen relation process
specimen.getFeatures().put(template_value_name, getSendCode(specimen, gate.Utils.stringFor(doc, specimen))); String specimens = finding.getFeatures().get("SPECIMEN").toString();
specimen.getFeatures().put(send_code_name, getOnlySENDCode(specimen, gate.Utils.stringFor(doc, specimen))); String[] specimens_splited = specimens.split(",");
specimen.getFeatures().put(send_codelist_name, getOnlySENDCodeList(specimen, gate.Utils.stringFor(doc, specimen))); Boolean first = true;
specimen.getFeatures().put("ANNOTATION_TYPE",specimen.getType()); for (String spe_id : specimens_splited) {
doc.getAnnotations(annotationSetRelationExtraction).add(specimen.getStartNode(), specimen.getEndNode(), "FINDING_"+finding_id, specimen.getFeatures()); if(!first) {
//if is not the first. Only enter when there is more than one specimen.
//Need to make copy of FINDING and increment finding id
//get all atributes from actual finding and replicate annotations
Integer finding_ant_id = finding_id;
finding_id = finding_id + 1;
AnnotationSet finding_atributes = doc.getAnnotations(annotationSetRelationExtraction).get("FINDING_"+finding_ant_id);
for (Annotation annotation : finding_atributes) {
if(!annotation.getFeatures().get("ANNOTATION_TYPE").toString().equals("SPECIMEN")) {
doc.getAnnotations(annotationSetRelationExtraction).add(annotation.getStartNode(), annotation.getEndNode(), "FINDING_"+finding_id, annotation.getFeatures());
}
}
findings_id_copy.add(finding_id);
}else {
first = false;
}
//add specimen to finding
Annotation specimen = as.get(new Integer(spe_id));
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); // Annotation STUDY_DOMAIN = getClosestAnnotation(doc, sentenceFields, finding, "STUDY_DOMAIN", right_limit, left_limit, null);
// if(STUDY_DOMAIN!=null) { // if(STUDY_DOMAIN!=null) {
...@@ -341,82 +373,87 @@ public class AnnotationUtil { ...@@ -341,82 +373,87 @@ public class AnnotationUtil {
// } // }
//if there is already a finding related to a dose_sex then //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 ) { for (Integer finding_id_to_process : findings_id_copy) {
if(finding.getFeatures().get("DOSE_SEX_MULTI")!=null && !finding.getFeatures().get("DOSE_SEX_MULTI").toString().equals("")) { //iterate over each finding in collection
//multi analysis if(finding.getFeatures().get("DOSE_SEX")!=null || finding.getFeatures().get("DOSE_SEX_MULTI")!=null ) {
Annotation dose_sex_multi = as.get(new Integer(finding.getFeatures().get("DOSE_SEX_MULTI").toString())); if(finding.getFeatures().get("DOSE_SEX_MULTI")!=null && !finding.getFeatures().get("DOSE_SEX_MULTI").toString().equals("")) {
AnnotationSet dose_sex_set = as.get("DOSE_SEX", dose_sex_multi.getStartNode().getOffset(), dose_sex_multi.getEndNode().getOffset()); //multi analysis
//por cada dosis y sexo relaciono Annotation dose_sex_multi = as.get(new Integer(finding.getFeatures().get("DOSE_SEX_MULTI").toString()));
Boolean first =true; AnnotationSet dose_sex_set = as.get("DOSE_SEX", dose_sex_multi.getStartNode().getOffset(), dose_sex_multi.getEndNode().getOffset());
for (Annotation dose_sex : dose_sex_set) { //por cada dosis y sexo relaciono
Annotation dose = as.get("DOSE", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next(); Boolean first =true;
Annotation sex = as.get("SEX", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next(); for (Annotation dose_sex : dose_sex_set) {
if(first) { Annotation dose = as.get("DOSE", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
first = false; Annotation sex = as.get("SEX", dose_sex.getStartNode().getOffset(), dose_sex.getEndNode().getOffset()).iterator().next();
}else { if(!first) {
//Need to make copy of FINDING and increment finding id //Need to make copy of FINDING and increment finding id
int finding_ant = finding_id; int finding_ant = finding_id_to_process;
finding_id = finding_id + 1; finding_id = finding_id + 1;
//get all atributes from actual finding and replicate annotations //get all atributes from actual finding and replicate annotations
AnnotationSet finding_atributes = doc.getAnnotations(annotationSetRelationExtraction).get("FINDING_"+finding_ant); AnnotationSet finding_atributes = doc.getAnnotations(annotationSetRelationExtraction).get("FINDING_"+finding_ant);
for (Annotation annotation : finding_atributes) { for (Annotation annotation : finding_atributes) {
if(!annotation.getFeatures().get("ANNOTATION_TYPE").toString().equals("SEX") && !annotation.getFeatures().get("ANNOTATION_TYPE").toString().equals("DOSE")) { 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()); doc.getAnnotations(annotationSetRelationExtraction).add(annotation.getStartNode(), annotation.getEndNode(), "FINDING_"+finding_id, annotation.getFeatures());
}
} }
finding_id_to_process = finding_id;
}else {
first = false;
} }
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_to_process, 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_to_process, 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("ANNOTATION_TYPE",dose.getType());
dose.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose)); dose.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose));
dose.getFeatures().put(send_code_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()); doc.getAnnotations(annotationSetRelationExtraction).add(dose.getStartNode(), dose.getEndNode(), "FINDING_"+finding_id_to_process, dose.getFeatures());
String send_code = getSendCode(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(template_value_name, send_code);
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex))); sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType()); sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures()); doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id_to_process, 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)); }else {
sex.getFeatures().put(template_value_name, send_code); if (finding.getFeatures().get("DOSE")!=null && !finding.getFeatures().get("DOSE").toString().equals("")) {
sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex))); Annotation dose = as.get(new Integer(finding.getFeatures().get("DOSE").toString()));
sex.getFeatures().put("ANNOTATION_TYPE",sex.getType()); dose.getFeatures().put("ANNOTATION_TYPE",dose.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id, sex.getFeatures()); 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_to_process, dose.getFeatures());
}else if (finding.getFeatures().get("DOSE_QUALIFICATION")!=null && !finding.getFeatures().get("DOSE_QUALIFICATION").toString().equals("")) {
}else { Annotation dose_qualification = as.get(new Integer(finding.getFeatures().get("DOSE_QUALIFICATION").toString()));
if (finding.getFeatures().get("DOSE")!=null && !finding.getFeatures().get("DOSE").toString().equals("")) { dose_qualification.getFeatures().put("ANNOTATION_TYPE","DOSE");
Annotation dose = as.get(new Integer(finding.getFeatures().get("DOSE").toString())); dose_qualification.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose_qualification));
dose.getFeatures().put("ANNOTATION_TYPE",dose.getType()); dose_qualification.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, dose_qualification));
dose.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose)); doc.getAnnotations(annotationSetRelationExtraction).add(dose_qualification.getStartNode(), dose_qualification.getEndNode(), "FINDING_"+finding_id_to_process, dose_qualification.getFeatures());
dose.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, dose)); }
doc.getAnnotations(annotationSetRelationExtraction).add(dose.getStartNode(), dose.getEndNode(), "FINDING_"+finding_id, dose.getFeatures()); if (finding.getFeatures().get("SEX")!=null && !finding.getFeatures().get("SEX").toString().equals("")) {
}else if (finding.getFeatures().get("DOSE_QUALIFICATION")!=null && !finding.getFeatures().get("DOSE_QUALIFICATION").toString().equals("")) { Annotation sex = as.get(new Integer(finding.getFeatures().get("SEX").toString()));
Annotation dose_qualification = as.get(new Integer(finding.getFeatures().get("DOSE_QUALIFICATION").toString())); String send_code = getSendCode(sex, gate.Utils.stringFor(doc, sex));
dose_qualification.getFeatures().put("ANNOTATION_TYPE","DOSE"); sex.getFeatures().put(template_value_name, send_code);
dose_qualification.getFeatures().put(template_value_name, gate.Utils.stringFor(doc, dose_qualification)); sex.getFeatures().put(send_code_name, getOnlySENDCode(sex, gate.Utils.stringFor(doc, sex)));
dose_qualification.getFeatures().put(send_code_name, gate.Utils.stringFor(doc, dose_qualification)); sex.getFeatures().put("ANNOTATION_TYPE",sex.getType());
doc.getAnnotations(annotationSetRelationExtraction).add(dose_qualification.getStartNode(), dose_qualification.getEndNode(), "FINDING_"+finding_id, dose_qualification.getFeatures()); doc.getAnnotations(annotationSetRelationExtraction).add(sex.getStartNode(), sex.getEndNode(), "FINDING_"+finding_id_to_process, sex.getFeatures());
} }
if (finding.getFeatures().get("SEX")!=null && !finding.getFeatures().get("SEX").toString().equals("")) {
Annotation sex = as.get(new Integer(finding.getFeatures().get("SEX").toString()));
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; finding_id = finding_id + 1;
......
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