/** * Outputs the RDF dataset found in the given JSON-LD object. * * @param input * the JSON-LD input. * @param options * the options to use: [base] the base IRI to use. [format] the * format to use to output a string: 'application/nquads' for * N-Quads (default). [loadContext(url, callback(err, url, * result))] the context loader. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdOptions options) throws JsonLdError { return toRDF(input, null, options); }
/** * Outputs the RDF dataset found in the given JSON-LD object. * * @param input * the JSON-LD input. * @param options * the options to use: [base] the base IRI to use. [format] the * format to use to output a string: 'application/nquads' for * N-Quads (default). [loadContext(url, callback(err, url, * result))] the context loader. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdOptions options) throws JsonLdError { return toRDF(input, null, options); }
/** * Outputs the RDF dataset found in the given JSON-LD object. * * @param input * the JSON-LD input. * @param options * the options to use: [base] the base IRI to use. [format] the * format to use to output a string: 'application/nquads' for * N-Quads (default). [loadContext(url, callback(err, url, * result))] the context loader. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdOptions options) throws JsonLdError { return toRDF(input, null, options); }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input) throws JsonLdError { return toRDF(input, new JsonLdOptions("")); }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input) throws JsonLdError { return toRDF(input, new JsonLdOptions("")); }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input) throws JsonLdError { return toRDF(input, new JsonLdOptions("")); }
/** * Load triples from JSON-LD to graph * * @param callback * @throws java.io.IOException * @throws com.github.jsonldjava.core.JsonLdError */ public void load(JSONLDTripleCallback callback) throws IOException, JsonLdError { // resolve the "reader" to JSON objects using parser Object jsonObject = JSONUtils.fromReader(this.reader); JsonLdProcessor.toRDF(jsonObject, callback); } }
/** * Load triples from JSON-LD to graph * * @param callback * @throws java.io.IOException * @throws com.github.jsonldjava.core.JsonLdError */ public void load(JSONLDTripleCallback callback) throws IOException, JsonLdError { // resolve the "reader" to JSON objects using parser Object jsonObject = JSONUtils.fromReader(this.reader); JsonLdProcessor.toRDF(jsonObject, callback); } }
/** * Load triples from JSON-LD to graph * * @param callback * @throws java.io.IOException * @throws com.github.jsonldjava.core.JsonLdError */ public void load(JSONLDTripleCallback callback) throws IOException, JsonLdError { // resolve the "reader" to JSON objects using parser Object jsonObject = JSONUtils.fromReader(this.reader); JsonLdProcessor.toRDF(jsonObject, callback); } }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @param callback * A callback that is called when the input has been converted to * Quads (null to use options.format instead). * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdTripleCallback callback) throws JsonLdError { return toRDF(input, callback, new JsonLdOptions("")); }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @param callback * A callback that is called when the input has been converted to * Quads (null to use options.format instead). * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdTripleCallback callback) throws JsonLdError { return toRDF(input, callback, new JsonLdOptions("")); }
/** * Outputs the RDF dataset found in the given JSON-LD object, using the * default {@link JsonLdOptions}. * * @param input * the JSON-LD input. * @param callback * A callback that is called when the input has been converted to * Quads (null to use options.format instead). * @return A JSON-LD object. * @throws JsonLdError * If there is an error converting the dataset to JSON-LD. */ public static Object toRDF(Object input, JsonLdTripleCallback callback) throws JsonLdError { return toRDF(input, callback, new JsonLdOptions("")); }
public String convertJSONLD(String json) throws IOException, JsonLdError { JsonLdOptions jsonLdOptions = new JsonLdOptions(); jsonLdOptions.format = "application/nquads"; Object jsonObject = JsonUtils.fromString(json); return JsonLdProcessor.toRDF(jsonObject, jsonLdOptions).toString(); }
public void parse(final InputStream in, final String sourceURI) throws JsonLdError, IOException { _callback = new JsonLDtripleCallback(sourceURI); final JsonLdOptions options = new JsonLdOptions(sourceURI); JsonLdProcessor .toRDF(JsonUtils.fromInputStream(in), _callback, options); }
@Override public void parse(final InputStream in, final String baseURI) throws IOException, RDFParseException, RDFHandlerException { final SesameTripleCallback callback = new SesameTripleCallback(getRDFHandler(), valueFactory, getParserConfig(), getParseErrorListener()); final JsonLdOptions options = new JsonLdOptions(baseURI); options.useNamespaces = true; try { JsonLdProcessor.toRDF(JsonUtils.fromInputStream(in), callback, options); } catch (final JsonLdError e) { throw new RDFParseException("Could not parse JSONLD", e); } catch (final JsonParseException e) { throw new RDFParseException("Could not parse JSONLD", e); } catch (final RuntimeException e) { if (e.getCause() != null && e.getCause() instanceof RDFParseException) { throw (RDFParseException) e.getCause(); } throw e; } }
/** * Performs RDF dataset normalization on the given JSON-LD input. The output * is an RDF dataset unless the 'format' option is used. * * @param input * the JSON-LD input to normalize. * @param options * the options to use: [base] the base IRI to use. [format] the * format if output is a string: 'application/nquads' for * N-Quads. [loadContext(url, callback(err, url, result))] the * context loader. * @return The JSON-LD object * @throws JsonLdError * If there is an error normalizing the dataset. */ public static Object normalize(Object input, JsonLdOptions options) throws JsonLdError { final JsonLdOptions opts = new JsonLdOptions(options.getBase()); opts.format = null; final RDFDataset dataset = (RDFDataset) toRDF(input, opts); return new JsonLdApi(options).normalize(dataset); }
@Test( groups = {MUST}, description = " LDP servers must respond with a application/ld+json " + "representation of the requested LDP-RS when the request " + "includes an Accept header, unless content negotiation or " + "Turtle support requires a different outcome [JSON-LD].") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldprs-get-jsonld", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testJsonLdRepresentation() throws IOException, JsonLdError { Response response = buildBaseRequestSpecification() .header(ACCEPT, "application/ld+json, application/json;q=0.5") .expect() .statusCode(isSuccessful()) .contentType(HeaderMatchers.isJsonLdCompatibleContentType()) .when() .get(getResourceUri()); // Make sure it parses as JSON-LD. Object json = JsonUtils.fromInputStream(response.asInputStream()); JsonLdProcessor.toRDF(json); // throws JsonLdError if not valid }
@Test public void toRdfWithNamespace() throws Exception { final URL contextUrl = getClass().getResource("/custom/contexttest-0003.jsonld"); assertNotNull(contextUrl); final Object context = JsonUtils.fromURL(contextUrl, JsonUtils.getDefaultHttpClient()); assertNotNull(context); final JsonLdOptions options = new JsonLdOptions(); options.useNamespaces = true; final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(context, options); // System.out.println(rdf.getNamespaces()); assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat")); assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev")); }
@Test public void fromRdfWithNamespaceLexicographicallyShortestChosen2() throws Exception { final RDFDataset inputRdf = new RDFDataset(); inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/"); inputRdf.setNamespace("aatrev", "http://vocab.getty.edu/aat/rev/"); inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype"); final JsonLdOptions options = new JsonLdOptions(); options.useNamespaces = true; final Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf), inputRdf.getContext(), options); final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options); // System.out.println(rdf.getNamespaces()); assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat")); assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aatrev")); final String toJSONLD = JsonUtils.toPrettyString(fromRDF); // System.out.println(toJSONLD); assertFalse("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/")); }
@Test public void fromRdfWithNamespaceLexicographicallyShortestChosen() throws Exception { final RDFDataset inputRdf = new RDFDataset(); inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/"); inputRdf.setNamespace("aat_rev", "http://vocab.getty.edu/aat/rev/"); inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype"); final JsonLdOptions options = new JsonLdOptions(); options.useNamespaces = true; final Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf), inputRdf.getContext(), options); final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options); // System.out.println(rdf.getNamespaces()); assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat")); assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev")); final String toJSONLD = JsonUtils.toPrettyString(fromRDF); // System.out.println(toJSONLD); assertTrue("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/")); }