RecommendationScopeProcessor { public static void process(ASTQueryContainer ast) throws VisitorException { final ScopedVariables scopedVariables = new ScopedVariables(); final POFConnected scope = new POFConnected(); scopedVariables.newConnectedVars.add(Hash.get(SyntaxTreeBuilder.PointOfFocus)); do { scopedVariables.updateVars(); scope.visit(ast, scopedVariables); } while (!scopedVariables.newConnectedVars.isEmpty()); pruneToScope(ast); } private  RecommendationScopeProcessor(); static void process(ASTQueryContainer ast);  }
@Test public void testSimpleBGP() throws Exception { final String q = "SELECT * { ?s ?POF ?o . ?o a ?Person }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = ast.dump(""); RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testDisjointBGPs() throws Exception { final String q = "SELECT * { ?s ?POF ?o . ?s2 a ?Person }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " Var (POF)\n" + " ObjectList\n" + " Var (o)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testDisjointGGPs() throws Exception { final String q = "SELECT * { ?s ?POF ?o . { SELECT * { ?s2 a ?Person } } }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " Var (POF)\n" + " ObjectList\n" + " Var (o)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testDisjointGGPs2() throws Exception { final String q = "SELECT * { ?s <knows> ?o . { SELECT * { ?o ?p ?o2. ?s2 a ?Person OPTIONAL {?s a ?POF} } } }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (knows)\n" + " ObjectList\n" + " Var (o)\n" + " GraphPatternGroup\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (o)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (o2)\n" + " OptionalGraphPattern\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (http: " ObjectList\n" + " Var (POF)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testRemovePrecedingBGP() throws Exception { final String query = "PREFIX rdf: <http: "SELECT * WHERE {\n" + " ?movie a <http: " <http: " ?n a ?POF " + "}LIMIT 10\n"; final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (n)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (http: " ObjectList\n" + " Var (POF)"; ast = SyntaxTreeBuilder.parseQuery(query); RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testDisjointGGPs3() throws Exception { final String q = "SELECT * { ?s1 <knows> ?o1 . { SELECT * { ?o ?p ?o2. ?s2 a ?Person OPTIONAL {?s a ?POF} } } }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " GraphPatternGroup\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " OptionalGraphPattern\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (http: " ObjectList\n" + " Var (POF)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testGraphGraphPattern() throws Exception { final String q = "SELECT * { ?s1 <knows> ?o1 . GRAPH ?POF { ?o ?p ?s } ?a ?b ?p }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " GraphGraphPattern\n" + " Var (POF)\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (o)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (s)\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (a)\n" + " PropertyListPath\n" + " Var (b)\n" + " ObjectList\n" + " Var (p)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }
@Test public void testGraphGraphPattern2() throws Exception { final String q = "SELECT * { ?s1 ?POF ?g . GRAPH ?g { ?o ?p ?s. } ?a ?b ?c }"; ast = SyntaxTreeBuilder.parseQuery(q); final String expected = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s1)\n" + " PropertyListPath\n" + " Var (POF)\n" + " ObjectList\n" + " Var (g)\n" + " GraphGraphPattern\n" + " Var (g)\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (o)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (s)"; RecommendationScopeProcessor.process(ast); assertEquals(expected, ast.dump("")); }