Search in sources :

Example 1 with DescribeOperator

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

the class TupleExprBuilder method visit.

@Override
public TupleExpr visit(ASTDescribe node, Object data) throws VisitorException {
    TupleExpr tupleExpr = (TupleExpr) data;
    if (tupleExpr == null) {
        tupleExpr = new SingletonSet();
    }
    Extension e = new Extension();
    ProjectionElemList projectionElements = new ProjectionElemList();
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        ValueExpr resource = (ValueExpr) node.jjtGetChild(i).jjtAccept(this, null);
        if (resource instanceof Var) {
            projectionElements.addElement(new ProjectionElem(((Var) resource).getName()));
        } else {
            String alias = "_describe_" + UUID.randomUUID().toString().replaceAll("-", "_");
            ExtensionElem elem = new ExtensionElem(resource, alias);
            e.addElement(elem);
            projectionElements.addElement(new ProjectionElem(alias));
        }
    }
    if (!e.getElements().isEmpty()) {
        e.setArg(tupleExpr);
        tupleExpr = e;
    }
    Projection p = new Projection(tupleExpr, projectionElements);
    return new DescribeOperator(p);
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) ProjectionElemList(org.eclipse.rdf4j.query.algebra.ProjectionElemList) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) SingletonSet(org.eclipse.rdf4j.query.algebra.SingletonSet) Var(org.eclipse.rdf4j.query.algebra.Var) DescribeOperator(org.eclipse.rdf4j.query.algebra.DescribeOperator) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) Projection(org.eclipse.rdf4j.query.algebra.Projection) MultiProjection(org.eclipse.rdf4j.query.algebra.MultiProjection) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ProjectionElem(org.eclipse.rdf4j.query.algebra.ProjectionElem)

Aggregations

DescribeOperator (org.eclipse.rdf4j.query.algebra.DescribeOperator)1 Extension (org.eclipse.rdf4j.query.algebra.Extension)1 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)1 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)1 Projection (org.eclipse.rdf4j.query.algebra.Projection)1 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)1 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)1 SingletonSet (org.eclipse.rdf4j.query.algebra.SingletonSet)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)1 Var (org.eclipse.rdf4j.query.algebra.Var)1