use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithBindingSetSameContext.
@Test
public void simpleQueryWithBindingSetSameContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph ?c {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("c", new URIImpl("uri:context1"));
QueryBindingSet bsConstraint2 = new QueryBindingSet();
bsConstraint2.addBinding("c", new URIImpl("uri:context1"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", new URIImpl("uri:Joe"));
expected.addBinding("c", new URIImpl("uri:context1"));
Assert.assertEquals(expected, bsList.get(0));
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryNoBindingSetConstantContext.
@Test
public void simpleQueryNoBindingSetConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph <uri:context1> {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", new URIImpl("uri:Joe"));
Assert.assertEquals(expected, bsList.get(0));
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithoutBindingSets.
@Test
public void simpleQueryWithoutBindingSets() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph ?c {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(3, bsList.size());
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new URIImpl("uri:Joe"));
expected1.addBinding("c", new URIImpl("uri:context1"));
QueryBindingSet expected2 = new QueryBindingSet();
expected2.addBinding("x", new URIImpl("uri:Doug"));
expected2.addBinding("c", new URIImpl("uri:context2"));
QueryBindingSet expected3 = new QueryBindingSet();
expected3.addBinding("x", new URIImpl("uri:Eric"));
expected3.addBinding("c", new URIImpl("uri:context3"));
Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2, expected3));
Set<BindingSet> actual = new HashSet<>(bsList);
Assert.assertEquals(expected, actual);
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testClearGraph.
public void testClearGraph() throws Exception {
RepositoryConnection conn = repository.getConnection();
String insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G1 {\n" + "<http://example/book3> dc:title \"A new book\" ;\n" + " dc:creator \"A.N.Other\" .\n" + "}\n" + "}";
Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
update.execute();
insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G2 {\n" + "<http://example/book3> dc:title \"A new book\" ;\n" + " dc:creator \"A.N.Other\" .\n" + "}\n" + "}";
update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
update.execute();
String query = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "select * where { <http://example/book3> ?p ?o. }";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(4, tupleHandler.getCount());
tupleHandler = new CountTupleHandler();
conn.clear(new URIImpl("http://example/addresses#G2"));
tupleQuery.evaluate(tupleHandler);
assertEquals(2, tupleHandler.getCount());
tupleHandler = new CountTupleHandler();
conn.clear(new URIImpl("http://example/addresses#G1"));
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StreamingTestIT method addRandomQueryStatementPairs.
private void addRandomQueryStatementPairs(final int numPairs) throws Exception {
final Set<Statement> statementPairs = new HashSet<>();
for (int i = 0; i < numPairs; i++) {
final String uri = "http://uuid_" + UUID.randomUUID().toString();
final Statement statement1 = new StatementImpl(new URIImpl(uri), new URIImpl("http://pred1"), new LiteralImpl("number_" + (i + 1)));
final Statement statement2 = new StatementImpl(new URIImpl(uri), new URIImpl("http://pred2"), new LiteralImpl("literal"));
statementPairs.add(statement1);
statementPairs.add(statement2);
}
super.getRyaSailRepository().getConnection().add(statementPairs, new Resource[0]);
super.getMiniFluo().waitForObservers();
}
Aggregations