Search in sources :

Example 1 with StatementPattern

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

the class AllItemsCollection method getAllItems.

public Var getAllItems(TupleQueryBuilder builder, Var defaultVar) {
    Var var = defaultVar != null ? defaultVar : builder.makeVar("item");
    builder.addTupleExpr(new StatementPattern(var, builder.makeVar("p", RDF.TYPE), builder.makeVar("ignore")));
    return var;
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var)

Example 2 with StatementPattern

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

the class TypeBasedCollection method getAllItems.

public Var getAllItems(TupleQueryBuilder builder, Var defaultVar) {
    Var var = defaultVar != null ? defaultVar : builder.makeVar("item");
    builder.addTupleExpr(new StatementPattern(var, builder.makeVar("p", RDF.TYPE), builder.makeVar("type", _typeURI)));
    return var;
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var)

Example 3 with StatementPattern

use of org.openrdf.query.algebra.StatementPattern in project gocd by gocd.

the class SesameGraph method contextualize.

private void contextualize(Query query) throws Exception {
    if (contextVar == null) {
        return;
    }
    TupleExpr tupleExpr = ((SailQuery) query).getParsedQuery().getTupleExpr();
    tupleExpr.visit(new QueryModelVisitorBase() {

        public void meet(StatementPattern node) throws Exception {
            if (node.getContextVar() != null) {
                throw new UnsupportedSPARQLStatementException("Attempted to execute a SPARQL statement with a GRAPH clause against a context aware graph.");
            }
            node.setContextVar(contextVar);
        }
    });
}
Also used : QueryModelVisitorBase(org.openrdf.query.algebra.helpers.QueryModelVisitorBase) StatementPattern(org.openrdf.query.algebra.StatementPattern) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException) TupleExpr(org.openrdf.query.algebra.TupleExpr) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) MoreThanOneResultFoundException(com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException) MalformedSPARQLException(com.thoughtworks.studios.shine.semweb.MalformedSPARQLException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) OpenRDFException(org.openrdf.OpenRDFException) NoSuchElementException(java.util.NoSuchElementException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) UnsupportedSPARQLStatementException(com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)

Example 4 with StatementPattern

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

Aggregations

StatementPattern (org.openrdf.query.algebra.StatementPattern)4 Var (org.openrdf.query.algebra.Var)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)1 MalformedSPARQLException (com.thoughtworks.studios.shine.semweb.MalformedSPARQLException)1 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)1 UnsupportedSPARQLStatementException (com.thoughtworks.studios.shine.semweb.UnsupportedSPARQLStatementException)1 PropertyRecord (edu.mit.simile.backstage.model.data.Database.PropertyRecord)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 OpenRDFException (org.openrdf.OpenRDFException)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)1 TupleExpr (org.openrdf.query.algebra.TupleExpr)1 ValueExpr (org.openrdf.query.algebra.ValueExpr)1 QueryModelVisitorBase (org.openrdf.query.algebra.helpers.QueryModelVisitorBase)1 RepositoryException (org.openrdf.repository.RepositoryException)1 RDFHandlerException (org.openrdf.rio.RDFHandlerException)1