Search in sources :

Example 76 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class QueryVariableNormalizerTest method testNeq2.

/**
 * @throws Exception
 *             Tests QueryVariableNormalizerContext to see if it recognizes
 *             that no substitution exists for the variables of q8 given
 *             that it has more variables than q1
 */
@Test
public void testNeq2() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q1, null);
    ParsedQuery pq2 = parser2.parseQuery(q8, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 0);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 77 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class QueryVariableNormalizerTest method tesGraphVarInBody.

@Test
public void tesGraphVarInBody() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q19, null);
    ParsedQuery pq2 = parser2.parseQuery(q25, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 1);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 78 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class QueryVariableNormalizerTest method testOrderEq.

/**
 * @throws Exception
 *             Tests QueryVariable normalizer on queries q9 and q18, where
 *             q18 is obtained from q9 by reordering lines.
 */
@Test
public void testOrderEq() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q9, null);
    ParsedQuery pq2 = parser2.parseQuery(q18, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 24);
    for (TupleExpr s : normalize) {
        Assert.assertTrue(isTupleSubset(s, pq1.getTupleExpr()) && isTupleSubset(pq1.getTupleExpr(), s));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 79 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class QueryVariableNormalizerTest method testVarGraph.

@Test
public void testVarGraph() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q19, null);
    ParsedQuery pq2 = parser2.parseQuery(q22, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 1);
    for (TupleExpr s : normalize) {
        Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 80 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class VarConstQueryVariableNormalizerTest method queryConstantNodeOneMatch.

@Test
public void queryConstantNodeOneMatch() throws Exception {
    SPARQLParser p = new SPARQLParser();
    ParsedQuery pq1 = p.parseQuery(query1, null);
    ParsedQuery pq2 = p.parseQuery(index1, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertEquals(1, normalize.size());
    for (TupleExpr te : normalize) {
        Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), te));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Aggregations

SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)265 ParsedQuery (org.openrdf.query.parser.ParsedQuery)249 Test (org.junit.Test)212 TupleExpr (org.openrdf.query.algebra.TupleExpr)162 ArrayList (java.util.ArrayList)100 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)99 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 StatementPattern (org.openrdf.query.algebra.StatementPattern)82 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)62 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)45 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)43 RyaURI (org.apache.rya.api.domain.RyaURI)42 BindingSet (org.openrdf.query.BindingSet)41 RyaStatement (org.apache.rya.api.domain.RyaStatement)39 Projection (org.openrdf.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 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19