Search in sources :

Example 66 with SPARQLParser

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

the class QueryVariableNormalizerTest method testEqNEQ.

/**
 * @throws Exception
 *             Tests QueryVariableNormalizerContext to see if it recognizes
 *             that no substitution exists for two moderate, similar queries
 *             q5 and q1 that are structurally different
 */
@Test
public void testEqNEQ() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q1, null);
    ParsedQuery pq2 = parser2.parseQuery(q5, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 0);
    pq1 = parser1.parseQuery(q5, null);
    pq2 = parser2.parseQuery(q1, null);
    List<TupleExpr> normalize2 = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertEquals(1, normalize2.size());
    for (TupleExpr s : normalize2) {
        List<TupleExpr> testList = QueryVariableNormalizer.getNormalizedIndex(pq2.getTupleExpr(), s);
        Assert.assertEquals(1, testList.size());
        for (TupleExpr t : testList) {
            Assert.assertTrue(t.equals(pq2.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 67 with SPARQLParser

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

the class QueryVariableNormalizerTest method testFilters1.

@Test
public void testFilters1() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q30, null);
    ParsedQuery pq2 = parser2.parseQuery(q31, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 1);
    for (TupleExpr s : normalize) {
        Assert.assertTrue(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 68 with SPARQLParser

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

the class QueryVariableNormalizerTest method testMedVarGraph.

@Test
public void testMedVarGraph() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q24, null);
    ParsedQuery pq2 = parser2.parseQuery(q25, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 2);
    for (TupleExpr s : normalize) {
        Assert.assertTrue(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 69 with SPARQLParser

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

the class QueryVariableNormalizerTest method testFilters3.

@Test
public void testFilters3() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q33, null);
    ParsedQuery pq2 = parser2.parseQuery(q35, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertTrue(normalize.size() == 1);
    for (TupleExpr s : normalize) {
        Assert.assertTrue(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 70 with SPARQLParser

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

the class QueryVariableNormalizerTest method testNeq.

/**
 * @throws Exception
 *             Tests QueryVariableNormalizerContext to see if it recognizes
 *             that no substitution exists for the large queries q8 and q9
 *             which contain the same number of variables and are similar.
 */
@Test
public void testNeq() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q9, 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)

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