Search in sources :

Example 1 with ASTValueExpr

use of org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public ValueConstant visit(ASTLiteral litNode, Object data) throws VisitorException {
    IRI datatype = null;
    // Get datatype URI from child URI node, if present
    ASTValueExpr dtNode = litNode.getDatatypeNode();
    if (dtNode instanceof ASTURI) {
        datatype = valueFactory.createIRI(((ASTURI) dtNode).getValue());
    } else if (dtNode != null) {
        throw new IllegalArgumentException("Unexpected datatype type: " + dtNode.getClass());
    }
    Literal literal;
    if (datatype != null) {
        literal = valueFactory.createLiteral(litNode.getLabel(), datatype);
    } else if (litNode.hasLang()) {
        literal = valueFactory.createLiteral(litNode.getLabel(), litNode.getLang());
    } else {
        literal = valueFactory.createLiteral(litNode.getLabel());
    }
    return new ValueConstant(literal);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) IsLiteral(org.eclipse.rdf4j.query.algebra.IsLiteral) Literal(org.eclipse.rdf4j.model.Literal) ASTLiteral(org.eclipse.rdf4j.query.parser.serql.ast.ASTLiteral) ASTIsLiteral(org.eclipse.rdf4j.query.parser.serql.ast.ASTIsLiteral) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) ASTURI(org.eclipse.rdf4j.query.parser.serql.ast.ASTURI)

Example 2 with ASTValueExpr

use of org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public ValueExpr visit(ASTInList node, Object data) throws VisitorException {
    ValueExpr leftArg = (ValueExpr) node.getValueExpr().jjtAccept(this, null);
    ValueExpr result = null;
    for (ASTValueExpr argExpr : node.getArgList().getElements()) {
        ValueExpr rightArg = (ValueExpr) argExpr.jjtAccept(this, null);
        if (result == null) {
            // First argument
            result = new SameTerm(leftArg, rightArg);
        } else {
            SameTerm sameTerm = new SameTerm(leftArg.clone(), rightArg);
            result = new Or(result, sameTerm);
        }
    }
    assert result != null;
    return result;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) Or(org.eclipse.rdf4j.query.algebra.Or) ASTOr(org.eclipse.rdf4j.query.parser.serql.ast.ASTOr) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ASTSameTerm(org.eclipse.rdf4j.query.parser.serql.ast.ASTSameTerm) SameTerm(org.eclipse.rdf4j.query.algebra.SameTerm)

Example 3 with ASTValueExpr

use of org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr in project rdf4j by eclipse.

the class QueryModelBuilder method visit.

@Override
public FunctionCall visit(ASTFunctionCall node, Object data) throws VisitorException {
    ValueConstant vc = (ValueConstant) node.getURI().jjtAccept(this, null);
    assert vc.getValue() instanceof IRI;
    FunctionCall functionCall = new FunctionCall(vc.getValue().toString());
    for (ASTValueExpr argExpr : node.getArgList().getElements()) {
        functionCall.addArg((ValueExpr) argExpr.jjtAccept(this, null));
    }
    return functionCall;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ASTValueExpr(org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) ASTFunctionCall(org.eclipse.rdf4j.query.parser.serql.ast.ASTFunctionCall) FunctionCall(org.eclipse.rdf4j.query.algebra.FunctionCall)

Aggregations

ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)3 IRI (org.eclipse.rdf4j.model.IRI)2 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)2 Literal (org.eclipse.rdf4j.model.Literal)1 FunctionCall (org.eclipse.rdf4j.query.algebra.FunctionCall)1 IsLiteral (org.eclipse.rdf4j.query.algebra.IsLiteral)1 Or (org.eclipse.rdf4j.query.algebra.Or)1 SameTerm (org.eclipse.rdf4j.query.algebra.SameTerm)1 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)1 ASTFunctionCall (org.eclipse.rdf4j.query.parser.serql.ast.ASTFunctionCall)1 ASTIsLiteral (org.eclipse.rdf4j.query.parser.serql.ast.ASTIsLiteral)1 ASTLiteral (org.eclipse.rdf4j.query.parser.serql.ast.ASTLiteral)1 ASTOr (org.eclipse.rdf4j.query.parser.serql.ast.ASTOr)1 ASTSameTerm (org.eclipse.rdf4j.query.parser.serql.ast.ASTSameTerm)1 ASTURI (org.eclipse.rdf4j.query.parser.serql.ast.ASTURI)1