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,6 +189,7 @@ public class App {
* @throws InvalidOffsetException
*/
private static void processDocumentandaWithStudyAsFinding(File inputFile, File outputGATEFile, String annotationSet, String annotationSetRelationExtraction) throws ResourceInstantiationException, JsonGenerationException, IOException{
try {
gate.Document doc = Factory.newDocument(inputFile.toURI().toURL(), "UTF-8");
AnnotationSet as = doc.getAnnotations(annotationSet);
System.out.println("**********************************************rule_finding_init************************************************************");
......@@ -222,7 +223,7 @@ public class App {
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(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);
}
......@@ -248,24 +249,7 @@ public class App {
}
}
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) {
......@@ -317,31 +301,92 @@ public class App {
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());
// }
//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());
}
// 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());
// }
}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;
}
......@@ -350,6 +395,10 @@ public class App {
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();
}
}
/**
......@@ -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