TupleExprBuilder extends AbstractASTVisitor { @Override public TupleExpr visit(ASTQueryContainer node, Object data) throws VisitorException { return (TupleExpr) node.getQuery().jjtAccept(this, null); } TupleExprBuilder(ValueFactory valueFactory); @Override TupleExpr visit(ASTQueryContainer node, Object data); @Override TupleExpr visit(ASTSelectQuery node, Object data); @Override TupleExpr visit(ASTSelect node, Object data); @Override TupleExpr visit(ASTConstructQuery node, Object data); @Override TupleExpr visit(ASTConstruct node, Object data); @Override TupleExpr visit(ASTDescribeQuery node, Object data); @Override TupleExpr visit(ASTDescribe node, Object data); @Override TupleExpr visit(ASTAskQuery node, Object data); @Override Group visit(ASTGroupClause node, Object data); @Override String visit(ASTGroupCondition node, Object data); @Override List<OrderElem> visit(ASTOrderClause node, Object data); @Override OrderElem visit(ASTOrderCondition node, Object data); @Override Long visit(ASTLimit node, Object data); @Override Long visit(ASTOffset node, Object data); @Override Object visit(ASTGraphPatternGroup node, Object data); @Override Object visit(ASTServiceGraphPattern node, Object data); @Override Object visit(ASTOptionalGraphPattern node, Object data); @Override Object visit(ASTGraphGraphPattern node, Object data); @Override Object visit(ASTUnionGraphPattern node, Object data); @Override Object visit(ASTMinusGraphPattern node, Object data); @Override Object visit(ASTPropertyList propListNode, Object data); @Override Object visit(ASTPathAlternative pathAltNode, Object data); @Override PropertySetElem visit(ASTPathOneInPropertySet node, Object data); @Override Object visit(ASTPathSequence pathSeqNode, Object data); @Override Object visit(ASTPropertyListPath propListNode, Object data); @Override List<ValueExpr> visit(ASTObjectList node, Object data); @Override Var visit(ASTBlankNodePropertyList node, Object data); @Override Var visit(ASTCollection node, Object data); @Override Object visit(ASTConstraint node, Object data); @Override Or visit(ASTOr node, Object data); @Override Object visit(ASTAnd node, Object data); @Override Not visit(ASTNot node, Object data); @Override Coalesce visit(ASTCoalesce node, Object data); @Override Compare visit(ASTCompare node, Object data); @Override FunctionCall visit(ASTSubstr node, Object data); @Override FunctionCall visit(ASTConcat node, Object data); @Override FunctionCall visit(ASTAbs node, Object data); @Override FunctionCall visit(ASTCeil node, Object data); @Override FunctionCall visit(ASTContains node, Object data); @Override FunctionCall visit(ASTFloor node, Object data); @Override FunctionCall visit(ASTRound node, Object data); @Override FunctionCall visit(ASTRand node, Object data); @Override SameTerm visit(ASTSameTerm node, Object data); @Override Sample visit(ASTSample node, Object data); @Override MathExpr visit(ASTMath node, Object data); @Override Object visit(ASTFunctionCall node, Object data); @Override FunctionCall visit(ASTEncodeForURI node, Object data); @Override Object visit(ASTStr node, Object data); @Override FunctionCall visit(ASTStrDt node, Object data); @Override FunctionCall visit(ASTStrStarts node, Object data); @Override FunctionCall visit(ASTStrEnds node, Object data); @Override FunctionCall visit(ASTStrLen node, Object data); @Override FunctionCall visit(ASTStrAfter node, Object data); @Override FunctionCall visit(ASTStrBefore node, Object data); @Override FunctionCall visit(ASTUpperCase node, Object data); @Override FunctionCall visit(ASTLowerCase node, Object data); @Override FunctionCall visit(ASTStrLang node, Object data); @Override FunctionCall visit(ASTNow node, Object data); @Override FunctionCall visit(ASTYear node, Object data); @Override FunctionCall visit(ASTMonth node, Object data); @Override FunctionCall visit(ASTDay node, Object data); @Override FunctionCall visit(ASTHours node, Object data); @Override FunctionCall visit(ASTMinutes node, Object data); @Override FunctionCall visit(ASTSeconds node, Object data); @Override FunctionCall visit(ASTTimezone node, Object data); @Override FunctionCall visit(ASTTz node, Object data); @Override FunctionCall visit(ASTMD5 node, Object data); @Override FunctionCall visit(ASTSHA1 node, Object data); @Override FunctionCall visit(ASTSHA224 node, Object data); @Override FunctionCall visit(ASTSHA256 node, Object data); @Override FunctionCall visit(ASTSHA384 node, Object data); @Override FunctionCall visit(ASTSHA512 node, Object data); @Override FunctionCall visit(ASTUUID node, Object data); @Override FunctionCall visit(ASTSTRUUID node, Object data); @Override IRIFunction visit(ASTIRIFunc node, Object data); @Override Lang visit(ASTLang node, Object data); @Override Datatype visit(ASTDatatype node, Object data); @Override Object visit(ASTLangMatches node, Object data); @Override BindingSetAssignment visit(ASTInlineData node, Object data); @Override BindingSetAssignment visit(ASTBindingsClause node, Object data); @Override BindingSet visit(ASTBindingSet node, Object data); @Override ValueExpr visit(ASTBindingValue node, Object data); @Override ValueExpr visit(ASTBound node, Object data); @Override IsURI visit(ASTIsIRI node, Object data); @Override IsBNode visit(ASTIsBlank node, Object data); @Override IsLiteral visit(ASTIsLiteral node, Object data); @Override IsNumeric visit(ASTIsNumeric node, Object data); @Override Object visit(ASTBNodeFunc node, Object data); @Override Object visit(ASTRegexExpression node, Object data); @Override FunctionCall visit(ASTReplace node, Object data); @Override Exists visit(ASTExistsFunc node, Object data); @Override Not visit(ASTNotExistsFunc node, Object data); @Override If visit(ASTIf node, Object data); @Override ValueExpr visit(ASTInfix node, Object data); @Override ValueExpr visit(ASTIn node, Object data); @Override ValueExpr visit(ASTNotIn node, Object data); @Override Var visit(ASTVar node, Object data); @Override ValueConstant visit(ASTIRI node, Object data); @Override Object visit(ASTQName node, Object data); @Override Object visit(ASTBind node, Object data); @Override Object visit(ASTBlankNode node, Object data); @Override ValueConstant visit(ASTRDFLiteral node, Object data); @Override ValueConstant visit(ASTNumericLiteral node, Object data); @Override ValueConstant visit(ASTTrue node, Object data); @Override ValueConstant visit(ASTFalse node, Object data); @Override String visit(ASTString node, Object data); @Override Object visit(ASTCount node, Object data); @Override Object visit(ASTGroupConcat node, Object data); @Override Object visit(ASTMax node, Object data); @Override Object visit(ASTMin node, Object data); @Override Object visit(ASTSum node, Object data); @Override Object visit(ASTAvg node, Object data); @Override TupleExpr visit(ASTTripleRef node, Object data); @Override ValueConstant visit(ASTConstTripleRef node, Object data);  }
@Test public void testAskQuerySolutionModifiers() { String query = "ASK WHERE { ?foo ?bar ?baz . } ORDER BY ?foo LIMIT 1"; try { TupleExprBuilder builder = new TupleExprBuilder(ValueFactoryImpl.getInstance()); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(query); TupleExpr result = builder.visit(qc, null); assertTrue(result instanceof Order); } catch (Exception e) { e.printStackTrace(); fail("should parse ask query with solution modifiers"); } }
@Test public void testNegatedPathWithFixedObject() { String query = "ASK WHERE { ?s !<http: try { TupleExprBuilder builder = new TupleExprBuilder(SimpleValueFactory.getInstance()); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(query); TupleExpr result = builder.visit(qc, null); assertTrue(result instanceof Slice); } catch (Exception e) { e.printStackTrace(); fail("should parse ask query with negated property path"); } }
@Test public void testServiceGraphPatternStringDetection1() throws TokenMgrError, ParseException, VisitorException { String servicePattern = "SERVICE <foo:bar> { ?x <foo:baz> ?y }"; StringBuilder qb = new StringBuilder(); qb.append("SELECT * \n"); qb.append("WHERE { \n"); qb.append(" { ?s ?p ?o } \n"); qb.append(" UNION \n"); qb.append(" { ?p ?q ?r } \n"); qb.append(servicePattern); qb.append("\n"); qb.append(" FILTER (?s = <foo:bar>) "); qb.append(" } "); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(qb.toString()); ServiceNodeFinder f = new ServiceNodeFinder(); f.visit(qc, null); assertTrue(f.getGraphPatterns().size() == 1); assertTrue(servicePattern.equals(f.getGraphPatterns().get(0))); }
@Test public void testServiceGraphPatternStringDetection2() throws TokenMgrError, ParseException, VisitorException { String servicePattern = "SERVICE <foo:bar> \r\n { ?x <foo:baz> ?y. \r\n \r\n }"; StringBuilder qb = new StringBuilder(); qb.append("SELECT * \n"); qb.append("WHERE { \n"); qb.append(" { ?s ?p ?o } \n"); qb.append(" UNION \n"); qb.append(" { ?p ?q ?r } \n"); qb.append(servicePattern); qb.append("\n"); qb.append(" FILTER (?s = <foo:bar>) "); qb.append(" } "); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(qb.toString()); ServiceNodeFinder f = new ServiceNodeFinder(); f.visit(qc, null); assertTrue(f.getGraphPatterns().size() == 1); assertTrue(servicePattern.equals(f.getGraphPatterns().get(0))); }
@Test public void testServiceGraphPatternStringDetection3() throws TokenMgrError, ParseException, VisitorException { String servicePattern1 = "SERVICE <foo:bar> \n { ?x <foo:baz> ?y. }"; String servicePattern2 = "SERVICE <foo:bar2> \n { ?x <foo:baz> ?y. }"; StringBuilder qb = new StringBuilder(); qb.append("SELECT * \n"); qb.append("WHERE { \n"); qb.append(servicePattern1); qb.append(" OPTIONAL { \n"); qb.append(servicePattern2); qb.append(" } \n"); qb.append(" } "); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(qb.toString()); ServiceNodeFinder f = new ServiceNodeFinder(); f.visit(qc, null); assertTrue(f.getGraphPatterns().size() == 2); assertTrue(servicePattern1.equals(f.getGraphPatterns().get(0))); assertTrue(servicePattern2.equals(f.getGraphPatterns().get(1))); }
@Test public void testServiceGraphPatternStringDetection4() throws TokenMgrError, ParseException, VisitorException { String servicePattern1 = "SERVICE <http: + "OPTIONAL { SERVICE SILENT <http: String servicePattern2 = "SERVICE SILENT <http: StringBuilder qb = new StringBuilder(); qb.append("SELECT * \n"); qb.append("WHERE { \n"); qb.append(servicePattern1); qb.append(" } "); ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(qb.toString()); ServiceNodeFinder f = new ServiceNodeFinder(); f.visit(qc, null); assertTrue(f.getGraphPatterns().size() == 2); assertTrue(servicePattern1.equals(f.getGraphPatterns().get(0))); assertTrue(servicePattern2.equals(f.getGraphPatterns().get(1))); }