Search in sources :

Example 1 with ValueExpr

use of org.openrdf.query.algebra.ValueExpr in project backstage by zepheira.

the class TupleQueryBuilder method makeFilterTupleExpr.

public TupleExpr makeFilterTupleExpr() {
    TupleExpr tupleExprs = joinTupleExpressions();
    ValueExpr conditions = joinConditions();
    return (conditions == null) ? tupleExprs : new Filter(tupleExprs, conditions);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Filter(org.openrdf.query.algebra.Filter) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 2 with ValueExpr

use of org.openrdf.query.algebra.ValueExpr in project backstage by zepheira.

the class Path method computeOutput.

@Override
public ExpressionResult computeOutput(Database database, TupleQueryBuilder builder, Map<String, ValueExpr> variableValues, Map<String, String> variableTypes) throws ExpressionException {
    String rootName = _rootVariable != null ? _rootVariable : "value";
    ValueExpr valueExpr = variableValues.get(rootName);
    String valueType = variableTypes.get(rootName);
    for (PathSegment segment : _segments) {
        if (valueExpr instanceof Var) {
            Var input = (Var) valueExpr;
            PropertyRecord record = database.getPropertyRecord(segment.propertyID);
            if (record == null) {
                throw new ExpressionException("No property can be aliased to '" + segment.propertyID + "'");
            }
            Var output = builder.makeVar("seg");
            Var propertyVar = builder.makeVar("seg", record.uri);
            if (segment.forward) {
                builder.addTupleExpr(new StatementPattern(input, propertyVar, output));
                valueType = record.valueType;
            } else {
                builder.addTupleExpr(new StatementPattern(output, propertyVar, input));
                valueType = "item";
            }
            valueExpr = output;
        } else {
            throw new ExpressionException("Non-final set in a path must be a variable.");
        }
    }
    return new ExpressionResult(valueExpr, valueType);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) StatementPattern(org.openrdf.query.algebra.StatementPattern) PropertyRecord(edu.mit.simile.backstage.model.data.Database.PropertyRecord) Var(org.openrdf.query.algebra.Var)

Example 3 with ValueExpr

use of org.openrdf.query.algebra.ValueExpr in project backstage by zepheira.

the class ListFacet method restrict.

@Override
public void restrict(TupleQueryBuilder builder, Var itemVar) throws ExpressionException {
    if (!hasRestrictions()) {
        return;
    }
    ExpressionResult result = _expression.computeOutputOnItem(_context.getDatabase(), builder, itemVar);
    if (!(result.valueExpr instanceof Var)) {
        throw new ExpressionException("Facet expression does not evaluate to a Var");
    }
    ValueExpr input = result.valueExpr;
    ValueExpr condition = null;
    if (_selectMissing) {
    // what do we do???
    }
    for (String v : _selection) {
        condition = createRestrictionClause(builder, v, result.valueType, input, condition);
    }
    builder.addCondition(condition);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) ExpressionResult(edu.mit.simile.backstage.model.data.ExpressionResult) Var(org.openrdf.query.algebra.Var) ExpressionException(edu.mit.simile.backstage.model.data.ExpressionException)

Example 4 with ValueExpr

use of org.openrdf.query.algebra.ValueExpr in project backstage by zepheira.

the class TupleQueryBuilder method getStringSerialization.

public String getStringSerialization() {
    StringBuffer sb = new StringBuffer();
    boolean first = true;
    for (TupleExpr tupleExpr : _tupleExprs) {
        if (first) {
            first = false;
        } else {
            sb.append(';');
        }
        sb.append(QueryModelTreePrinter.printTree(tupleExpr));
    }
    for (ValueExpr valueExpr : _conditions) {
        if (first) {
            first = false;
            sb.append('|');
        } else {
            sb.append(';');
        }
        sb.append(QueryModelTreePrinter.printTree(valueExpr));
    }
    return sb.toString();
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Aggregations

ValueExpr (org.openrdf.query.algebra.ValueExpr)4 TupleExpr (org.openrdf.query.algebra.TupleExpr)2 Var (org.openrdf.query.algebra.Var)2 PropertyRecord (edu.mit.simile.backstage.model.data.Database.PropertyRecord)1 ExpressionException (edu.mit.simile.backstage.model.data.ExpressionException)1 ExpressionResult (edu.mit.simile.backstage.model.data.ExpressionResult)1 Filter (org.openrdf.query.algebra.Filter)1 StatementPattern (org.openrdf.query.algebra.StatementPattern)1