Search in sources :

Example 11 with SPARQLParser

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);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 12 with SPARQLParser

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);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) Test(org.junit.Test)

Example 13 with SPARQLParser

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);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 14 with SPARQLParser

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);
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaStatement(org.apache.rya.api.domain.RyaStatement) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 15 with SPARQLParser

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);
}
Also used : SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

SPARQLParser (org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)260 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)244 Test (org.junit.Test)208 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)162 ArrayList (java.util.ArrayList)99 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)99 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)82 QueryModelNode (org.eclipse.rdf4j.query.algebra.QueryModelNode)62 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)43 RyaIRI (org.apache.rya.api.domain.RyaIRI)42 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)40 RyaStatement (org.apache.rya.api.domain.RyaStatement)39 BindingSet (org.eclipse.rdf4j.query.BindingSet)37 Projection (org.eclipse.rdf4j.query.algebra.Projection)37 RyaType (org.apache.rya.api.domain.RyaType)35 HashSet (java.util.HashSet)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)20 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)18