use of org.apache.rya.api.model.VisibilityBindingSet 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.apache.rya.api.model.VisibilityBindingSet 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.apache.rya.api.model.VisibilityBindingSet 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.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class MultiProjectionEvaluatorTest method singleBlankNode.
@Test
public void singleBlankNode() throws Exception {
// Read the multi projection object from a SPARQL query.
final MultiProjection multiProjection = getMultiProjection("CONSTRUCT {" + "_:b a <urn:movementObservation> ; " + "<urn:location> ?location ; " + "<urn:direction> ?direction ; " + "}" + "WHERE {" + "?thing <urn:corner> ?location ." + "?thing <urn:compass> ?direction." + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("location", vf.createLiteral("South St and 5th St"));
bs.addBinding("direction", vf.createLiteral("NW"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// Create the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final String blankNodeId = UUID.randomUUID().toString();
final BNode blankNode = vf.createBNode(blankNodeId);
bs = new MapBindingSet();
bs.addBinding("subject", blankNode);
bs.addBinding("predicate", RDF.TYPE);
bs.addBinding("object", vf.createURI("urn:movementObservation"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
bs = new MapBindingSet();
bs.addBinding("subject", blankNode);
bs.addBinding("predicate", vf.createURI("urn:location"));
bs.addBinding("object", vf.createLiteral("South St and 5th St"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
bs = new MapBindingSet();
bs.addBinding("subject", blankNode);
bs.addBinding("predicate", vf.createURI("urn:direction"));
bs.addBinding("object", vf.createLiteral("NW"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
// Run the projection evaluator.
final Set<VisibilityBindingSet> results = MultiProjectionEvaluator.make(multiProjection, () -> blankNodeId).project(original);
// The expected binding sets.
assertEquals(expected, results);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class MultiProjectionEvaluatorTest method multipleBlanknodes.
@Test
public void multipleBlanknodes() throws Exception {
// Read the multi projection object from a SPARQL query.
final MultiProjection multiProjection = getMultiProjection("CONSTRUCT {" + "_:b a <urn:vehicle> . " + "_:b <urn:tiresCount> 4 ." + "_:c a <urn:pet> . " + "_:c <urn:isDead> false . " + "}" + "WHERE {" + "?vehicle <urn:owner> ?owner . " + "?vehicle <urn:plates> ?plates . " + "?pet <urn:owner> ?owner . " + "?pet <urn:isLiving> true . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("vehicle", vf.createLiteral("Alice's car"));
bs.addBinding("owner", vf.createURI("urn:Alice"));
bs.addBinding("plates", vf.createLiteral("XXXXXXX"));
bs.addBinding("pet", vf.createURI("urn:Kitty"));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
// Run the projection evaluator.
final Set<VisibilityBindingSet> results = MultiProjectionEvaluator.make(multiProjection, new RandomUUIDFactory()).project(original);
// Figure out the blank nodes.
Value vehicalBNode = null;
Value petBNode = null;
for (final VisibilityBindingSet result : results) {
final Value object = result.getValue("object");
if (object.equals(vf.createURI("urn:vehicle"))) {
vehicalBNode = result.getValue("subject");
} else if (object.equals(vf.createURI("urn:pet"))) {
petBNode = result.getValue("subject");
}
}
// The expected binding sets.
final Set<VisibilityBindingSet> expected = new HashSet<>();
bs = new MapBindingSet();
bs.addBinding("subject", vehicalBNode);
bs.addBinding("predicate", RDF.TYPE);
bs.addBinding("object", vf.createURI("urn:vehicle"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
bs = new MapBindingSet();
bs.addBinding("subject", vehicalBNode);
bs.addBinding("predicate", vf.createURI("urn:tiresCount"));
bs.addBinding("object", vf.createLiteral("4", XMLSchema.INTEGER));
expected.add(new VisibilityBindingSet(bs, "a|b"));
bs = new MapBindingSet();
bs.addBinding("subject", petBNode);
bs.addBinding("predicate", RDF.TYPE);
bs.addBinding("object", vf.createURI("urn:pet"));
expected.add(new VisibilityBindingSet(bs, "a|b"));
bs = new MapBindingSet();
bs.addBinding("subject", petBNode);
bs.addBinding("predicate", vf.createURI("urn:isDead"));
bs.addBinding("object", vf.createLiteral(false));
expected.add(new VisibilityBindingSet(bs, "a|b"));
assertEquals(expected, results);
}
Aggregations