use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser 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.createIRI("uri:Joe"));
bs.addBinding("y", VF.createIRI("uri:Bob"));
bs.addBinding("z", VF.createIRI("uri:BurgerShack"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob"));
RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Bob"), new RyaIRI("uri:worksAt"), new RyaIRI("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.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class ConstructGraphTest method testConstructGraphSerializerBlankNode.
@Test
public void testConstructGraphSerializerBlankNode() throws MalformedQueryException {
String query = "select ?x where { _:b <uri:talksTo> ?x. _:b <uri:worksAt> ?y }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructGraph graph = new ConstructGraph(patterns);
String constructString = ConstructGraphSerializer.toConstructString(graph);
ConstructGraph deserialized = ConstructGraphSerializer.toConstructGraph(constructString);
assertEquals(graph, deserialized);
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser 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.createIRI("uri:Joe"));
bs.addBinding("z", VF.createIRI("uri:BurgerShack"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
Set<RyaStatement> statements2 = graph.createGraphFromBindingSet(vBs);
RyaIRI subject = null;
for (RyaStatement statement : statements) {
RyaIRI subjURI = statement.getSubject();
if (subject == null) {
subject = subjURI;
} else {
assertEquals(subjURI, subject);
}
}
RyaIRI subject2 = null;
for (RyaStatement statement : statements2) {
RyaIRI subjURI = statement.getSubject();
if (subject2 == null) {
subject2 = subjURI;
} else {
assertEquals(subjURI, subject2);
}
}
assertTrue(!subject.equals(subject2));
ConstructGraphTestUtils.ryaStatementsEqualIgnoresBlankNode(statements, statements2);
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser 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.createIRI("uri:worksWith"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>());
RyaStatement expected = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:worksWith"), new RyaIRI("uri:Bob"));
expected.setTimestamp(statement.getTimestamp());
expected.setColumnVisibility(new byte[0]);
assertEquals(expected, statement);
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class AccumuloSelectivityEvalDAOTest method getSpList.
private List<StatementPattern> getSpList(String query) throws MalformedQueryException {
SPARQLParser sp = new SPARQLParser();
ParsedQuery pq = sp.parseQuery(query, null);
TupleExpr te = pq.getTupleExpr();
return StatementPatternCollector.process(te);
}
Aggregations