use of org.apache.jena.query.Query in project jena by apache.
the class TestAPI method testARQConstructQuad_Prefix.
// Allow duplicated template quads in execConstructQuads()
@Test
public void testARQConstructQuad_Prefix() {
String queryString = "PREFIX : <http://example/ns#> CONSTRUCT { GRAPH :g1 { ?s :p ?o} } WHERE { ?s ?p ?o }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Quad> quads = qExec.execConstructQuads();
DatasetGraph result = DatasetGraphFactory.create();
long count = 0;
while (quads.hasNext()) {
count++;
Quad qd = quads.next();
result.add(qd);
}
DatasetGraph expected = DatasetGraphFactory.create();
expected.add(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
assertEquals(1, count);
assertTrue(IsoMatcher.isomorphic(expected, result));
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestAPI method testARQConstructQuad_a_1.
// // Execute a test both with and without regex optimization enabled
// // Check the number of results
// private void XexecRegexTest(int expected, String queryString)
// {
// Object b = ARQ.getContext().get(ARQ.enableRegexConstraintsOpt) ;
// try {
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "false") ;
// int count1 = queryAndCount(queryString) ;
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "true") ;
// int count2 = queryAndCount(queryString) ;
// assertEquals("Different number of results", count1, count2) ;
// if ( expected >= 0 )
// assertEquals("Unexpected number of results", expected, count1) ;
// } finally {
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, b) ;
// }
// }
// ARQ Construct Quad Tests:
// Two types of query strings: a) construct triple string; b) construct quad string;
// Two kinds of query methods: 1) execTriples(); 2) execQuads();
// Test a)+1)
@Test
public void testARQConstructQuad_a_1() {
String queryString = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Triple> ts = qExec.execConstructTriples();
Model result = ModelFactory.createDefaultModel();
while (ts.hasNext()) {
Triple t = ts.next();
Statement stmt = ModelUtils.tripleToStatement(result, t);
if (stmt != null)
result.add(stmt);
}
assertEquals(3, result.size());
assertTrue(m.isIsomorphicWith(result));
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestAPI method testExecJson.
/**
* Test that a JSON query returns an array with the correct size, given a pre-populated model.
*/
@Test
public void testExecJson() {
// JENA-632
Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } " + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, m)) {
JsonArray jsonArray = qexec.execJson();
assertNotNull(jsonArray);
assertEquals(3, jsonArray.size());
}
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestAPI method testInitialBindings7.
@Test
public void testInitialBindings7() {
// JENA-1354
Query query = QueryFactory.create("SELECT DISTINCT ?x WHERE {}");
Dataset ds = DatasetFactory.create();
QuerySolutionMap initialBinding = new QuerySolutionMap();
initialBinding.add("a", ResourceFactory.createTypedLiteral(Boolean.TRUE));
try (QueryExecution qexec = QueryExecutionFactory.create(query, ds, initialBinding)) {
assertFalse(qexec.execSelect().next().contains("a"));
}
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestAPI method testARQConstructQuad_Duplicate_1.
// Allow duplicated quads in execConstructQuads()
@Test
public void testARQConstructQuad_Duplicate_1() {
String queryString = "CONSTRUCT { GRAPH ?g1 {?s ?p ?o} } WHERE { ?s ?p ?o. GRAPH ?g1 {?s1 ?p1 ?o1} }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Quad> ts = qExec.execConstructQuads();
long count = 0;
Quad expected = Quad.create(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
while (ts.hasNext()) {
count++;
Quad qd = ts.next();
assertEquals(expected, qd);
}
// 3 duplicated quads
assertEquals(3, count);
}
Aggregations