Search in sources :

Example 1 with QueryOptionsPathElement

use of com.inova8.pathql.element.QueryOptionsPathElement 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)

Aggregations

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