Search in sources :

Example 6 with StatementPattern

use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.

the class BaseTupleExprRenderer method toStatementPattern.

/**
 * Turn a ProjectionElemList for a construct query projection (three elements aliased as 'subject',
 * 'predicate' and 'object' in that order) into a StatementPattern.
 *
 * @param theList
 *        the elem list to render
 * @return the elem list for a construct projection as a statement pattern
 * @throws Exception
 *         if there is an exception while rendering
 */
public StatementPattern toStatementPattern(ProjectionElemList theList) throws Exception {
    ProjectionElem aSubj = theList.getElements().get(0);
    ProjectionElem aPred = theList.getElements().get(1);
    ProjectionElem aObj = theList.getElements().get(2);
    return new StatementPattern(mExtensions.containsKey(aSubj.getSourceName()) ? new Var(scrubVarName(aSubj.getSourceName()), asValue(mExtensions.get(aSubj.getSourceName()))) : new Var(scrubVarName(aSubj.getSourceName())), mExtensions.containsKey(aPred.getSourceName()) ? new Var(scrubVarName(aPred.getSourceName()), asValue(mExtensions.get(aPred.getSourceName()))) : new Var(scrubVarName(aPred.getSourceName())), mExtensions.containsKey(aObj.getSourceName()) ? new Var(scrubVarName(aObj.getSourceName()), asValue(mExtensions.get(aObj.getSourceName()))) : new Var(scrubVarName(aObj.getSourceName())));
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) Var(org.eclipse.rdf4j.query.algebra.Var) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem)

Example 7 with StatementPattern

use of org.eclipse.rdf4j.query.algebra.StatementPattern 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)

Example 8 with StatementPattern

use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.

the class AbstractQueryBuilder method multiProjection.

private UnaryTupleOperator multiProjection() {
    MultiProjection aProjection = new MultiProjection();
    Extension aExt = null;
    for (StatementPattern aPattern : mProjectionPatterns) {
        ProjectionElemList aList = new ProjectionElemList();
        aList.addElement(new ProjectionElem(aPattern.getSubjectVar().getName(), "subject"));
        aList.addElement(new ProjectionElem(aPattern.getPredicateVar().getName(), "predicate"));
        aList.addElement(new ProjectionElem(aPattern.getObjectVar().getName(), "object"));
        if (aPattern.getSubjectVar().hasValue()) {
            if (aExt == null) {
                aExt = new Extension();
            }
            aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getSubjectVar().getValue()), aPattern.getSubjectVar().getName()));
        }
        if (aPattern.getPredicateVar().hasValue()) {
            if (aExt == null) {
                aExt = new Extension();
            }
            aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getPredicateVar().getValue()), aPattern.getPredicateVar().getName()));
        }
        if (aPattern.getObjectVar().hasValue()) {
            if (aExt == null) {
                aExt = new Extension();
            }
            aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getObjectVar().getValue()), aPattern.getObjectVar().getName()));
        }
        aProjection.addProjection(aList);
    }
    if (aExt != null) {
        aProjection.setArg(aExt);
    }
    return aProjection;
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) MultiProjection(org.eclipse.rdf4j.query.algebra.MultiProjection) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem)

Example 9 with StatementPattern

use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.

the class GroupBuilder method atoms.

public GroupBuilder<T, E> atoms(Set<StatementPattern> thePatterns) {
    for (StatementPattern aPattern : thePatterns) {
        aPattern.setContextVar(mContext);
        aPattern.setScope(mScope);
    }
    mGroup.addAll(thePatterns);
    return this;
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern)

Example 10 with StatementPattern

use of org.eclipse.rdf4j.query.algebra.StatementPattern 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)

Aggregations

StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)19 Var (org.eclipse.rdf4j.query.algebra.Var)14 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)9 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)6 ArrayList (java.util.ArrayList)5 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)5 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)5 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)5 LinkedHashSet (java.util.LinkedHashSet)4 Extension (org.eclipse.rdf4j.query.algebra.Extension)4 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)4 Join (org.eclipse.rdf4j.query.algebra.Join)4 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)4 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)3 EmptySet (org.eclipse.rdf4j.query.algebra.EmptySet)3 Projection (org.eclipse.rdf4j.query.algebra.Projection)3 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)3 SameTerm (org.eclipse.rdf4j.query.algebra.SameTerm)3 Slice (org.eclipse.rdf4j.query.algebra.Slice)3 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)3