Search in sources :

Example 1 with LinkedDataMap

use of com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap in project aic-praise by aic-sri-international.

the class ReadWorldModelersJSONLD method main.

public static void main(String[] args) throws Throwable {
    // Open a valid json(-ld) input file
    // InputStream inputStream = new FileInputStream("src/main/resources/test2.jsonld");
    InputStream inputStream = new FileInputStream("src/main/resources/debug_docs_cag-0.2.0.jsonld");
    // InputStream inputStream = new FileInputStream("C:\\Users\\E26638\\Documents\\Research\\World Modelers\\6-month evaluation\\Example CAGs\\BBN\\bbn-m6-cag.v0.1\\bbn-m6-cag.v0.1\\bbn-m6-cag.v0.1\\cag.json-ld");
    // Read the file into an Object (The type of this object will be a List, Map, String, Boolean,
    // Number or null depending on the root object in the file).
    Object jsonObject = JsonUtils.fromInputStream(inputStream);
    // JsonLdOptions options = new JsonLdOptions();
    // Object expanded = JsonLdProcessor.expand(jsonObject, options);
    // Object flattened = JsonLdProcessor.flatten(jsonObject, options);
    println("Flattened:");
    println(JsonUtils.toPrettyString(jsonObject));
    println("Linked data:");
    LinkedDataObject linkedDataRoot = JSONLDJavaUtil.getRootLinkedDataObject(jsonObject);
    println("linkedDataRoot: " + linkedDataRoot);
    LinkedDataObject linkedDataDocuments = ((LinkedDataMap) linkedDataRoot).get("https://github.com/clulab/eidos/wiki/JSON-LD#Documents");
    println("linkedDataDocuments: " + linkedDataDocuments);
// LinkedDataObject linkedDataLube = ((LinkedDataList)linkedDataProducts).get(1);
// println("linkedDataLube: " + linkedDataLube);
// LinkedDataObject linkedDataCompanion = ((LinkedDataMap)linkedDataLube).get("http://ns.example.com/store#companion");
// println("linkedDataCompanion: " + linkedDataCompanion);
}
Also used : LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) LinkedDataMap(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) FileInputStream(java.io.FileInputStream)

Example 2 with LinkedDataMap

use of com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap in project aic-praise by aic-sri-international.

the class ReadJSONLD method main.

public static void main(String[] args) throws Throwable {
    // Open a valid json(-ld) input file
    InputStream inputStream = new FileInputStream("src/main/resources/test.jsonld");
    // InputStream inputStream = new FileInputStream("C:\\Users\\E26638\\Documents\\Research\\World Modelers\\6-month evaluation\\Example CAGs\\BBN\\bbn-m6-cag.v0.1\\bbn-m6-cag.v0.1\\bbn-m6-cag.v0.1\\cag.json-ld");
    // Read the file into an Object (The type of this object will be a List, Map, String, Boolean,
    // Number or null depending on the root object in the file).
    Object jsonObject = JsonUtils.fromInputStream(inputStream);
    // Create a context JSON map containing prefixes and definitions
    Map context = new HashMap();
    // Customise context...
    // Create an instance of JsonLdOptions with the standard JSON-LD options
    JsonLdOptions options = new JsonLdOptions();
    // Customise options...
    // Call whichever JSONLD function you want! (e.g. compact)
    Object flatten = JsonLdProcessor.flatten(jsonObject, context, options);
    // Print out the result (or don't, it's your call!)
    System.out.println(JsonUtils.toPrettyString(flatten));
    Object expanded = JsonLdProcessor.expand(jsonObject, options);
    // // Print out the result (or don't, it's your call!)
    // System.out.println(JsonUtils.toPrettyString(expanded));
    // System.out.println(JsonUtils.toPrettyString(jsonObject));
    // Map root = (Map) jsonObject;
    // println("root: " + root);
    // List products = (List) root.get("product");
    // println("products: " + products);
    // Map lube = (Map) products.get(1);
    // println("lube: " + lube);
    // Object companion = lube.get("companion");
    // println("companion: " + companion);
    // 
    println("\nExpanded");
    Map eroot = (Map) ((List) expanded).get(0);
    println("root: " + eroot);
    List eproducts = (List) eroot.get("http://ns.example.com/store#product");
    println("products: " + eproducts);
    Map elube = (Map) eproducts.get(1);
    println("lube: " + elube);
    Object ecompanion = elube.get("http://ns.example.com/store#companion");
    println("companion: " + ecompanion);
    println("Linked data:");
    LinkedDataObject linkedDataRoot = JSONLDJavaUtil.getRootLinkedDataObject(jsonObject);
    println("linkedDataRoot: " + linkedDataRoot);
    LinkedDataObject linkedDataProducts = ((LinkedDataMap) linkedDataRoot).get("http://ns.example.com/store#product");
    println("linkedDataProducts: " + linkedDataProducts);
    LinkedDataObject linkedDataLube = ((LinkedDataList) linkedDataProducts).get(1);
    println("linkedDataLube: " + linkedDataLube);
    LinkedDataObject linkedDataCompanion = ((LinkedDataMap) linkedDataLube).get("http://ns.example.com/store#companion");
    println("linkedDataCompanion: " + linkedDataCompanion);
}
Also used : LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) JsonLdOptions(com.github.jsonldjava.core.JsonLdOptions) HashMap(java.util.HashMap) LinkedDataMap(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) List(java.util.List) LinkedDataList(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataList) HashMap(java.util.HashMap) Map(java.util.Map) LinkedDataMap(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap) FileInputStream(java.io.FileInputStream) LinkedDataList(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataList)

Aggregations

LinkedDataMap (com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataMap)2 LinkedDataObject (com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 JsonLdOptions (com.github.jsonldjava.core.JsonLdOptions)1 LinkedDataList (com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1