A follow-up to this:
((Map) jsonLdObject).put("@context", ((Map) jsonLdContext).get("@context");
you have to grab the content of @context from the definitions to insert
into @context in the document.
Grahame
public class JsonLdReadTest {
>> @Test
>> public final void test() throws JsonGenerationException, IOException {
>> // read the jsonld file (with a URI as value of @context)
>> File f = new File("/Users/fps/Desktop/jsonldTest.json");
>> Object jsonLdObject = JsonUtils.fromInputStream(new
>> FileInputStream(f));
>>
>> // read the context file
>> // (here from disk, normally read file at URI defined in @context)
>> File ctxf = new File("/Users/fps/Desktop/jsonl
>> dTestContext.json");
>> Object jsonLdContext = JsonUtils.fromInputStream(new
>> FileInputStream(ctxf));
>>
>> // jsonldObject is a Map.
>> // Replace value associated to @context
>> ((Map) jsonLdObject).put("@context", jsonLdContext);
>>
>> // the jsonld with the @context replaced
>> String jsonld = JsonUtils.toString(jsonLdObject);
>>
>> System.out.println(jsonld);
>>
>> // no problem now to parse it
>> Model m = parse(jsonld);
>> }
>>
>> private Model parse(String jsonld) {
>> Model m = ModelFactory.createDefaultModel();
>> StringReader reader = new StringReader(jsonld);
>> m.read(reader, null, "JSON-LD");
>> return m;
>> }
>>
>> }
>>
>>
>
>
> --
> -----
> http://www.healthintersections.com.au / [email protected]
> / +61 411 867 065 <+61%20411%20867%20065>
>
--
-----
http://www.healthintersections.com.au / [email protected]
/ +61 411 867 065