use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractDatasetGraphFind method find_union_01.
@Test
public void find_union_01() {
List<Quad> x = toList(dsg.find(Quad.unionGraph, null, null, null));
assertEquals(3, x.size());
x.stream().allMatch(q -> q.getGraph().equals(Quad.unionGraph));
List<Triple> z = x.stream().map(Quad::asTriple).collect(Collectors.toList());
assertTrue(z.contains(q4.asTriple()));
assertTrue(z.contains(q5.asTriple()));
Quad qx = Quad.create(Quad.unionGraph, q4.asTriple());
assertTrue(x.contains(qx));
Quad qz = Quad.create(Quad.unionGraph, q2.asTriple());
assertFalse(x.contains(qz));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestFmtUtils method stringForQuadEncoding.
@Test
public void stringForQuadEncoding() {
Node n1 = NodeFactory.createURI("q1");
Quad quad = new Quad(n1, getTriple());
assertEquals("<q1> <n1> <n2> \"l3\"", stringForQuad(quad));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractQuadOutputFormatTests method generateTuples.
@Override
protected Iterator<QuadWritable> generateTuples(int num) {
List<QuadWritable> qs = new ArrayList<QuadWritable>();
for (int i = 0; i < num; i++) {
Quad q = new Quad(NodeFactory.createURI("http://example.org/graphs/" + i), NodeFactory.createURI("http://example.org/subjects/" + i), NodeFactory.createURI("http://example.org/predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
qs.add(new QuadWritable(q));
}
return qs.iterator();
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractTriplesToQuadsMapper method map.
@Override
protected final void map(TKey key, TripleWritable value, Context context) throws IOException, InterruptedException {
Triple triple = value.get();
Node graphNode = this.selectGraph(triple);
context.write(key, new QuadWritable(new Quad(graphNode, triple)));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestEmbeddedFuseki method embedded_04.
@Test
public void embedded_04() {
DatasetGraph dsg = dataset();
Txn.executeWrite(dsg, () -> {
Quad q = SSE.parseQuad("(_ :s :p _:b)");
dsg.add(q);
});
// A service with just being able to do quads operations
// That is, GET, POST, PUT on "/data" in N-quads and TriG.
DataService dataService = new DataService(dsg);
dataService.addEndpoint(OperationName.Quads_RW, "");
dataService.addEndpoint(OperationName.Query, "");
dataService.addEndpoint(OperationName.Update, "");
int port = FusekiLib.choosePort();
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
server.start();
try {
// Put data in.
String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
Graph g = SSE.parseGraph(data);
HttpEntity e = graphToHttpEntity(g);
HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
// Get data out.
try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
Graph g2 = GraphFactory.createDefaultGraph();
RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
assertTrue(g.isIsomorphicWith(g2));
}
// Query.
query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(3, x);
});
// Update
UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
// Query again.
query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(0, x);
});
} finally {
server.stop();
}
}
Aggregations