use of org.apache.jena.query.ResultSet in project jena by apache.
the class FusekiBuilder method getOne.
public static RDFNode getOne(Resource svc, String property) {
String ln = property.substring(property.indexOf(':') + 1);
ResultSet rs = FusekiLib.query("SELECT * { ?svc " + property + " ?x}", svc.getModel(), "svc", svc);
if (!rs.hasNext())
throw new FusekiConfigException("No " + ln + " for service " + FusekiLib.nodeLabel(svc));
RDFNode x = rs.next().get("x");
if (rs.hasNext())
throw new FusekiConfigException("Multiple " + ln + " for service " + FusekiLib.nodeLabel(svc));
return x;
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class EvaluatorSimple method dump.
private static void dump(Table table) {
System.out.println("Table: " + Lib.className(table));
QueryIterator qIter = table.iterator(null);
ResultSet rs = new ResultSetStream(table.getVarNames(), null, table.iterator(null));
ResultSetFormatter.out(rs);
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class SelectBuilderTest method testVarReplacementInSubQuery.
@Test
public void testVarReplacementInSubQuery() throws ParseException {
Model m = ModelFactory.createDefaultModel();
Resource r = m.createResource("urn:one");
m.add(r, m.getProperty("urn:p:one"), m.createTypedLiteral(1));
m.add(r, m.getProperty("urn:p:two"), m.createTypedLiteral(3));
m.add(r, m.getProperty("urn:p:three"), m.createTypedLiteral(5));
r = m.createResource("urn:two");
m.add(r, m.getProperty("urn:p:one"), m.createTypedLiteral(2));
m.add(r, m.getProperty("urn:p:two"), m.createTypedLiteral(4));
m.add(r, m.getProperty("urn:p:three"), m.createTypedLiteral(6));
SelectBuilder sb = new SelectBuilder().addVar("?x").addVar("?p").addWhere("?x", "?p", "?o").addFilter("?o < ?limit");
builder.addPrefix("xsd", XSD.getURI()).addVar("?x").addVar("count(?p)", "?c").addWhere("?x", "?p", "?o2").addSubQuery(sb).addGroupBy("?x");
builder.setVar("?limit", 4);
QueryExecution qexec = QueryExecutionFactory.create(builder.build(), m);
ResultSet results = qexec.execSelect();
assertTrue(results.hasNext());
for (; results.hasNext(); ) {
QuerySolution soln = results.nextSolution();
assertTrue(soln.contains("x"));
assertTrue(soln.contains("c"));
if ("urn:one".equals(soln.get("?x").asResource().getURI())) {
assertEquals(2, soln.get("?c").asLiteral().getInt());
} else {
assertEquals(1, soln.get("?c").asLiteral().getInt());
}
}
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class SelectBuilderTest method testAggregatorsInSubQuery.
@Test
public void testAggregatorsInSubQuery() throws ParseException {
Model m = ModelFactory.createDefaultModel();
Resource r = m.createResource("urn:one");
m.add(r, m.getProperty("urn:p:one"), m.createTypedLiteral(1));
m.add(r, m.getProperty("urn:p:two"), m.createTypedLiteral(3));
m.add(r, m.getProperty("urn:p:three"), m.createTypedLiteral(5));
r = m.createResource("urn:two");
m.add(r, m.getProperty("urn:p:one"), m.createTypedLiteral(2));
m.add(r, m.getProperty("urn:p:two"), m.createTypedLiteral(4));
m.add(r, m.getProperty("urn:p:three"), m.createTypedLiteral(6));
SelectBuilder sb = new SelectBuilder().addVar("?x").addVar("max(?o)", "?max").addWhere("?x", "?p", "?o").addGroupBy("?x");
builder.addPrefix("xsd", XSD.getURI()).addVar("?x").addVar("min(?o2)", "?min").addWhere("?x", "?p2", "?o2").addSubQuery(sb).addFilter("?max = '6'^^xsd:int").addGroupBy("?x");
QueryExecution qexec = QueryExecutionFactory.create(builder.build(), m);
ResultSet results = qexec.execSelect();
assertTrue(results.hasNext());
for (; results.hasNext(); ) {
QuerySolution soln = results.nextSolution();
assertTrue(soln.contains("x"));
assertTrue(soln.contains("min"));
assertEquals("urn:two", soln.get("?x").asResource().getURI());
assertEquals(2, soln.get("?min").asLiteral().getInt());
}
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestEmbeddedFuseki method embedded_03.
// Different dataset name.
@Test
public void embedded_03() {
DatasetGraph dsg = dataset();
int port = FusekiLib.choosePort();
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/ds1", dsg).build();
server.start();
try {
// Add while live.
Txn.executeWrite(dsg, () -> {
Quad q = SSE.parseQuad("(_ :s :p _:b)");
dsg.add(q);
});
query("http://localhost:" + port + "/ds1/query", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(1, x);
});
} finally {
server.stop();
}
}
Aggregations