ContentRemovalProcessor { public static void process(ASTQueryContainer ast) throws VisitorException { final ContentRemovalVisitor c = new ContentRemovalVisitor(); c.visit(ast, null); } private  ContentRemovalProcessor(); static void process(ASTQueryContainer ast);  }
@Test public void testObjectRemoval() throws Exception { final String q = "SELECT * { ?s ?p \"test\". ?s a <Person>. ?s ?p True. ?s ?p False }"; ast = SyntaxTreeBuilder.parseQuery(q); ContentRemovalProcessor.process(ast); final String[] vars = SparqlVarGenerator.getCurrentVarNames(); assertEquals(3, vars.length); final String expectedAst = "QueryContainer\n" + " SelectQuery\n" + " Select ( * )\n" + " WhereClause\n" + " GraphPatternGroup\n" + " BasicGraphPattern\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (" + vars[0] + ")\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (http: " ObjectList\n" + " IRI (Person)\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (" + vars[1] + ")\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (" + vars[2] + ")"; assertEquals(expectedAst, ast.dump("")); }
@Test public void testSubjectAndIRIRemoval() throws Exception { final String q = "SELECT * { ?s <name> <test>. ?s <label> <test>. <moi> a <Person>. <moi> ?p <Person> }"; final String expectedAst = "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 (name)\n" + " ObjectList\n" + " Var (IRIn1010444415016862037)\n" + " TriplesSameSubjectPath\n" + " Var (s)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (label)\n" + " ObjectList\n" + " Var (IRIn1010444415016862037)\n" + " TriplesSameSubjectPath\n" + " Var (IRIn8119792335708867021)\n" + " PropertyListPath\n" + " PathAlternative\n" + " PathSequence\n" + " PathElt\n" + " IRI (http: " ObjectList\n" + " IRI (Person)\n" + " TriplesSameSubjectPath\n" + " Var (IRIn8119792335708867021)\n" + " PropertyListPath\n" + " Var (p)\n" + " ObjectList\n" + " Var (IRI4869599639157439053)"; ast = SyntaxTreeBuilder.parseQuery(q); ContentRemovalProcessor.process(ast); assertEquals(expectedAst, ast.dump("")); }