private TupleExpr replaceVarOccurrence(TupleExpr te, List<ValueExpr> objectList, Var replacementVar) throws VisitorException { for (ValueExpr objExpr : objectList) { Var objVar = mapValueExprToVar(objExpr); VarReplacer replacer = new VarReplacer(objVar, replacementVar); te.visit(replacer); } return te; }
@Override public Object visit(ASTPropertyListPath propListNode, Object data) throws VisitorException { ValueExpr subject = (ValueExpr)data; ValueExpr verbPath = (ValueExpr)propListNode.getVerb().jjtAccept(this, data); if (verbPath instanceof Var) { @SuppressWarnings("unchecked") List<ValueExpr> objectList = (List<ValueExpr>)propListNode.getObjectList().jjtAccept(this, null); Var subjVar = mapValueExprToVar(subject); Var predVar = mapValueExprToVar(verbPath); for (ValueExpr object : objectList) { Var objVar = mapValueExprToVar(object); graphPattern.addRequiredSP(subjVar, predVar, objVar); } } else { // path is a single IRI or a more complex path. handled by the // visitor. } ASTPropertyListPath nextPropList = propListNode.getNextPropertyList(); if (nextPropList != null) { nextPropList.jjtAccept(this, subject); } return null; }
@Override public Object visit(ASTPropertyList propListNode, Object data) throws VisitorException { ValueExpr subject = (ValueExpr)data; ValueExpr predicate = (ValueExpr)propListNode.getVerb().jjtAccept(this, null); @SuppressWarnings("unchecked") List<ValueExpr> objectList = (List<ValueExpr>)propListNode.getObjectList().jjtAccept(this, null); Var subjVar = mapValueExprToVar(subject); Var predVar = mapValueExprToVar(predicate); for (ValueExpr object : objectList) { Var objVar = mapValueExprToVar(object); graphPattern.addRequiredSP(subjVar, predVar, objVar); } ASTPropertyList nextPropList = propListNode.getNextPropertyList(); if (nextPropList != null) { nextPropList.jjtAccept(this, subject); } return graphPattern.buildTupleExpr(); }
@Override public Object visit(ASTGraphGraphPattern node, Object data) throws VisitorException { Var oldContext = graphPattern.getContextVar(); Scope oldScope = graphPattern.getStatementPatternScope(); ValueExpr newContext = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); graphPattern.setContextVar(mapValueExprToVar(newContext)); graphPattern.setStatementPatternScope(Scope.NAMED_CONTEXTS); node.jjtGetChild(1).jjtAccept(this, null); graphPattern.setContextVar(oldContext); graphPattern.setStatementPatternScope(oldScope); return null; }
@Override public Var visit(ASTCollection node, Object data) throws VisitorException { Var rootListVar = createAnonVar(); Var listVar = rootListVar; int childCount = node.jjtGetNumChildren(); for (int i = 0; i < childCount; i++) { ValueExpr childValue = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null); Var childVar = mapValueExprToVar(childValue); graphPattern.addRequiredSP(listVar, TupleExprs.createConstVar(RDF.FIRST), childVar); Var nextListVar; if (i == childCount - 1) { nextListVar = TupleExprs.createConstVar(RDF.NIL); } else { nextListVar = createAnonVar(); } graphPattern.addRequiredSP(listVar, TupleExprs.createConstVar(RDF.REST), nextListVar); listVar = nextListVar; } return rootListVar; }
@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; }
Var subjVar = mapValueExprToVar(subject); if (i == pathLength - 1) { if (objectList.contains(subjVar)) { // See SES-1685 Var objVar = mapValueExprToVar(objectList.get(objectList.indexOf(subjVar))); objVarReplacement = new Var[] { objVar, createAnonVar() }; objectList.remove(objVar); Var objVar = mapValueExprToVar(object); te = handlePathModifiers(scope, subjVar, te, objVar, contextVar, lowerBound, upperBound); Var objVar = mapValueExprToVar(object); if (objVar.equals(subjVar)) { // see SES-1685 Var objVarReplacement = createAnonVar(); Var predVar = mapValueExprToVar(pred); Var objVar = mapValueExprToVar(object); boolean replaced = false; SameTerm condition = new SameTerm(objVar, mapValueExprToVar(object)); pathSequencePattern.addConstraint(condition); Var objVar = mapValueExprToVar(object); startVar = objVar;