uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luca Toldo"<lucato...@gmail.com>
Subject Using REST api with UIMA
Date Thu, 04 May 2017 07:49:49 GMT
The following Java code (inspired from http://stackoverflow.com/questions/40838999/getting-output-in-json-format-in-uima
) 

import java.io.*;
import org.apache.uima.fit.factory.JCasFactory;
import org.apache.uima.jcas.JCas;
import org.apache.uima.cas.CAS;
import org.apache.uima.json.JsonCasSerializer;
public class  test {
        public static void main(String [] args ) throws IOException {
                try {
                        String note="Lorem ipsum incididunt ut labore et dolore magna aliqua";
                        JCas jcas = JCasFactory.createJCas();
                        jcas.setDocumentText(note);
                        JsonCasSerializer jcs = new JsonCasSerializer();
                        jcs.setPrettyPrint(true); 
                        StringWriter sw = new StringWriter();
                        CAS cas = jcas.getCas();
                        jcs.serialize(cas, sw); 
                        System.out.println(sw.toString());
                } catch (Exception ex) {
                }
        }
}


delivers properly formatted JSON CAS:

{"_context" : {
    "_types" : {
      "DocumentAnnotation" : {"_id" : "uima.tcas.DocumentAnnotation", 
        "_feature_types" : {"sofa" : "_ref" } }, 
      "Sofa" : {"_id" : "uima.cas.Sofa", 
        "_feature_types" : {"sofaArray" : "_ref" } }, 
      "Annotation" : {"_id" : "uima.tcas.Annotation", 
        "_feature_types" : {"sofa" : "_ref" }, 
        "_subtypes" : ["DocumentAnnotation" ] }, 
      "AnnotationBase" : {"_id" : "uima.cas.AnnotationBase", 
        "_feature_types" : {"sofa" : "_ref" }, 
        "_subtypes" : ["Annotation" ] }, 
      "TOP" : {"_id" : "uima.cas.TOP", 
        "_subtypes" : ["AnnotationBase",  "Sofa" ] } } }, 
  "_views" : {
    "_InitialView" : {
      "DocumentAnnotation" : [
        {"sofa" : 1,  "begin" : 0,  "end" : 55,  "language" : "x-unspecified" } ] } }, 
  "_referenced_fss" : {
    "1" : {"_type" : "Sofa",  "sofaNum" : 1,  "sofaID" : "_InitialView",  "mimeType" : "text",
 "sofaString" : "Lorem ipsum incididunt ut labore et dolore magna aliqua" } } }

How to deserialize that back into CAS object ?

Mime
View raw message