use of org.eclipse.rdf4j.query.algebra.Var in project rdf4j by eclipse.
the class TupleExprBuilder method createTupleExprForNegatedPropertySet.
private TupleExpr createTupleExprForNegatedPropertySet(NegatedPropertySet nps, int index) {
Var subjVar = nps.getSubjectVar();
Var predVar = createAnonVar();
ValueExpr filterCondition = null;
ValueExpr filterConditionInverse = null;
// build (inverted) filter conditions for each negated path element.
for (PropertySetElem elem : nps.getPropertySetElems()) {
ValueConstant predicate = elem.getPredicate();
if (elem.isInverse()) {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterConditionInverse == null) {
filterConditionInverse = compare;
} else {
filterConditionInverse = new And(compare, filterConditionInverse);
}
} else {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterCondition == null) {
filterCondition = compare;
} else {
filterCondition = new And(compare, filterCondition);
}
}
}
TupleExpr patternMatch = null;
// one item)
if (filterCondition != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatch == null) {
patternMatch = new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar());
} else {
patternMatch = new Join(new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar()), patternMatch);
}
}
}
TupleExpr patternMatchInverse = null;
// one item):
if (filterConditionInverse != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatchInverse == null) {
patternMatchInverse = new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar());
} else {
patternMatchInverse = new Join(new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar()), patternMatchInverse);
}
}
}
TupleExpr completeMatch = null;
if (patternMatch != null) {
completeMatch = new Filter(patternMatch, filterCondition);
}
if (patternMatchInverse != null) {
if (completeMatch == null) {
completeMatch = new Filter(patternMatchInverse, filterConditionInverse);
} else {
completeMatch = new Union(new Filter(patternMatchInverse, filterConditionInverse), completeMatch);
}
}
return completeMatch;
}
use of org.eclipse.rdf4j.query.algebra.Var in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Var visit(ASTVar node, Object data) throws VisitorException {
Var var = new Var(node.getName());
var.setAnonymous(node.isAnonymous());
return var;
}
use of org.eclipse.rdf4j.query.algebra.Var in project rdf4j by eclipse.
the class TupleExprBuilder method createAnonVar.
/**
* Creates an anonymous Var with a unique, randomly generated, variable name.
*
* @return an anonymous Var with a unique, randomly generated, variable name
*/
private Var createAnonVar() {
// dashes ('-') in the generated UUID are replaced with underscores so
// the
// varname
// remains compatible with the SPARQL grammar. See SES-2310.
final Var var = new Var("_anon_" + UUID.randomUUID().toString().replaceAll("-", "_"));
var.setAnonymous(true);
return var;
}
use of org.eclipse.rdf4j.query.algebra.Var in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Var visit(ASTBlankNodePropertyList node, Object data) throws VisitorException {
Var bnodeVar = createAnonVar();
super.visit(node, bnodeVar);
return bnodeVar;
}
use of org.eclipse.rdf4j.query.algebra.Var in project rdf4j by eclipse.
the class ConstructorBuilder method getConstructVars.
/**
* Gets the set of variables that are relevant for the constructor. This method accumulates all subject,
* predicate and object variables from the supplied statement patterns, but ignores any context variables.
*/
private Set<Var> getConstructVars(Collection<StatementPattern> statementPatterns) {
Set<Var> vars = new LinkedHashSet<Var>(statementPatterns.size() * 2);
for (StatementPattern sp : statementPatterns) {
vars.add(sp.getSubjectVar());
vars.add(sp.getPredicateVar());
vars.add(sp.getObjectVar());
}
return vars;
}
Aggregations