Search in sources :

Example 1 with LinkedDataObject

use of com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject 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 LinkedDataObject

use of com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject 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)

Example 3 with LinkedDataObject

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

the class JSONLDJavaUtil method getRootLinkedDataObject.

/**
 * Returns a {@link LinkedDataObject} corresponding to the root objects of a JSONLD-JAVA object.
 * @param jsonldJavaObject
 * @return
 */
public static LinkedDataObject getRootLinkedDataObject(Object jsonldJavaObject) {
    Object flattenedExpanded = getFlattenedExpandedJSONLDJavaObject(jsonldJavaObject);
    Object root = getRoot(flattenedExpanded);
    Map<String, Object> objectIndex = makeObjectIndex(flattenedExpanded);
    Util.println("Object index:\n" + Util.join("\n", objectIndex.entrySet()));
    LinkedDataObject result = make(root, objectIndex::get);
    return result;
}
Also used : LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject)

Example 4 with LinkedDataObject

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

the class JSONLDJavaUtil method getObjectFromMap.

@SuppressWarnings("unchecked")
private static LinkedDataObject getObjectFromMap(Object jsonldJavaObject, Function<String, Object> objectIndex) {
    LinkedDataObject result;
    Object jsonldJavaObjectToUse = determineJSONLDObjectToUse(jsonldJavaObject, objectIndex);
    result = new JSONLDMap((Map<String, Object>) jsonldJavaObjectToUse, objectIndex);
    return result;
}
Also used : LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with LinkedDataObject

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

the class JSONLDMap method get.

@Override
public LinkedDataObject get(String key) {
    Object value = jsonldjavaMap.get(key);
    LinkedDataObject result = make(value);
    return result;
}
Also used : LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject) LinkedDataObject(com.sri.ai.praise.other.integration.linkeddata.api.LinkedDataObject)

Aggregations

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