Search in sources :

Example 6 with ValueConstant

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

the class TupleExprBuilder method visit.

@Override
public ValueConstant visit(ASTRDFLiteral node, Object data) throws VisitorException {
    String label = (String) node.getLabel().jjtAccept(this, null);
    String lang = node.getLang();
    ASTIRI datatypeNode = node.getDatatype();
    Literal literal;
    if (datatypeNode != null) {
        IRI datatype;
        try {
            datatype = valueFactory.createIRI(datatypeNode.getValue());
        } catch (IllegalArgumentException e) {
            // invalid URI
            throw new VisitorException(e.getMessage());
        }
        literal = valueFactory.createLiteral(label, datatype);
    } else if (lang != null) {
        literal = valueFactory.createLiteral(label, lang);
    } else {
        literal = valueFactory.createLiteral(label);
    }
    return new ValueConstant(literal);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IsLiteral(org.eclipse.rdf4j.query.algebra.IsLiteral) BooleanLiteral(org.eclipse.rdf4j.model.impl.BooleanLiteral) Literal(org.eclipse.rdf4j.model.Literal) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant)

Example 7 with ValueConstant

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

the class FilterBuilder method regex.

public GroupBuilder<T, E> regex(ValueExpr theExpr, String thePattern, String theFlags) {
    Regex aRegex = new Regex();
    aRegex.setArg(theExpr);
    aRegex.setPatternArg(new ValueConstant(SimpleValueFactory.getInstance().createLiteral(thePattern)));
    if (theFlags != null) {
        aRegex.setFlagsArg(new ValueConstant(SimpleValueFactory.getInstance().createLiteral(theFlags)));
    }
    return filter(aRegex);
}
Also used : Regex(org.eclipse.rdf4j.query.algebra.Regex) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant)

Example 8 with ValueConstant

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

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

the class GroupBuilder method filter.

public GroupBuilder<T, E> filter(String theVar, Compare.CompareOp theOp, Value theValue) {
    Compare aComp = new Compare(new Var(theVar), new ValueConstant(theValue), theOp);
    mGroup.addFilter(aComp);
    return this;
}
Also used : Var(org.eclipse.rdf4j.query.algebra.Var) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Example 10 with ValueConstant

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

ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)23 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)7 Var (org.eclipse.rdf4j.query.algebra.Var)7 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)6 IRI (org.eclipse.rdf4j.model.IRI)4 Compare (org.eclipse.rdf4j.query.algebra.Compare)4 Extension (org.eclipse.rdf4j.query.algebra.Extension)4 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)4 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)4 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)4 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)4 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)4 ArrayList (java.util.ArrayList)3 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 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)3 ASTGraphOrDefault (org.eclipse.rdf4j.query.parser.sparql.ast.ASTGraphOrDefault)3 HashMap (java.util.HashMap)2