Search in sources :

Example 1 with LiteralValueElement

use of com.inova8.pathql.element.LiteralValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternVisitor method visitQueryOptions.

/**
 * Visit query options.
 *
 * @param ctx the ctx
 * @return the query options path element
 */
@Override
public QueryOptionsPathElement visitQueryOptions(QueryOptionsContext ctx) {
    // queryOptions : ( queryOption )+;
    // queryOption: KEY '=' literal ('^^' type )?;
    // KEY : '&' [a-zA-Z]+ ;
    CustomQueryOptions customQueryOptions = new CustomQueryOptions();
    for (QueryOptionContext queryOption : ctx.queryOption()) {
        String key = queryOption.KEY().getText().substring(1);
        LiteralValueElement literal = (LiteralValueElement) visit(queryOption.literal());
        if (queryOption.type() != null) {
            IriRefValueElement type = (IriRefValueElement) visit(queryOption.type());
            Literal typeLiteral = Values.literal(Values.getValueFactory(), literal.getLiteral().getLabel(), type.getIri());
            customQueryOptions.add(key, typeLiteral);
        } else {
            customQueryOptions.add(key, literal.getLiteral());
        }
    }
    QueryOptionsPathElement queryOptionsPathElement = new QueryOptionsPathElement(this.repositoryContext);
    queryOptionsPathElement.setCustomQueryOptions(customQueryOptions);
    return queryOptionsPathElement;
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) QueryOptionContext(com.inova8.pathql.pathPattern.PathPatternParser.QueryOptionContext) LiteralValueElement(com.inova8.pathql.element.LiteralValueElement) QueryOptionsPathElement(com.inova8.pathql.element.QueryOptionsPathElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) Literal(org.eclipse.rdf4j.model.Literal)

Example 2 with LiteralValueElement

use of com.inova8.pathql.element.LiteralValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternVisitor method visitLiteral.

/**
 * Visit literal.
 *
 * @param ctx the ctx
 * @return the literal value element
 */
@Override
public LiteralValueElement visitLiteral(LiteralContext ctx) {
    // rdfLiteral: (DQLITERAL | SQLITERAL) ('^^' (IRI_REF |  qname) )? ;
    LiteralValueElement literalElement = new LiteralValueElement(this.repositoryContext);
    String literalValue = null;
    if (ctx.DQLITERAL() == null) {
        literalValue = ctx.SQLITERAL().getText();
    } else {
        literalValue = ctx.DQLITERAL().getText();
    }
    literalValue = literalValue.substring(1, literalValue.length() - 1);
    IRI datatypeIRI = null;
    if (ctx.IRI_REF() == null) {
        if (ctx.qname() == null) {
            literalElement.setLiteral(literal(literalValue));
        } else {
            IriRefValueElement qnameElement = visitQname(ctx.qname());
            datatypeIRI = qnameElement.getIri();
            literalElement.setLiteral(literal(literalValue, datatypeIRI));
        }
    } else {
        String datatypeIRIString = ctx.IRI_REF().getText();
        literalElement.setLiteral(literal(literalValue, datatypeIRIString));
    }
    // literalElement.setLiteral(literal(literalValue));
    return literalElement;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) LiteralValueElement(com.inova8.pathql.element.LiteralValueElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement)

Aggregations

IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)2 LiteralValueElement (com.inova8.pathql.element.LiteralValueElement)2 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)1 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)1 QueryOptionContext (com.inova8.pathql.pathPattern.PathPatternParser.QueryOptionContext)1 IRI (org.eclipse.rdf4j.model.IRI)1 Literal (org.eclipse.rdf4j.model.Literal)1