private void addTripleToDataset(RDFDataset dataset, RDFDataset.Node subject, RDFDataset.Node predicate, RDFDataset.Node object){ String name = "@default"; RDFDataset.Quad triple = new RDFDataset.Quad(subject, predicate, object, name); // initialise graph in dataset if (!dataset.containsKey(name)) { final List<RDFDataset.Quad> tmp = new ArrayList<RDFDataset.Quad>(); tmp.add(triple); dataset.put(name, tmp); } // add triple if unique to its graph else { final List<RDFDataset.Quad> triples = (List<RDFDataset.Quad>) dataset.get(name); if (!triples.contains(triple)) { triples.add(triple); } } }
private void addTypeTripleToDataset(RDFDataset dataset, String id, String type) { String name = "@default"; RDFDataset.Quad triple = new RDFDataset.Quad(id, JsonLdConsts.RDF_TYPE, type, name); // initialise graph in dataset if (!dataset.containsKey(name)) { final List<RDFDataset.Quad> tmp = new ArrayList<RDFDataset.Quad>(); tmp.add(triple); dataset.put(name, tmp); } // add triple if unique to its graph else { final List<RDFDataset.Quad> triples = (List<RDFDataset.Quad>) dataset.get(name); if (!triples.contains(triple)) { triples.add(triple); } } } }
final RDFDataset.Quad triple = new RDFDataset.Quad(subject, predicate, object, name);
firstBNode = new BlankNode(api.generateBlankNodeIdentifier()); triples.add(new Quad(subject, predicate, firstBNode, graphName)); for (int i = 0; i < list.size() - 1; i++) { final Node object = objectToRDF(list.get(i)); triples.add(new Quad(firstBNode, first, object, graphName)); final Node restBNode = new BlankNode(api.generateBlankNodeIdentifier()); triples.add(new Quad(firstBNode, rest, restBNode, graphName)); firstBNode = restBNode; triples.add(new Quad(firstBNode, first, last, graphName)); triples.add(new Quad(firstBNode, rest, nil, graphName)); final Node object = objectToRDF(item); if (object != null) { triples.add(new Quad(subject, predicate, object, graphName));
firstBNode = new BlankNode(api.generateBlankNodeIdentifier()); triples.add(new Quad(subject, predicate, firstBNode, graphName)); for (int i = 0; i < list.size() - 1; i++) { final Node object = objectToRDF(list.get(i)); triples.add(new Quad(firstBNode, first, object, graphName)); final Node restBNode = new BlankNode(api.generateBlankNodeIdentifier()); triples.add(new Quad(firstBNode, rest, restBNode, graphName)); firstBNode = restBNode; triples.add(new Quad(firstBNode, first, last, graphName)); triples.add(new Quad(firstBNode, rest, nil, graphName)); final Node object = objectToRDF(item); if (object != null) { triples.add(new Quad(subject, predicate, object, graphName));
final RDFDataset.Quad triple = new RDFDataset.Quad(subject, predicate, object, name);
final RDFDataset.Quad triple = new RDFDataset.Quad(subject, predicate, object, name);
/** * Adds a triple to the specified graph of this dataset * * @param s * the subject for the triple * @param p * the predicate for the triple * @param value * the value of the literal object for the triple * @param datatype * the datatype of the literal object for the triple (null values * will default to xsd:string) * @param graph * the graph to add this triple to * @param language * the language of the literal object for the triple (or null) */ public void addQuad(final String s, final String p, final String value, final String datatype, final String language, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(s, p, value, datatype, language, graph)); }
/** * Adds a triple to the specified graph of this dataset * * @param s * the subject for the triple * @param p * the predicate for the triple * @param value * the value of the literal object for the triple * @param datatype * the datatype of the literal object for the triple (null values * will default to xsd:string) * @param graph * the graph to add this triple to * @param language * the language of the literal object for the triple (or null) */ public void addQuad(final String s, final String p, final String value, final String datatype, final String language, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(s, p, value, datatype, language, graph)); }
/** * Adds a triple to the specified graph of this dataset * * @param s * the subject for the triple * @param p * the predicate for the triple * @param value * the value of the literal object for the triple * @param datatype * the datatype of the literal object for the triple (null values * will default to xsd:string) * @param graph * the graph to add this triple to * @param language * the language of the literal object for the triple (or null) */ public void addQuad(final String s, final String p, final String value, final String datatype, final String language, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(s, p, value, datatype, language, graph)); }
/** * Adds a triple to the specified graph of this dataset * * @param subject * the subject for the triple * @param predicate * the predicate for the triple * @param object * the object for the triple * @param graph * the graph to add this triple to */ public void addQuad(final String subject, final String predicate, final String object, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(subject, predicate, object, graph)); }
/** * Adds a triple to the specified graph of this dataset * * @param subject * the subject for the triple * @param predicate * the predicate for the triple * @param object * the object for the triple * @param graph * the graph to add this triple to */ public void addQuad(final String subject, final String predicate, final String object, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(subject, predicate, object, graph)); }
/** * Adds a triple to the specified graph of this dataset * * @param subject * the subject for the triple * @param predicate * the predicate for the triple * @param object * the object for the triple * @param graph * the graph to add this triple to */ public void addQuad(final String subject, final String predicate, final String object, String graph) { if (graph == null) { graph = "@default"; } if (!containsKey(graph)) { put(graph, new ArrayList<Quad>()); } ((ArrayList<Quad>) get(graph)).add(new Quad(subject, predicate, object, graph)); }
RDFDataset.Quad createJsonLdQuad(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) { return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object), asJsonLdString(graphName)); }
@Test public void compareToDifferentSubject() throws Exception { final Quad q2 = new Quad("http://example.com/other", "http://example.com/p1", "http://example.com/o1", "http://example.com/g1"); assertNotEquals(0, q.compareTo(q2)); }
@Test public void compareToDifferentPredicate() throws Exception { final Quad q2 = new Quad("http://example.com/s1", "http://example.com/other", "http://example.com/o1", "http://example.com/g1"); assertNotEquals(0, q.compareTo(q2)); }
@Test public void compareToDifferentGraph() throws Exception { final Quad q2 = new Quad("http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "http://example.com/other"); assertNotEquals(0, q.compareTo(q2)); }
@Test public void compareToDifferentObject() throws Exception { final Quad q2 = new Quad("http://example.com/s1", "http://example.com/p1", "http://example.com/other", "http://example.com/g1"); assertNotEquals(0, q.compareTo(q2)); }
@Test public void compareToDifferentObjectType() throws Exception { final Quad q2 = new Quad("http://example.com/s1", "http://example.com/p1", "http://example.com/other", null, null, // literal "http://example.com/g1"); assertNotEquals(0, q.compareTo(q2)); }
@Test public void compareToSame() throws Exception { final Quad q2 = new Quad("http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "http://example.com/g1"); assertEquals(0, q.compareTo(q2)); // Should still compare equal, even if extra attributes are added q2.put("example", "value"); assertEquals(0, q.compareTo(q2)); }