Search in sources :

Example 1 with ASTLiteral

use of org.eclipse.rdf4j.query.parser.serql.ast.ASTLiteral 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)

Aggregations

IRI (org.eclipse.rdf4j.model.IRI)1 Literal (org.eclipse.rdf4j.model.Literal)1 IsLiteral (org.eclipse.rdf4j.query.algebra.IsLiteral)1 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)1 ASTIsLiteral (org.eclipse.rdf4j.query.parser.serql.ast.ASTIsLiteral)1 ASTLiteral (org.eclipse.rdf4j.query.parser.serql.ast.ASTLiteral)1 ASTURI (org.eclipse.rdf4j.query.parser.serql.ast.ASTURI)1 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)1