Search in sources :

Example 21 with Var

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;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) Filter(org.eclipse.rdf4j.query.algebra.Filter) Var(org.eclipse.rdf4j.query.algebra.Var) And(org.eclipse.rdf4j.query.algebra.And) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Join(org.eclipse.rdf4j.query.algebra.Join) Compare(org.eclipse.rdf4j.query.algebra.Compare) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Union(org.eclipse.rdf4j.query.algebra.Union)

Example 22 with Var

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;
}
Also used : Var(org.eclipse.rdf4j.query.algebra.Var)

Example 23 with 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;
}
Also used : Var(org.eclipse.rdf4j.query.algebra.Var)

Example 24 with 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;
}
Also used : Var(org.eclipse.rdf4j.query.algebra.Var)

Example 25 with Var

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) Var(org.eclipse.rdf4j.query.algebra.Var)

Aggregations

Var (org.eclipse.rdf4j.query.algebra.Var)48 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)19 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)15 ArrayList (java.util.ArrayList)14 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)14 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)13 Extension (org.eclipse.rdf4j.query.algebra.Extension)10 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)10 ASTVar (org.eclipse.rdf4j.query.parser.serql.ast.ASTVar)8 List (java.util.List)7 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)7 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)7 LinkedHashSet (java.util.LinkedHashSet)6 Projection (org.eclipse.rdf4j.query.algebra.Projection)6 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)5 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)5 SameTerm (org.eclipse.rdf4j.query.algebra.SameTerm)5 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)4 Filter (org.eclipse.rdf4j.query.algebra.Filter)4 BindingSet (org.eclipse.rdf4j.query.BindingSet)3