Commit ec995dc1 authored by jcorvi's avatar jcorvi
Browse files

new formats as results

parent 612008c1
Pipeline #25539 failed with stage
in 1 minute and 58 seconds
package es.bsc.inb.ades.export.json.main;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -168,7 +172,8 @@ public class App {
String fileOutPutName = file.getName();
File outputAbstractFile = new File (outputDirectoryPath + File.separator + fileOutPutName.replace(".xml", "_documents.json"));
File outputAnnotationsFile = new File (outputDirectoryPath + File.separator + fileOutPutName.replace(".xml", "_annotations.json"));
processDocument(file, outputAbstractFile, outputAnnotationsFile, annotationSet, annotationSetRelationExtraction);
File cvsOutputFile = new File (outputDirectoryPath + File.separator + fileOutPutName.replace(".xml", "_FINDINGS.csv"));
processDocument(file, outputAbstractFile, outputAnnotationsFile, cvsOutputFile, annotationSet, annotationSetRelationExtraction);
} catch (ResourceInstantiationException e) {
System.out.println("App::process :: error with document " + file.getAbsolutePath());
e.printStackTrace();
......@@ -199,7 +204,7 @@ public class App {
* @throws JsonGenerationException
* @throws InvalidOffsetException
*/
private static void processDocument(File inputFile, File outputTextFile, File outputAnnotationsFile, String annotationSet, String annotationSetRelationExtraction ) throws ResourceInstantiationException, JsonGenerationException, IOException, InvalidOffsetException{
private static void processDocument(File inputFile, File outputTextFile, File outputAnnotationsFile, File cvsOutputFile,String annotationSet, String annotationSetRelationExtraction ) throws ResourceInstantiationException, JsonGenerationException, IOException, InvalidOffsetException{
gate.Document doc = Factory.newDocument(inputFile.toURI().toURL(), "UTF-8");
Gson gsonBuilder = new GsonBuilder().create();
JsonObject annotated_document = new JsonObject();
......@@ -229,7 +234,7 @@ public class App {
writer1 = null;
annotated_document=null;
exportCVS(annotated_document, cvsOutputFile);
//document text
......@@ -251,6 +256,16 @@ public class App {
}
private static void exportCVS(JsonObject annotated_document, File cvsOutput) {
StringBuffer retStr = new StringBuffer("");
try {
createTxtFile("SR-DOMAIN-RESULT.csv", retStr.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Process the plain annotation of the document
* @param annotationSet
......@@ -390,43 +405,6 @@ public class App {
findingElementObject.add("features", features);
findingObject.add(key, findingElementObject);
// List<SRDomainFinding> srDomainFindings = generateSRDomainData(annotations_findings_by_type);
// JsonArray srDomainFinding_Json = new JsonArray();
//
// for (SRDomainFinding srDomainFinding : srDomainFindings) {
// JsonObject srDomainFindingJSON = new JsonObject();
// srDomainFindingJSON.addProperty("STUDYID", srDomainFinding.getSTUDYID());
// srDomainFindingJSON.addProperty("DOMAIN", srDomainFinding.getDOMAIN());
// srDomainFindingJSON.addProperty("SRSEQ", i+"");
// srDomainFindingJSON.addProperty("SRRISK", srDomainFinding.getSRRISK());
// srDomainFindingJSON.addProperty("SPGRPCD", srDomainFinding.getSPGRPCD());
// srDomainFindingJSON.addProperty("GRPLBL", srDomainFinding.getGRPLBL());
// srDomainFindingJSON.addProperty("SRGRPDOS", srDomainFinding.getSRGRPDOS());
// srDomainFindingJSON.addProperty("SRSEX", srDomainFinding.getSRSEX());
// srDomainFindingJSON.addProperty("SRSTDY", srDomainFinding.getSRSTDY());
// srDomainFindingJSON.addProperty("SRSTPHSE", srDomainFinding.getSRSTPHSE());
// srDomainFindingJSON.addProperty("SROBSTDY", srDomainFinding.getSROBSTDY());
// srDomainFindingJSON.addProperty("SRENDY", srDomainFinding.getSRENDY());
// srDomainFindingJSON.addProperty("SRENPHSE", srDomainFinding.getSRENPHSE());
// srDomainFindingJSON.addProperty("SROBENDY", srDomainFinding.getSROBENDY());
// srDomainFindingJSON.addProperty("SRDOMAIN", srDomainFinding.getSRDOMAIN());
// srDomainFindingJSON.addProperty("SRSPEC", srDomainFinding.getSRSPEC());
// srDomainFindingJSON.addProperty("SRTSTCD", srDomainFinding.getSRTSTCD());
// srDomainFindingJSON.addProperty("SRFNDG", srDomainFinding.getSRFNDG());
// srDomainFindingJSON.addProperty("SRORES", srDomainFinding.getSRORES());
// srDomainFindingJSON.addProperty("SROBSV", srDomainFinding.getSROBSV());
// srDomainFindingJSON.addProperty("SROBSQ", srDomainFinding.getSROBSQ());
// srDomainFindingJSON.addProperty("SRSEV", srDomainFinding.getSRSEV());
// srDomainFindingJSON.addProperty("SRPCNT", srDomainFinding.getSRPCNT());
// srDomainFindingJSON.addProperty("SRSIGF", srDomainFinding.getSRSIGF());
// srDomainFindingJSON.addProperty("SRTRTEF", srDomainFinding.getSRTRTEF());
// srDomainFindingJSON.addProperty("SRCOMNT", srDomainFinding.getSRCOMNT());
// srDomainFindingJSON.addProperty("srDomainId", i);
// srDomainFindingJSON.addProperty("findingId", id_finding);
// srDomainFinding_Json.add(srDomainFindingJSON);
// i=i+1;
// }
// findingObject.add("srDomainFindings", srDomainFinding_Json);
}
List<SRDomainFinding> srDomainFindings = generateSRDomainData(annotations_findings_by_type);
......@@ -728,6 +706,22 @@ public class App {
return mainList;
}
/**
* Create a plain text file with the given string
* @param path
* @param plainText
* @throws FileNotFoundException
* @throws IOException
*/
private static void createTxtFile(String path, String plainText) throws FileNotFoundException, IOException {
File fout = new File(path);
FileOutputStream fos = new FileOutputStream(fout);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos,StandardCharsets.UTF_8));
bw.write(plainText);
bw.flush();
bw.close();
}
/**
* Return a set of files
* @param dir
......
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