private void addStatement(RDFDataset result, URI context, Resource subject, URI predicate, URI object) { if (context == null) { result.addTriple(subject.toString(), predicate.toString(), object.toString()); } else { result.addQuad(subject.toString(), predicate.toString(), object.toString(), context.toString()); } }
private void addStatement(RDFDataset result, URI context, Resource subject, URI predicate, String value) { if (context == null) { result.addTriple(subject.toString(), predicate.toString(), value, null, null); } else { result.addQuad(subject.toString(), predicate.toString(), value, null, null, context.toString()); } }
private void addStatement(RDFDataset result, URI context, Resource subject, URI predicate, String value, URI datatype) { if (context == null) { result.addTriple(subject.toString(), predicate.toString(), value, datatype.toString(), null); } else { result.addQuad(subject.toString(), predicate.toString(), value, datatype.toString(), null, context.toString()); } }
private void addStatement(RDFDataset result, URI context, Resource subject, URI predicate, String value, String language) { if (context == null) { result.addTriple(subject.toString(), predicate.toString(), value, null, language); } else { result.addQuad(subject.toString(), predicate.toString(), value, null, language, context.toString()); } }
result.addTriple(state.curSubject, state.curPredicate, bnode); state.advanceLinePosition(1); result.addTriple(state.curSubject, state.curPredicate, RDF_NIL); result.addTriple(state.curSubject, state.curPredicate, bnode); state.push(); state.curSubject = bnode; validateIRI(state, iri); result.addTriple(state.curSubject, state.curPredicate, iri); } else { datatype = XSD_BOOLEAN; result.addTriple(state.curSubject, state.curPredicate, value, datatype, lang); + "position: " + state.linePosition + "}"); result.addTriple(state.curSubject, RDF_REST, RDF_NIL); state.pop(); state.advanceLinePosition(1); result.addTriple(state.curSubject, RDF_REST, bnode); state.curSubject = bnode; continue;
private void handleStatement(RDFDataset result, Triple t, Map<BlankNode,String> bNodeMap) { final String subject = getResourceValue(t.getSubject(), bNodeMap); final String predicate = getResourceValue(t.getPredicate(), bNodeMap); final RDFTerm object = t.getObject(); if (object instanceof Literal) { final String value = ((Literal)object).getLexicalForm(); final String language; final String datatype; datatype = getResourceValue(((Literal)object).getDataType(), bNodeMap); Language l = ((Literal)object).getLanguage(); if(l == null){ language = null; } else { language = l.toString(); } result.addTriple(subject, predicate, value, datatype, language); count++; } else { result.addTriple(subject, predicate, getResourceValue((BlankNodeOrIRI) object, bNodeMap)); count++; } }
private void handleStatement(RDFDataset result, Triple t, Map<BlankNode,String> bNodeMap) { final String subject = getResourceValue(t.getSubject(), bNodeMap); final String predicate = getResourceValue(t.getPredicate(), bNodeMap); final RDFTerm object = t.getObject(); if (object instanceof Literal) { final String value = ((Literal)object).getLexicalForm(); final String language; final String datatype; datatype = getResourceValue(((Literal)object).getDataType(), bNodeMap); Language l = ((Literal)object).getLanguage(); if(l == null){ language = null; } else { language = l.toString(); } result.addTriple(subject, predicate, value, datatype, language); count++; } else { result.addTriple(subject, predicate, getResourceValue((BlankNodeOrIRI) object, bNodeMap)); count++; } }
private void handleStatement(RDFDataset result, Triple t, Map<BlankNode, String> blankNodeMap) { final String subject = getResourceValue(t.getSubject(), blankNodeMap); final String predicate = getResourceValue(t.getPredicate(), blankNodeMap); final RDFTerm object = t.getObject(); if (object instanceof Literal) { final Literal literalObject = (Literal) object; final String value = literalObject.getLexicalForm(); final String language; final String datatype; if (literalObject.getLanguage() != null) { language = literalObject.getLanguage().toString(); datatype = RDF_LANG_STRING; } else { datatype = getResourceValue(literalObject.getDataType(), blankNodeMap); language = null; } result.addTriple(subject, predicate, value, datatype, language); count++; } else { result.addTriple(subject, predicate, getResourceValue((BlankNodeOrIRI) object, blankNodeMap)); count++; } }
@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); } }
inputRdf.addTriple(subjectGenerator.apply(i), predicateGenerator.apply(i), objectGenerator.apply(i));
potentialSubjects.get(prng.nextInt(potentialSubjects.size())), null); } else if (i % 5 == 0) { testData.addTriple( potentialSubjects.get(prng.nextInt(potentialSubjects.size())), potentialPredicates.get(prng.nextInt(potentialPredicates.size())), potentialSubjects.get(prng.nextInt(potentialSubjects.size()))); } else if (i % 5 == 0) { testData.addTriple( potentialSubjects.get(prng.nextInt(potentialSubjects.size())), potentialPredicates.get(prng.nextInt(potentialPredicates.size())),
@Test public void prefixUsedToShortenPredicate() throws Exception { final RDFDataset inputRdf = new RDFDataset(); inputRdf.setNamespace("ex", "http://www.a.com/foo/"); inputRdf.addTriple("http://www.a.com/foo/s", "http://www.a.com/foo/p", "http://www.a.com/foo/o"); assertEquals("http://www.a.com/foo/", inputRdf.getNamespace("ex")); final JsonLdOptions options = new JsonLdOptions(); options.useNamespaces = true; final Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf), inputRdf.getContext(), options); final String toJSONLD = JsonUtils.toPrettyString(fromRDF); // System.out.println(toJSONLD); assertFalse("The lexicographically shortest URI was not chosen", toJSONLD.contains("http://www.a.com/foo/p")); }
@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/")); }
@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/")); }