Commit fef9e358 authored by Javi Corvi's avatar Javi Corvi
Browse files

new version ready for presentation

parent fe30117a
Pipeline #25793 passed with stage
in 4 minutes and 15 seconds
......@@ -94,15 +94,22 @@ public class DocumentController {
return snippet;
}
@RequestMapping("/documents/{id}/evidence/findings")
public String findAllFindingEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/all")
public String findAllEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/sentences")
public String findSentencesEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findSentencesEvidenceByDocumentId(id);
//String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
......
package es.bsc.inb.ades.rest.api.model;
import org.apache.tomcat.util.bcel.classfile.Constant;
import es.bsc.inb.ades.rest.api.util.Constants;
/**
* This class describes a finding in SR-Domain format.
* No textual evidence.
......@@ -57,7 +61,14 @@ public class SRDomainFinding implements Cloneable{
}
public String getSrdomain_value() {
return SRDOMAIN_DESC + "(" + SRDOMAIN + ")";
if(Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN)!=null) {
return Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN) + "(" + SRDOMAIN + ")";
}else if(SRDOMAIN==null || SRDOMAIN.equals("")) {
return "";
}else {
return SRDOMAIN;
}
}
public String getSrfndg_value() {
......
......@@ -30,6 +30,8 @@ public interface DocumentService {
String findFindingsEvidenceByDocumentId(Long id);
String findAllEvidenceByDocumentId(Long id);
String findSentencesEvidenceByDocumentId(Long id);
String findTextByDocumentId(Long id);
......
......@@ -215,10 +215,20 @@ public class DocumentServiceImpl implements DocumentService {
* Get Findings evidence from a document
*/
public String findFindingsEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllFindingsEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get Findings evidence from a document
*/
public String findAllEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get relevant sentences evidence from a document
*/
......@@ -636,6 +646,98 @@ public class DocumentServiceImpl implements DocumentService {
int a = 1;
int r = 1;
for (Annotation sentenceAnnotation : sentences) {
JsonArray values_sentence = new JsonArray();
//values_sentence.add("T"+t);
values_sentence.add("S"+sentenceAnnotation.getId());
values_sentence.add("RELEVANT_SENTENCE");
JsonArray offste_sentence = new JsonArray();
JsonArray offste2_sentence = new JsonArray();
offste_sentence.add(sentenceAnnotation.getStartOffset());
offste_sentence.add(sentenceAnnotation.getEndOffset());
offste2_sentence.add(offste_sentence);
values_sentence.add(offste2_sentence);
entities.add(values_sentence);
t++;
if(sentenceAnnotation.getFindings()!=null) {
for (Finding findingSelected : sentenceAnnotation.getFindings()) {
List<Annotation> all = findingSelected.generateSortedAnnotationsAll();
String id_finding = "";
for (Annotation annotation : all) {
JsonArray values = new JsonArray();
String type = annotation.getFeature("ANNOTATION_TYPE");
//String id = "T"+t;
String id = "E"+annotation.getId();
//TODO source
// String source = annotation.getFeature("SOURCES");
// if(source!=null && !source.equals("")) {
// id = id + " - SOURCE: " + source;
// }
// values.add("T"+t+ " - SOURCE: " + source);
values.add(id);
values.add(type);
JsonArray offste = new JsonArray();
JsonArray offste2 = new JsonArray();
offste.add(annotation.getStartOffset());
offste.add(annotation.getEndOffset());
offste2.add(offste);
values.add(offste2);
entities.add(values);
if(type.equals("FINDING") || type.equals("STUDY_TESTCD") ) {
id_finding = "T"+t;
JsonArray values_a = new JsonArray();
values_a.add("A"+a);
values_a.add("Notorious");
values_a.add(id_finding);
attributes.add(values_a);
a++;
}else {
JsonArray values_r = new JsonArray();
values_r.add("R"+r);
values_r.add("Relation");
JsonArray values_r_e = new JsonArray();
JsonArray values_r_e_v = new JsonArray();
values_r_e_v.add("Entity");
values_r_e_v.add(id_finding);
values_r_e.add(values_r_e_v);
JsonArray values_r_e_v_2 = new JsonArray();
values_r_e_v_2.add("Subentity");
values_r_e_v_2.add("T"+t);
values_r_e.add(values_r_e_v_2);
values_r.add(values_r_e);
relations.add(values_r);
r++;
}
t++;
}
}
}
}
findings_evidence.add("entities", entities);
findings_evidence.add("attributes", attributes);
findings_evidence.add("relations", relations);
return gsonBuilder.toJson(findings_evidence).toString();
}
/**
* Generate the evidence of view all button.
* @param text
* @param findingSelected
* @return
*/
private String generateAllFindingsEvidenceSnippet(String text, List<Annotation> sentences) {
Gson gsonBuilder = new GsonBuilder().create();
JsonObject findings_evidence = new JsonObject();
findings_evidence.addProperty("text", text);
JsonArray entities = new JsonArray();
JsonArray attributes = new JsonArray();
JsonArray relations = new JsonArray();
int t = 1;
int a = 1;
int r = 1;
for (Annotation sentenceAnnotation : sentences) {
// JsonArray values_sentence = new JsonArray();
// values_sentence.add("T"+t);
// values_sentence.add("PRETOX_RELEVANT_SENTENCE");
......
package es.bsc.inb.ades.rest.api.util;
import java.util.HashMap;
import java.util.Map;
public class Constants {
public static int SLICE_START = 1000;
......@@ -7,4 +10,26 @@ public class Constants {
public static int POINTS_INT = 5;
public static String POINTS = ".....";
public static Map<String, String> SEND_DOMAIN_NAMES = new HashMap<String, String>(){{
put("LB", "Laboratory Test Results");
put("BW", "Body Weight");
put("BG", "Body Weight Gain");
put("CV", "Cardiovascular Domain");
put("CL", "Clinical");
put("DD", "Death Diagnosis");
put("EG", "ECG Test Results");
put("FM", "Fetal Measurements");
put("FW", "Food And Water");
put("FX", "Fetal Pathology Findings");
put("MA", "Macroscopic Findings");
put("MI", "Microscopic Findings");
put("OM", "Organ Measurements");
put("RE", "Respiratory Findings");
put("TF", "Tumor Findings");
put("VS", "Vital Signs");
}};
}
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