/** * Framing does not work on named graphs so we need to pull just the graph nodes out. * * @see <a href="https://github.com/jsonld-java/jsonld-java/issues/109">#109</a> */ @Override protected Map<String, Object> applyOnce(Object input, JsonLdOptions options) throws JsonLdError { if (input instanceof Map<?, ?>) { Map<?, ?> inputMap = (Map<?, ?>) input; if (inputMap.containsKey(JsonLdConsts.GRAPH)) { // Only pass the context and the graph itself to the framing implementation Map<String, Object> alternateInput = new LinkedHashMap<>(); alternateInput.put(JsonLdConsts.CONTEXT, inputMap.get(JsonLdConsts.CONTEXT)); alternateInput.put(JsonLdConsts.GRAPH, inputMap.get(JsonLdConsts.GRAPH)); alternateInput.values().removeIf(Objects::isNull); input = alternateInput; } } // There is a bug in the JSON-LD API where an empty list causes an NPE if (BdioDocument.toGraphNodes(input).isEmpty()) { Map<String, Object> emptyResult = new HashMap<>(1); emptyResult.put(JsonLdConsts.GRAPH, new ArrayList<>(0)); return emptyResult; } else { return JsonLdProcessor.frame(input, frame, options); } } }
@Test public void testFrame0001() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0001-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0001-in.jsonld")); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, new JsonLdOptions()); assertEquals(2, frame2.size()); }
@Test public void testFrame0002() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0002-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0002-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(false); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0002-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0006() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0006-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0006-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(true); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0006-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0008() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0008-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0008-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setEmbed("@always"); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0008-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0007() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0007-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0007-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(true); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0007-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0004() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(true); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0005() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0005-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0005-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(true); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0005-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0009() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0009-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0009-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setProcessingMode("json-ld-1.1"); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0009-out.jsonld")); assertEquals(out, frame2); }
@Test public void testFrame0003() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0002-frame.jsonld")); final Object in = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0002-in.jsonld")); final JsonLdOptions opts = new JsonLdOptions(); opts.setCompactArrays(false); opts.setProcessingMode("json-ld-1.1"); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); assertFalse("Result should contain no blank nodes", frame2.toString().contains("_:")); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0003-out.jsonld")); assertEquals(out, frame2); }
frame = JsonUtils.fromString((String) frame); obj = JsonLdProcessor.frame(obj, frame, opts);
rval = JsonLdProcessor.frame(rval, frame, new JsonLdOptions(manifestURL));
@Test public void testFrame0010() throws IOException, JsonLdError { final Object frame = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0010-frame.jsonld")); //{ // "@id": "http://example.com/main/id", // "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": { // "@id": "http://example.com/rdf/id", // "http://www.w3.org/1999/02/22-rdf-syntax-ns#label": "someLabel" // } //} final RDFDataset ds = new RDFDataset(); ds.addTriple("http://example.com/main/id", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://example.com/rdf/id"); ds.addTriple("http://example.com/rdf/id", "http://www.w3.org/1999/02/22-rdf-syntax-ns#label", "someLabel", null, null); final JsonLdOptions opts = new JsonLdOptions(); opts.setProcessingMode(JsonLdOptions.JSON_LD_1_0); final Object in = new JsonLdApi(opts).fromRDF(ds, true); final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts); final Object out = JsonUtils .fromInputStream(getClass().getResourceAsStream("/custom/frame-0010-out.jsonld")); assertEquals(out, frame2); } }
final Map<String, Object> frameJson = (Map<String, Object>) JsonUtils .fromInputStream(frameStream); result = JsonLdProcessor.frame(input, frameJson, options); } else if (testType.contains("jld:FromRDFTest")) { result = JsonLdProcessor.fromRDF(input, options);