You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rya.apache.org by mi...@apache.org on 2015/12/07 13:04:44 UTC
[14/51] [partial] incubator-rya git commit: Cannot delete temp branch,
doc'd it.
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/ExternalProcessorTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/ExternalProcessorTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/ExternalProcessorTest.java
deleted file mode 100644
index bac9871..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/ExternalProcessorTest.java
+++ /dev/null
@@ -1,1654 +0,0 @@
-package mvm.rya.indexing.external.tupleSet;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-import mvm.rya.indexing.external.ExternalProcessor;
-import mvm.rya.indexing.external.ExternalProcessor.BindingSetAssignmentCollector;
-import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
-import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Assert;
-import org.openrdf.query.algebra.Projection;
-import org.openrdf.query.algebra.QueryModelNode;
-import org.openrdf.query.algebra.StatementPattern;
-import org.openrdf.query.algebra.TupleExpr;
-import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
-import org.openrdf.query.algebra.helpers.StatementPatternCollector;
-import org.openrdf.query.parser.ParsedQuery;
-import org.openrdf.query.parser.sparql.SPARQLParser;
-
-import com.google.common.collect.Sets;
-
-
-
-
-
-
-public class ExternalProcessorTest {
-
-
-
-
- private String queryString = ""//
- + "SELECT ?e ?c ?l ?o " //
- + "{" //
- + " ?e a ?c . "//
- + " ?c a ?l . "//
- + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
- + " ?e <uri:talksTo> ?o "//
- + "}";//
-
- private String indexSparqlString = ""//
- + "SELECT ?x ?y ?z " //
- + "{" //
- + " ?x <http://www.w3.org/2000/01/rdf-schema#label> ?z. "//
- + " ?x a ?y . "//
- + " ?y a ?z "//
- + "}";//
-
-
- private String q1 = ""//
- + "SELECT ?e ?l ?c " //
- + "{" //
- + " ?e a ?c . "//
- + " ?c <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
- + " ?l <uri:talksTo> ?e . "//
- + "}";//
-
- private String q2 = ""//
- + "SELECT ?a ?t ?v " //
- + "{" //
- + " ?a a ?t . "//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?v . "//
- + " ?v <uri:talksTo> ?a . "//
- + "}";//
-
-
-
- private String q5 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " //
- + "{" //
- + " ?f a ?m ."//
- + " ?e a ?l ."//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?p <uri:talksTo> ?n . "//
- + " ?r <uri:talksTo> ?a . "//
- + "}";//
-
-
-
- private String q7 = ""//
- + "SELECT ?s ?t ?u " //
- + "{" //
- + " ?s a ?t ."//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."//
- + " ?u <uri:talksTo> ?s . "//
- + "}";//
-
-
- private String q8 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " //
- + "{" //
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?f a ?m ."//
- + " ?p <uri:talksTo> ?n . "//
- + " ?e a ?l ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?r <uri:talksTo> ?a . "//
- + "}";//
-
-
-
-
- private String q11 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r ?x ?y ?w ?t ?duck ?chicken ?pig ?rabbit " //
- + "{" //
- + " ?w a ?t ."//
- + " ?x a ?y ."//
- + " ?duck a ?chicken ."//
- + " ?pig a ?rabbit ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?f a ?m ."//
- + " ?p <uri:talksTo> ?n . "//
- + " ?e a ?l ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?r <uri:talksTo> ?a . "//
- + "}";//
-
-
- private String q12 = ""//
- + "SELECT ?b ?p ?dog ?cat " //
- + "{" //
- + " ?b a ?p ."//
- + " ?dog a ?cat. "//
- + "}";//
-
-
-
- private String q13 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r ?x ?y ?w ?t ?duck ?chicken ?pig ?rabbit ?dick ?jane ?betty " //
- + "{" //
- + " ?w a ?t ."//
- + " ?x a ?y ."//
- + " ?duck a ?chicken ."//
- + " ?pig a ?rabbit ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?f a ?m ."//
- + " ?p <uri:talksTo> ?n . "//
- + " ?e a ?l ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?r <uri:talksTo> ?a . "//
- + " ?dick <uri:talksTo> ?jane . "//
- + " ?jane <uri:talksTo> ?betty . "//
- + "}";//
-
-
- private String q14 = ""//
- + "SELECT ?harry ?susan ?mary " //
- + "{" //
- + " ?harry <uri:talksTo> ?susan . "//
- + " ?susan <uri:talksTo> ?mary . "//
- + "}";//
-
-
-
- String q15 = ""//
- + "SELECT ?a ?b ?c ?d ?e ?f ?q " //
- + "{" //
- + " GRAPH ?x { " //
- + " ?a a ?b ."//
- + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?d <uri:talksTo> ?e . "//
- + " FILTER ( ?e < ?f && (?a > ?b || ?c = ?d) ). " //
- + " FILTER(bound(?f) && sameTerm(?a,?b)&&bound(?q)). " //
- + " ?b a ?q ."//
- + " }"//
- + "}";//
-
-
- String q16 = ""//
- + "SELECT ?g ?h ?i " //
- + "{" //
- + " GRAPH ?y { " //
- + " ?g a ?h ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?i ."//
- + " }"//
- + "}";//
-
- String q17 = ""//
- + "SELECT ?j ?k ?l ?m ?n ?o " //
- + "{" //
- + " GRAPH ?z { " //
- + " ?j <uri:talksTo> ?k . "//
- + " FILTER ( ?k < ?l && (?m > ?n || ?o = ?j) ). " //
- + " }"//
- + "}";//
-
- String q18 = ""//
- + "SELECT ?r ?s ?t ?u " //
- + "{" //
- + " GRAPH ?q { " //
- + " FILTER(bound(?r) && sameTerm(?s,?t)&&bound(?u)). " //
- + " ?t a ?u ."//
- + " }"//
- + "}";//
-
-
-
- String q19 = ""//
- + "SELECT ?a ?b ?c ?d ?e ?f ?q ?g ?h " //
- + "{" //
- + " GRAPH ?x { " //
- + " ?a a ?b ."//
- + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?d <uri:talksTo> ?e . "//
- + " FILTER ( ?e < ?f && (?a > ?b || ?c = ?d) ). " //
- + " FILTER(bound(?f) && sameTerm(?a,?b)&&bound(?q)). " //
- + " FILTER(?g IN (1,2,3) && ?h NOT IN(5,6,7)). " //
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?g. "//
- + " ?b a ?q ."//
- + " }"//
- + "}";//
-
-
- String q20 = ""//
- + "SELECT ?m ?n " //
- + "{" //
- + " GRAPH ?q { " //
- + " FILTER(?m IN (1,2,3) && ?n NOT IN(5,6,7)). " //
- + " ?n <http://www.w3.org/2000/01/rdf-schema#label> ?m. "//
- + " }"//
- + "}";//
-
-
- String q21 = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"Polygon\")) " //
- + "}";//
-
-
- String q22 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?person ?commentmatch ?labelmatch" //
- + "{" //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?labelmatch . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#comment> ?commentmatch . "//
- + " FILTER(fts:text(?labelmatch, \"bob\")) . " //
- + " FILTER(fts:text(?commentmatch, \"bob\")) " //
- + "}";//
-
-
- String q23 = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?a ?b ?c " //
- + "{" //
- + " ?a a geo:Feature . "//
- + " ?b a geo:Point . "//
- + " ?b geo:asWKT ?c . "//
- + " FILTER(geof:sfWithin(?c, \"Polygon\")) " //
- + "}";//
-
-
- String q24 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?f ?g " //
- + "{" //
- + " ?f <http://www.w3.org/2000/01/rdf-schema#comment> ?g . "//
- + " FILTER(fts:text(?g, \"bob\")) " //
- + "}";//
-
-
- String q25 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?person ?commentmatch ?labelmatch ?point" //
- + "{" //
- + " ?person a ?point. " //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?labelmatch . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#comment> ?commentmatch . "//
- + " FILTER((?person > ?point) || (?person = ?labelmatch)). "
- + " FILTER(fts:text(?labelmatch, \"bob\")) . " //
- + " FILTER(fts:text(?commentmatch, \"bob\")) " //
- + "}";//
-
-
- String q26 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?a ?b ?c " //
- + "{" //
- + " ?a a ?c. " //
- + " ?a a <http://example.org/ontology/Person> . "//
- + " ?a <http://www.w3.org/2000/01/rdf-schema#label> ?b . "//
- + " FILTER((?a > ?c) || (?a = ?b)). "
- + " FILTER(fts:text(?b, \"bob\")) . " //
- + "}";//
-
-
-
- String q27 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?person ?commentmatch ?labelmatch ?other ?feature ?point ?wkt ?g ?h" //
- + "{" //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?labelmatch . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#comment> ?commentmatch . "//
- + " FILTER((?person > ?other) || (?person = ?labelmatch)). "
- + " ?person a ?other. "//
- + " FILTER(fts:text(?labelmatch, \"bob\")) . " //
- + " FILTER(fts:text(?commentmatch, \"bob\")) " //
- + " ?feature a geo:Feature . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"Polygon\")) " //
- + " FILTER(?g IN (1,2,3) && ?h NOT IN(5,6,7)). " //
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?g. "//
- + "}";//
-
-
- String q28 = ""//
- + "SELECT ?m ?n " //
- + "{" //
- + " FILTER(?m IN (1,2,3) && ?n NOT IN(5,6,7)). " //
- + " ?n <http://www.w3.org/2000/01/rdf-schema#label> ?m. "//
- + "}";//
-
-
- String q29 = ""//
- + "SELECT ?m ?n ?o" //
- + "{" //
- + " FILTER(?m IN (1,2,3) && ?n NOT IN(5,6,7)). " //
- + " ?n <http://www.w3.org/2000/01/rdf-schema#label> ?m. "//
- + " ?m a ?o." //
- + " FILTER(ISNUMERIC(?o))."
- + "}";//
-
- String q30 = ""//
- + "SELECT ?pig ?dog ?owl" //
- + "{" //
- + " FILTER(?pig IN (1,2,3) && ?dog NOT IN(5,6,7)). " //
- + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig. "//
- + " ?pig a ?owl. " //
- + " FILTER(ISNUMERIC(?owl))."
- + "}";//
-
-
- String q31 = ""//
- + "SELECT ?q ?r ?s " //
- + "{" //
- + " {?q a ?r} UNION {?r a ?s} ."//
- + " ?r a ?s ."//
- + "}";//
-
-
-
- String q33 = ""//
- + "SELECT ?q ?r ?s ?t " //
- + "{" //
- + " OPTIONAL {?q a ?r} ."//
- + " ?s a ?t ."//
- + "}";//
-
-
- String q34 = ""//
- + "SELECT ?q ?r " //
- + "{" //
- + " FILTER(?q > ?r) ."//
- + " ?q a ?r ."//
- + "}";//
-
-
- String q35 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?s ?t ?u ?v ?w ?x ?y ?z " //
- + "{" //
- + " FILTER(?s > ?t)."//
- + " ?s a ?t ."//
- + " FILTER(?u > ?v)."//
- + " ?u a ?v ."//
- + " ?w <http://www.w3.org/2000/01/rdf-schema#label> ?x ."//
- + " FILTER(fts:text(?x, \"bob\")) . " //
- + " ?y <http://www.w3.org/2000/01/rdf-schema#label> ?z ."//
- + " FILTER(fts:text(?z, \"bob\")) . " //
- + "}";//
-
-
- String q36 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?dog ?cat " //
- + "{" //
- + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?cat ."//
- + " FILTER(fts:text(?cat, \"bob\")) . " //
- + "}";//
-
-
- String q37 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?s ?t " //
- + "{" //
- + " FILTER(?s > ?t)."//
- + " ?s a ?t ."//
- + " FILTER(?s > ?t)."//
- + " ?s a ?t ."//
- + " FILTER(?s > ?t)."//
- + " ?s a ?t ."//
- + "}";//
-
-
-
- String q38 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?s ?t " //
- + "{" //
- + " FILTER(?s > ?t)."//
- + " ?s a ?t ."//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?s ."//
- + " FILTER(?s > ?t)."//
- + "}";//
-
-
-
- String q39 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?s ?t " //
- + "{" //
- + " VALUES(?s) { (<ub:poodle>)(<ub:pitbull>)} ." //
- + " ?t <ub:peesOn> <ub:rug> ." //
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?s ."//
- + "}";//
-
- String q40 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?u ?v " //
- + "{" //
- + " ?v <ub:peesOn> <ub:rug> ." //
- + " ?v <http://www.w3.org/2000/01/rdf-schema#label> ?u ."//
- + "}";//
-
- String q41 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?s ?t ?w ?x" //
- + "{" //
- + " FILTER(?s > ?t)."//
- + " VALUES(?s) { (<ub:poodle>)(<ub:pitbull>)} ." //
- + " VALUES(?w) { (<ub:persian>) (<ub:siamese>) } ." //
- + " ?t <ub:peesOn> <ub:rug> ." //
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?s ."//
- + " ?w <ub:peesOn> <ub:rug> ." //
- + " ?w <http://www.w3.org/2000/01/rdf-schema#label> ?x ."//
- + "}";//
-
- String q42 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?u ?v " //
- + "{" //
- + " FILTER(?u > ?v)."//
- + " ?v <ub:peesOn> <ub:rug> ." //
- + " ?v <http://www.w3.org/2000/01/rdf-schema#label> ?u ."//
- + "}";//
-
- String q43 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?a ?b " //
- + "{" //
- + " ?b <ub:peesOn> <ub:rug> ." //
- + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?a ."//
- + "}";//
-
-
-
-
- @Test
- public void testVarRelableIndexSmaller() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(queryString, null);
- ParsedQuery pq2 = parser2.parseQuery(indexSparqlString, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
-
-
- Assert.assertTrue(qSet.containsAll(set) && set.size() != 0);
-
- }
-
-
-
- @Test
- public void testVarRelableIndexSameSize() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q1, null);
- ParsedQuery pq2 = parser2.parseQuery(q2, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
-
- Assert.assertTrue(set.equals(qSet));
-
-
- }
-
-
-
-
-
- @Test
- public void testTwoIndexLargeQuery() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q11, null);
- ParsedQuery pq2 = parser2.parseQuery(q7, null);
- ParsedQuery pq3 = parser3.parseQuery(q12, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(set.equals(qSet));
-
-
- }
-
-
-
- @Test
- public void testThreeIndexLargeQuery() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
- SPARQLParser parser4 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q13, null);
- ParsedQuery pq2 = parser2.parseQuery(q5, null);
- ParsedQuery pq3 = parser3.parseQuery(q12, null);
- ParsedQuery pq4 = parser4.parseQuery(q14, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr()+ " , " + pq3.getTupleExpr()+ " , " +pq4.getTupleExpr());
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
- SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
- list.add(extTup3);
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(set.equals(qSet));
-
- }
-
-
-
-
-
-
-
-
- @Test
- public void testSingleIndexLargeQuery() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q8, null);
- ParsedQuery pq2 = parser2.parseQuery(q7, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
-
- Assert.assertTrue(set.equals(qSet));
-
- }
-
-
-
-
-
-
- @Test
- public void testContextFilter() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
- SPARQLParser parser4 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q15, null);
- ParsedQuery pq2 = parser2.parseQuery(q16, null);
- ParsedQuery pq3 = parser3.parseQuery(q17, null);
- ParsedQuery pq4 = parser4.parseQuery(q18, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr()+ " , " + pq3.getTupleExpr()+ " , " +pq4.getTupleExpr());
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
- SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
- list.add(extTup3);
-
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(qSet.containsAll(set) && eTupSet.size() == 1);
- }
-
-
-
-
-
- @Test
- public void testContextFilterFourIndex() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
- SPARQLParser parser4 = new SPARQLParser();
- SPARQLParser parser5 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q19, null);
- ParsedQuery pq2 = parser2.parseQuery(q16, null);
- ParsedQuery pq3 = parser3.parseQuery(q17, null);
- ParsedQuery pq4 = parser4.parseQuery(q18, null);
- ParsedQuery pq5 = parser5.parseQuery(q20, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr()+ " , " + pq3.getTupleExpr()+ " , " +pq4.getTupleExpr()+ " , " +pq5.getTupleExpr());
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
- SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
- SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet(new Projection(pq5.getTupleExpr()));
-
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
- list.add(extTup3);
- list.add(extTup4);
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(qSet.containsAll(set) && eTupSet.size() == 2);
- }
-
-
-
-
- @Test
- public void testGeoIndexFunction() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q21, null);
- ParsedQuery pq2 = parser2.parseQuery(q23, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
-
- Assert.assertTrue(qSet.containsAll(set) && set.size() != 0);
-
- }
-
-
-
- @Test
- public void testFreeTestIndexFunction() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q22, null);
- ParsedQuery pq2 = parser2.parseQuery(q24, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
-
- Assert.assertTrue(qSet.containsAll(set) && set.size() != 0);
-
- }
-
-
- @Test
- public void testThreeIndexGeoFreeCompareFilterMix() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q25, null);
- ParsedQuery pq2 = parser2.parseQuery(q24, null);
- ParsedQuery pq3 = parser3.parseQuery(q26, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 2);
-
-
- }
-
-
-
-
-
- @Test
- public void testFourIndexGeoFreeCompareFilterMix() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
- SPARQLParser parser4 = new SPARQLParser();
- SPARQLParser parser5 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q27, null);
- ParsedQuery pq2 = parser2.parseQuery(q23, null);
- ParsedQuery pq3 = parser3.parseQuery(q26, null);
- ParsedQuery pq4 = parser4.parseQuery(q24, null);
- ParsedQuery pq5 = parser5.parseQuery(q28, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr()+ " and " + pq5.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
- SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
- SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet(new Projection(pq5.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup4);
- list.add(extTup1);
- list.add(extTup2);
- list.add(extTup3);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Assert.assertTrue(eTupSet.size() == 4);
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(set.equals(qSet));
-
-
-
- }
-
-
-
-
-
- @Test
- public void testThreeIndexGeoFreeCompareFilterMix2() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
- SPARQLParser parser4 = new SPARQLParser();
-
-
- ParsedQuery pq1 = parser1.parseQuery(q27, null);
- ParsedQuery pq2 = parser2.parseQuery(q23, null);
- ParsedQuery pq3 = parser3.parseQuery(q26, null);
- ParsedQuery pq4 = parser4.parseQuery(q28, null);
-
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
- SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
-
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
-
- list.add(extTup1);
- list.add(extTup3);
- list.add(extTup2);
-
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Assert.assertTrue(eTupSet.size() == 3);
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
- Assert.assertTrue(qSet.containsAll(set));
-
-
- }
-
-
-
-
-
-
-
- @Test
- public void testISNUMERIC() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q29, null);
- ParsedQuery pq2 = parser2.parseQuery(q30, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
- Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 1);
-
-
- }
-
-
- @Test
- public void testInvalidQueryUnion() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q31, null);
- ParsedQuery pq2 = parser2.parseQuery(q31, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
- boolean thrown = false;
-
- try {
- ExternalProcessor processor = new ExternalProcessor(list);
- processor.process(pq1.getTupleExpr());
- } catch (IllegalArgumentException e) {
- System.out.println(e);
- thrown = true;
- }
-
- Assert.assertTrue(thrown);
-
- }
-
-
-
-
-
- @Test
- public void testInvalidQueryOptional() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q33, null);
- ParsedQuery pq2 = parser2.parseQuery(q33, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
- boolean thrown = false;
-
- try {
- ExternalProcessor processor = new ExternalProcessor(list);
- processor.process(pq1.getTupleExpr());
- } catch (IllegalArgumentException e) {
- System.out.println(e);
- thrown = true;
- }
-
- Assert.assertTrue(thrown);
-
- }
-
-
-
-
- @Test
- public void testTwoRepeatedIndex() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q35, null);
- ParsedQuery pq2 = parser2.parseQuery(q34, null);
- ParsedQuery pq3 = parser3.parseQuery(q36, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
-
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- System.out.println("Processed query is " + tup);
-
-
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for(QueryModelNode s: eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for(StatementPattern t: tempSet) {
- set.add(t);
- }
-
- }
-
-
- Assert.assertTrue(set.equals(qSet) && eTupSet.size()==4);
-
-
- }
-
-
-
- @Test
- public void testRepeatedStatementPatternQuery() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q37, null);
- ParsedQuery pq2 = parser2.parseQuery(q34, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
- boolean thrown = false;
-
- try {
- ExternalProcessor processor = new ExternalProcessor(list);
- processor.process(pq1.getTupleExpr());
- } catch (IllegalArgumentException e) {
- System.out.println(e);
- thrown = true;
- }
-
- Assert.assertTrue(thrown);
- }
-
-
-
-
-
-
-
-
- @Test
- public void testRepeatedFilterQuery() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q38, null);
- ParsedQuery pq2 = parser2.parseQuery(q38, null);
-
- System.out.println("Query is " + pq1.getTupleExpr());
- System.out.println("Index is " + pq2.getTupleExpr());
-
-
- SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup);
-
- boolean thrown = false;
-
- try {
- ExternalProcessor processor = new ExternalProcessor(list);
- processor.process(pq1.getTupleExpr());
- } catch (IllegalArgumentException e) {
- System.out.println(e);
- thrown = true;
- }
-
- Assert.assertTrue(thrown);
- }
-
-
-
-
- @Test
- public void testBindingSetAssignment1() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q39, null);
- ParsedQuery pq2 = parser2.parseQuery(q40, null);
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
-
- list.add(extTup1);
-
- ExternalProcessor processor = new ExternalProcessor(list);
-
- TupleExpr tup = processor.process(pq1.getTupleExpr());
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
-
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for (QueryModelNode s : eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for (StatementPattern t : tempSet) {
- set.add(t);
- }
-
- Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 1);
-
- BindingSetAssignmentCollector bsac1 = new BindingSetAssignmentCollector();
- BindingSetAssignmentCollector bsac2 = new BindingSetAssignmentCollector();
- pq1.getTupleExpr().visit(bsac1);
- tup.visit(bsac2);
-
- Assert.assertTrue(bsac1.getBindingSetAssignments().equals(bsac2.getBindingSetAssignments()));
-
- }
- }
-
-
- @Test
- public void testBindingSetAssignment2() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
- SPARQLParser parser3 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q41, null);
- ParsedQuery pq2 = parser2.parseQuery(q42, null);
- ParsedQuery pq3 = parser2.parseQuery(q43, null);
-
- SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
- SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
-
- List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
- list.add(extTup1);
- list.add(extTup2);
-
- ExternalProcessor processor = new ExternalProcessor(list);
- TupleExpr tup = processor.process(pq1.getTupleExpr());
- System.out.println("Processed query is " + tup);
-
- ExternalTupleVstor visitor = new ExternalTupleVstor();
- tup.visit(visitor);
-
- StatementPatternCollector spc = new StatementPatternCollector();
- pq1.getTupleExpr().visit(spc);
- Set<StatementPattern> qSet = Sets.newHashSet(spc.getStatementPatterns());
- ExternalTupleVstor eTup = new ExternalTupleVstor();
- tup.visit(eTup);
- Set<QueryModelNode> eTupSet = eTup.getExtTup();
- Set<StatementPattern> set = Sets.newHashSet();
- for (QueryModelNode s : eTupSet) {
- StatementPatternCollector spc1 = new StatementPatternCollector();
- ((ExternalTupleSet) s).getTupleExpr().visit(spc1);
- Set<StatementPattern> tempSet = Sets.newHashSet(spc1.getStatementPatterns());
- for (StatementPattern t : tempSet) {
- set.add(t);
- }
- }
-
- Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 2);
-
- BindingSetAssignmentCollector bsac1 = new BindingSetAssignmentCollector();
- BindingSetAssignmentCollector bsac2 = new BindingSetAssignmentCollector();
- pq1.getTupleExpr().visit(bsac1);
- tup.visit(bsac2);
-
- Assert.assertTrue(bsac1.getBindingSetAssignments().equals(bsac2.getBindingSetAssignments()));
-
- }
-
-
-
- public static class ExternalTupleVstor extends QueryModelVisitorBase<RuntimeException> {
-
- private Set<QueryModelNode> eSet = new HashSet<QueryModelNode>();
-
- @Override
- public void meetNode(QueryModelNode node) throws RuntimeException {
- if (node instanceof ExternalTupleSet) {
- eSet.add(node);
- }
- super.meetNode(node);
- }
-
- public Set<QueryModelNode> getExtTup() {
- return eSet;
- }
-
- }
-
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/QueryVariableNormalizerTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/QueryVariableNormalizerTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/QueryVariableNormalizerTest.java
deleted file mode 100644
index aec959e..0000000
--- a/extras/indexing/src/test/java/mvm/rya/indexing/external/tupleSet/QueryVariableNormalizerTest.java
+++ /dev/null
@@ -1,965 +0,0 @@
-package mvm.rya.indexing.external.tupleSet;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-import java.util.List;
-import java.util.Set;
-
-import mvm.rya.indexing.external.QueryVariableNormalizer;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.openrdf.query.algebra.StatementPattern;
-import org.openrdf.query.algebra.TupleExpr;
-import org.openrdf.query.algebra.helpers.StatementPatternCollector;
-import org.openrdf.query.parser.ParsedQuery;
-import org.openrdf.query.parser.sparql.SPARQLParser;
-
-import com.google.common.collect.Sets;
-
-
-
-public class QueryVariableNormalizerTest {
-
- private String q1 = ""//
- + "SELECT ?e ?l ?c " //
- + "{" //
- + " ?e a ?c . "//
- + " ?c <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
- + " ?l <uri:talksTo> ?e . "//
- + "}";//
-
- private String q2 = ""//
- + "SELECT ?a ?t ?v " //
- + "{" //
- + " ?a a ?t . "//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?v . "//
- + " ?v <uri:talksTo> ?a . "//
- + "}";//
-
- private String q3 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " ?f a ?d . "//
- + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?m "//
- + "}";//
-
- private String q4 = ""//
- + "SELECT ?s ?t ?u " //
- + "{" //
- + " ?s a ?t . "//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u "//
- + "}";//
-
- private String q5 = ""//
- + "SELECT ?f ?m ?d ?s " //
- + "{" //
- + " ?m a ?d . "//
- + " ?f a ?m . "//
- + " ?f a ?s . "//
- + " ?m <uri:talksTo> ?f . "//
- + " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?m "//
- + "}";//
-
- private String q6 = ""//
- + "SELECT ?q ?r ?s ?t ?u " //
- + "{" //
- + " ?q a ?r ."//
- + " ?r a ?s ."//
- + " ?t a ?u ."//
- + "}";//
-
- private String q7 = ""//
- + "SELECT ?s ?t ?u ?x ?y ?z " //
- + "{" //
- + " ?s a ?t ."//
- + " ?x a ?y ."//
- + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."//
- + " ?y <http://www.w3.org/2000/01/rdf-schema#label> ?z ."//
- + "}";//
-
- private String q8 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " //
- + "{" //
- + " ?f a ?m ."//
- + " ?e a ?l ."//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?f <uri:talksTo> ?m . "//
- + " ?m <uri:talksTo> ?a . "//
- + " ?o <uri:talksTo> ?r . "//
- + "}";//
-
- private String q9 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " //
- + "{" //
- + " ?f a ?m ."//
- + " ?e a ?l ."//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?p <uri:talksTo> ?n . "//
- + " ?r <uri:talksTo> ?a . "//
- + "}";//
-
- private String q10 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " ?f a ?m ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?d <uri:talksTo> ?f . "//
- + "}";//
-
- private String q11 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?x ?y ?z" //
- + "{" //
- + " ?f a ?m ."//
- + " ?m a ?d ."//
- + " ?d a ?e ."//
- + " ?e a ?l ."//
- + " ?l a ?c ."//
- + " ?x a ?y ."//
- + " ?y a ?z ."//
- + " ?z a ?x ."//
- + "}";//
-
- private String q12 = ""//
- + "SELECT ?s ?t ?u ?v " //
- + "{" //
- + " \"hello\" ?s ?t ."//
- + " ?t a ?u ."//
- + " ?u ?v \"m\" . "//
- + "}";//
-
- private String q13 = ""//
- + "SELECT ?x ?y ?z ?w " //
- + "{" //
- + " \"hello\" ?x ?y ."//
- + " ?y a ?z ."//
- + " ?z ?w \"m\" . "//
- + "}";//
-
- private String q14 = ""//
- + "SELECT ?e ?l ?c " //
- + "{" //
- + " ?c a ?l . "//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e. "//
- + " ?e <uri:talksTo> ?c . "//
- + "}";//
-
- String q15 = ""//
- + "SELECT ?x ?y ?z ?w " //
- + "{" //
- + " ?x ?y ?z ."//
- + " ?y ?z ?w ."//
- + "}";//
-
- String q16 = ""//
- + "SELECT ?a ?b ?c " //
- + "{" //
- + " ?a ?b ?c ."//
- + "}";//
-
- String q17 = ""//
- + "SELECT ?q ?r " //
- + "{" //
- + " ?q ?r \"url:\" ."//
- + "}";//
-
- private String q18 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " //
- + "{" //
- + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."//
- + " ?f a ?m ."//
- + " ?p <uri:talksTo> ?n . "//
- + " ?e a ?l ."//
- + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?c <uri:talksTo> ?e . "//
- + " ?n a ?o ."//
- + " ?a a ?h ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?r <uri:talksTo> ?a . "//
- + "}";//
-
- String q23 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " GRAPH ?x { " //
- + " ?f a ?m ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?x a ?f. "//
- + " }"//
- + "}";//
-
- String q22 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " GRAPH ?y { " //
- + " ?f a ?m ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?d <uri:talksTo> ?f . "//
- + " ?y a ?f . "//
- + " }"//
- + "}";//
-
- String q19 = ""//
- + "SELECT ?r ?s ?t " //
- + "{" //
- + " GRAPH ?u { " //
- + " ?r a ?s ."//
- + " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?t ."//
- + " ?t <uri:talksTo> ?r . "//
- + " ?u a ?r . "//
- + " }"//
- + "}";//
-
- String q20 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " GRAPH <https://non-constant> { " //
- + " ?f a ?m ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?d <uri:talksTo> ?f . "//
- + " }"//
- + "}";//
-
- String q21 = ""//
- + "SELECT ?r ?s ?t " //
- + "{" //
- + " GRAPH <https://non-constant> { " //
- + " ?r a ?s ."//
- + " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?t ."//
- + " ?t <uri:talksTo> ?r . "//
- + " }"//
- + "}";//
-
- private String q24 = ""//
- + "SELECT ?e ?l ?c ?x ?y ?z " //
- + "{" //
- + " GRAPH ?d { " //
- + " ?c a ?l . "//
- + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e. "//
- + " ?e <uri:talksTo> ?c . "//
- + " ?x a ?y . "//
- + " ?y <http://www.w3.org/2000/01/rdf-schema#label> ?z. "//
- + " ?z <uri:talksTo> ?x . "//
- + "}" //
- + "}";//
-
- String q25 = ""//
- + "SELECT ?f ?m ?d " //
- + "{" //
- + " GRAPH ?w { " //
- + " ?f a ?m ."//
- + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
- + " ?d <uri:talksTo> ?f . "//
- + " }"//
- + "}";//
-
- private String q26 = ""//
- + "SELECT ?f ?m ?d ?e ?l ?c ?x ?y ?z" //
- + "{" //
- + " GRAPH ?w { " //
- + " ?f a ?m ."//
- + " ?m a ?d ."//
- + " ?d a ?e ."//
- + " ?e a ?l ."//
- + " ?l a ?c ."//
- + " ?x a ?y ."//
- + " ?y a ?z ."//
- + " ?z a ?x ."//
- + " }"//
- + "}";//
-
- private String q27 = ""//
- + "SELECT ?q ?r ?s ?t ?u " //
- + "{" //
- + " GRAPH ?n { " //
- + " ?q a ?r ."//
- + " ?r a ?s ."//
- + " ?t a ?u ."//
- + " }"//
- + "}";//
-
-
-
-
- String q30 = ""//
- + "SELECT ?a ?b ?c ?d ?e ?f ?q ?g ?h " //
- + "{" //
- + " GRAPH ?x { " //
- + " ?a a ?b ."//
- + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ."//
- + " ?d <uri:talksTo> ?e . "//
- + " FILTER(bound(?f) && sameTerm(?a,?b)&&bound(?q)). " //
- + " FILTER ( ?e < ?f && (?a > ?b || ?c = ?d) ). " //
- + " FILTER(?g IN (1,2,3) && ?h NOT IN(5,6,7)). " //
- + " ?x <http://www.w3.org/2000/01/rdf-schema#label> ?g. "//
- + " ?b a ?q ."//
- + " }"//
- + "}";//
-
-
- String q31 = ""//
- + "SELECT ?m ?n " //
- + "{" //
- + " GRAPH ?q { " //
- + " FILTER(?m IN (1,2,3) && ?n NOT IN(5,6,7)). " //
- + " ?q <http://www.w3.org/2000/01/rdf-schema#label> ?m. "//
- + " }"//
- + "}";//
-
-
- String q32 = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?feature ?point ?wkt " //
- + "{" //
- + " ?feature a geo:Feature . "//
- + " ?feature geo:hasGeometry ?point . "//
- + " ?point a geo:Point . "//
- + " ?point geo:asWKT ?wkt . "//
- + " FILTER(geof:sfWithin(?wkt, \"Polygon\")) " //
- + "}";//
-
-
- String q33 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?person ?commentmatch ?labelmatch" //
- + "{" //
- + " ?person a <http://example.org/ontology/Person> . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?labelmatch . "//
- + " ?person <http://www.w3.org/2000/01/rdf-schema#comment> ?commentmatch . "//
- + " FILTER(fts:text(?labelmatch, \"bob\")) . " //
- + " FILTER(fts:text(?commentmatch, \"bob\")) " //
- + "}";//
-
-
- String q34 = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "//
- + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "//
- + "SELECT ?a ?b ?c " //
- + "{" //
- + " ?a a geo:Feature . "//
- + " ?b a geo:Point . "//
- + " ?b geo:asWKT ?c . "//
- + " FILTER(geof:sfWithin(?c, \"Polygon\")) " //
- + "}";//
-
-
- String q35 = "PREFIX fts: <http://rdf.useekm.com/fts#> "//
- + "SELECT ?a ?b " //
- + "{" //
- + " ?a <http://www.w3.org/2000/01/rdf-schema#comment> ?b . "//
- + " FILTER(fts:text(?b, \"bob\")) " //
- + "}";//
-
-
-
-
-
-
-
-
-
-
-
- /**
- * @param tuple1
- * @param tuple2
- * @return
- * @throws Exception
- */
- public boolean tupleEquals(TupleExpr tuple1, TupleExpr tuple2) throws Exception {
-
- Set<StatementPattern> spSet1 = Sets.newHashSet(StatementPatternCollector.process(tuple1));
- Set<StatementPattern> spSet2 = Sets.newHashSet(StatementPatternCollector.process(tuple2));
-
- return spSet1.equals(spSet2);
-
- }
-
- /**
- * @param tuple1
- * @param tuple2
- * @return
- * @throws Exception
- */
- public boolean isTupleSubset(TupleExpr tuple1, TupleExpr tuple2) throws Exception {
-
- Set<StatementPattern> spSet1 = Sets.newHashSet(StatementPatternCollector.process(tuple1));
- Set<StatementPattern> spSet2 = Sets.newHashSet(StatementPatternCollector.process(tuple2));
-
- return (Sets.intersection(spSet1, spSet2).equals(spSet2));
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext on the queries q1,q2
- * which are the same up to a relabeling of variables.
- */
- @Test
- public void testEqThreeDiffVars() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q1, null);
- ParsedQuery pq2 = parser2.parseQuery(q2, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertEquals(1, normalize.size());
-
- for (TupleExpr s : normalize) {
- Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
-
- }
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext on queries q1 and q14
- * which are the same up to the permutation of their variables.
- */
- @Test
- public void testEqThreePermuteVars() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q1, null);
- ParsedQuery pq2 = parser2.parseQuery(q14, null);
-
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertEquals(1, normalize.size());
-
- for (TupleExpr s : normalize) {
- Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
- }
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext on the queries q12 and
- * q13, which are the same up to a relabeling of the variables,
- * but have StatementPatterns whose constants are not
- * predicates.
- */
- @Test
- public void testEqPredNotConst() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q12, null);
- ParsedQuery pq2 = parser2.parseQuery(q13, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertEquals(1, normalize.size());
-
- for (TupleExpr s : normalize) {
- // System.out.println(s);
- Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
- }
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext on the large query q9
- * with with a smaller, potential index q10 to see if the
- * correct number of outputs are produced.
- */
- @Test
- public void testEqLargeEx() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q9, null);
- ParsedQuery pq2 = parser2.parseQuery(q10, null);
-
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertEquals(4, normalize.size());
-
- for (TupleExpr s : normalize) {
- List<TupleExpr> testList = QueryVariableNormalizer.getNormalizedIndex(pq2.getTupleExpr(), s);
- Assert.assertEquals(1, testList.size());
- for (TupleExpr t : testList) {
- Assert.assertTrue(t.equals(pq2.getTupleExpr()));
- }
- }
-
- SPARQLParser parser3 = new SPARQLParser();
- ParsedQuery pq3 = parser3.parseQuery(q7, null);
- List<TupleExpr> normalize2 = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq3.getTupleExpr());
-
- Assert.assertEquals(12, normalize2.size());
- for (TupleExpr s : normalize2) {
- Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), s));
- }
-
- }
-
- /**
- * @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()));
- }
- }
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext to see if it recognizes
- * that no substitution exists for two small, similar queries q3
- * and q4 that are structurally different
- */
- @Test
- public void testNeq1() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q3, null);
- ParsedQuery pq2 = parser2.parseQuery(q4, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 0);
-
- }
-
- /**
- * @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);
-
- }
-
- /**
- * @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);
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext on the large query q11
- * and q6, which have many similar nodes, to see if the correct
- * number of outputs are produced.
- */
- @Test
- public void testLargeNeq() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q11, null);
- ParsedQuery pq2 = parser2.parseQuery(q6, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 33);
- for (TupleExpr s : normalize) {
- Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), s));
- }
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext with two queries whose
- * StatementPattern nodes contain no constant Vars.
- */
- @Test
- public void testNoConstants() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q15, null);
- ParsedQuery pq2 = parser2.parseQuery(q16, 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));
- }
-
- pq1 = parser1.parseQuery(q16, null);
- pq2 = parser2.parseQuery(q17, null);
- normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 0);
-
- }
-
- /**
- * @throws Exception
- * Tests QueryVariableNormalizerContext with same query passed
- * in as query and index. Tests that only one index is produced
- * and that it equals original query.
- */
- @Test
- public void testSameTuples() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q11, null);
- ParsedQuery pq2 = parser2.parseQuery(q11, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 1);
- Assert.assertTrue(normalize.get(0).equals(pq1.getTupleExpr()) && normalize.get(0).equals(pq2.getTupleExpr()));
-
- }
-
-
-
- /**
- * @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));
- }
-
- }
-
- @Test
- public void testSimpleVarGraph() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q22, null);
- ParsedQuery pq2 = parser2.parseQuery(q23, 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()));
- }
-
- }
-
- @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()));
- }
-
- }
-
- @Test
- public void tesVarConstantGraph() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q19, null);
- ParsedQuery pq2 = parser2.parseQuery(q20, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 0);
-
- }
-
- @Test
- public void testConstantGraph() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q20, null);
- ParsedQuery pq2 = parser2.parseQuery(q21, 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()));
- }
-
- }
-
-
- @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));
- }
-
- }
-
-
- @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);
-
- }
-
-
- @Test
- public void tesLargeVarGraph() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q26, null);
- ParsedQuery pq2 = parser2.parseQuery(q27, null);
-
- List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
- pq2.getTupleExpr());
-
- Assert.assertTrue(normalize.size() == 33);
- for (TupleExpr s : normalize) {
- Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(),s));
- }
-
-
- }
-
-
- @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));
- }
-
-
- }
-
-
-
- @Test
- public void testFilters2() throws Exception {
-
- SPARQLParser parser1 = new SPARQLParser();
- SPARQLParser parser2 = new SPARQLParser();
-
- ParsedQuery pq1 = parser1.parseQuery(q32, null);
- ParsedQuery pq2 = parser2.parseQuery(q34, 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));
- }
-
-
- }
-
-
-
- @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));
- }
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-}