@Override public Object visit(ASTMinusGraphPattern node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; TupleExpr leftArg = graphPattern.buildTupleExpr(); graphPattern = new GraphPattern(parentGP); node.jjtGetChild(0).jjtAccept(this, null); TupleExpr rightArg = graphPattern.buildTupleExpr(); parentGP = new GraphPattern(); parentGP.addRequiredTE(new Difference(leftArg, rightArg)); graphPattern = parentGP; return null; }
@Override public Object visit(ASTUnionGraphPattern node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP); node.jjtGetChild(0).jjtAccept(this, null); TupleExpr leftArg = graphPattern.buildTupleExpr(); graphPattern = new GraphPattern(parentGP); node.jjtGetChild(1).jjtAccept(this, null); TupleExpr rightArg = graphPattern.buildTupleExpr(); parentGP.addRequiredTE(new Union(leftArg, rightArg)); graphPattern = parentGP; return null; }
@Override public Object visit(ASTOptionalGraphPattern node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP); super.visit(node, null); // remove filter conditions from graph pattern for inclusion as // conditions // in the OptionalTE List<ValueExpr> optionalConstraints = graphPattern.removeAllConstraints(); TupleExpr optional = graphPattern.buildTupleExpr(); graphPattern = parentGP; graphPattern.addOptionalTE(optional, optionalConstraints); return null; }
@Override public Exists visit(ASTExistsFunc node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP); Exists e = new Exists(); node.jjtGetChild(0).jjtAccept(this, e); TupleExpr te = graphPattern.buildTupleExpr(); e.setSubQuery(te); graphPattern = parentGP; return e; }
@Override public Object visit(ASTGraphPatternGroup node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP); boolean optionalPatternInGroup = false; for (int i = 0; i < node.jjtGetNumChildren(); i++) { if (optionalPatternInGroup) { // building the LeftJoin and resetting the graphPattern. TupleExpr te = graphPattern.buildTupleExpr(); graphPattern = new GraphPattern(parentGP); graphPattern.addRequiredTE(te); optionalPatternInGroup = false; } Node childNode = node.jjtGetChild(i); data = childNode.jjtAccept(this, data); if (childNode instanceof ASTOptionalGraphPattern) { optionalPatternInGroup = true; } } // Filters are scoped to the graph pattern group and do not affect // bindings external to the group TupleExpr te = graphPattern.buildTupleExpr(); parentGP.addRequiredTE(te); graphPattern = parentGP; return te; }
@Override public Not visit(ASTNotExistsFunc node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP); Exists e = new Exists(); node.jjtGetChild(0).jjtAccept(this, e); TupleExpr te = graphPattern.buildTupleExpr(); e.setSubQuery(te); graphPattern = parentGP; return new Not(e); }
@Override public TupleExpr visit(ASTInsertClause node, Object data) throws VisitorException { TupleExpr result = (TupleExpr)data; // Collect insert clause triples GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(); // inherit scope & context graphPattern.setStatementPatternScope(parentGP.getStatementPatternScope()); graphPattern.setContextVar(parentGP.getContextVar()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { node.jjtGetChild(i).jjtAccept(this, data); } TupleExpr insertExpr = graphPattern.buildTupleExpr(); graphPattern = parentGP; return insertExpr; }
Union currentUnion = union; for (int i = 0; i < altCount - 1; i++) { graphPattern = new GraphPattern(parentGP); pathAltNode.jjtGetChild(i).jjtAccept(this, data); TupleExpr arg = graphPattern.buildTupleExpr(); currentUnion.setLeftArg(arg); if (i == altCount - 2) { // second-to-last item graphPattern = new GraphPattern(parentGP); pathAltNode.jjtGetChild(i + 1).jjtAccept(this, data); arg = graphPattern.buildTupleExpr();
@Override public TupleExpr visit(ASTQuadsNotTriples node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(); ValueExpr contextNode = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, data); Var contextVar = mapValueExprToVar(contextNode); graphPattern.setContextVar(contextVar); graphPattern.setStatementPatternScope(Scope.NAMED_CONTEXTS); for (int i = 1; i < node.jjtGetNumChildren(); i++) { node.jjtGetChild(i).jjtAccept(this, data); } TupleExpr result = graphPattern.buildTupleExpr(); parentGP.addRequiredTE(result); graphPattern = parentGP; return result; }
graphPattern = new GraphPattern(); super.visit(node, null); TupleExpr constructExpr = graphPattern.buildTupleExpr();
@Override public Object visit(ASTServiceGraphPattern node, Object data) throws VisitorException { GraphPattern parentGP = graphPattern; ValueExpr serviceRef = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); graphPattern = new GraphPattern(parentGP); node.jjtGetChild(1).jjtAccept(this, null); TupleExpr serviceExpr = graphPattern.buildTupleExpr(); if (serviceExpr instanceof SingletonSet) return null; // do not add an empty service block String serviceExpressionString = node.getPatternString(); parentGP.addRequiredTE(new Service(mapValueExprToVar(serviceRef), serviceExpr, serviceExpressionString, node.getPrefixDeclarations(), node.getBaseURI(), node.isSilent())); graphPattern = parentGP; return null; }
GraphPattern gp = new GraphPattern(); gp.setContextVar(contextVar); gp.setStatementPatternScope(scope); GraphPattern gp = new GraphPattern(); gp.setContextVar(contextVar); gp.setStatementPatternScope(scope);
GraphPattern replacementGP = new GraphPattern(graphPattern); replacementGP.addRequiredTE(result);
@Override public TupleExpr visit(ASTDeleteClause node, Object data) throws VisitorException { TupleExpr result = (TupleExpr)data; // Collect construct triples GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(); // inherit scope & context graphPattern.setStatementPatternScope(parentGP.getStatementPatternScope()); graphPattern.setContextVar(parentGP.getContextVar()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { node.jjtGetChild(i).jjtAccept(this, data); } TupleExpr deleteExpr = graphPattern.buildTupleExpr(); // FIXME we should adapt the grammar so we can avoid doing this in // post-processing. VarCollector collector = new VarCollector(); deleteExpr.visit(collector); for (Var var : collector.getCollectedVars()) { if (var.isAnonymous() && !var.hasValue()) { // blank node in delete pattern, not allowed by SPARQL spec. throw new VisitorException("DELETE clause may not contain blank nodes"); } } graphPattern = parentGP; return deleteExpr; }
@Override public Modify visit(ASTDeleteWhere node, Object data) throws VisitorException { // Collect delete clause triples GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(); // inherit scope & context graphPattern.setStatementPatternScope(parentGP.getStatementPatternScope()); graphPattern.setContextVar(parentGP.getContextVar()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { node.jjtGetChild(i).jjtAccept(this, data); } TupleExpr whereExpr = graphPattern.buildTupleExpr(); graphPattern = parentGP; TupleExpr deleteExpr = whereExpr.clone(); // FIXME we should adapt the grammar so we can avoid doing this // post-processing. VarCollector collector = new VarCollector(); deleteExpr.visit(collector); for (Var var : collector.getCollectedVars()) { if (var.isAnonymous() && !var.hasValue()) { throw new VisitorException("DELETE WHERE may not contain blank nodes"); } } Modify modify = new Modify(deleteExpr, null, whereExpr); return modify; }
throws VisitorException graphPattern = new GraphPattern();
GraphPattern pathSequencePattern = new GraphPattern(graphPattern); GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(parentGP);
graphPattern = new GraphPattern(); node.getWhereClause().jjtAccept(this, null); tupleExpr = graphPattern.buildTupleExpr();
graphPattern = new GraphPattern(parentGP); node.getWhereClause().jjtAccept(this, null); TupleExpr tupleExpr = graphPattern.buildTupleExpr();
graphPattern = new GraphPattern(); node.getWhereClause().jjtAccept(this, null); TupleExpr tupleExpr = graphPattern.buildTupleExpr();