use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class ConstructGraphTest method testConstructGraphBNode.
@Test
public void testConstructGraphBNode() throws MalformedQueryException {
String query = "select ?x where { _:b <uri:talksTo> ?x. _:b <uri:worksAt> ?z }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructGraph graph = new ConstructGraph(patterns);
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", vf.createURI("uri:Joe"));
bs.addBinding("z", vf.createURI("uri:BurgerShack"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
Set<RyaStatement> statements2 = graph.createGraphFromBindingSet(vBs);
RyaURI subject = null;
for (RyaStatement statement : statements) {
RyaURI subjURI = statement.getSubject();
if (subject == null) {
subject = subjURI;
} else {
assertEquals(subjURI, subject);
}
}
RyaURI subject2 = null;
for (RyaStatement statement : statements2) {
RyaURI subjURI = statement.getSubject();
if (subject2 == null) {
subject2 = subjURI;
} else {
assertEquals(subjURI, subject2);
}
}
assertTrue(!subject.equals(subject2));
ConstructGraphTestUtils.ryaStatementsEqualIgnoresBlankNode(statements, statements2);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class ConstructGraphTest method testConstructGraph.
@Test
public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException {
String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructGraph graph = new ConstructGraph(patterns);
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", vf.createURI("uri:Joe"));
bs.addBinding("y", vf.createURI("uri:Bob"));
bs.addBinding("z", vf.createURI("uri:BurgerShack"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Bob"), new RyaURI("uri:worksAt"), new RyaURI("uri:BurgerShack"));
Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2));
expected.forEach(x -> x.setColumnVisibility("FOUO".getBytes()));
ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class ConstructProjectionTest method testConstructProjectionProjPred.
@Test
public void testConstructProjectionProjPred() throws MalformedQueryException {
String query = "select ?p where { <uri:Joe> ?p <uri:Bob> }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructProjection projection = new ConstructProjection(patterns.get(0));
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("p", vf.createURI("uri:worksWith"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>());
RyaStatement expected = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:worksWith"), new RyaURI("uri:Bob"));
expected.setTimestamp(statement.getTimestamp());
expected.setColumnVisibility(new byte[0]);
assertEquals(expected, statement);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class StatementPatternMatcherTest method matchesPredicate.
@Test
public void matchesPredicate() throws Exception {
// Create the matcher against a pattern that matches a specific predicate.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "?s <urn:talksTo> ?o ." + "}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("o", vf.createURI("urn:Bob"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class StatementPatternMatcherTest method matchesObject.
@Test
public void matchesObject() throws Exception {
// Create the matcher against a pattern that matches a specific object.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "?s ?p <urn:Bob> ." + "}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("p", vf.createURI("urn:talksTo"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
Aggregations