Search in sources :

Example 1 with IriRefValueElement

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

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

the class PathPatternVisitor method visitReifiedPredicate.

/**
 * Visit reified predicate.
 *
 * @param ctx the ctx
 * @return the predicate element
 */
@Override
public PredicateElement visitReifiedPredicate(ReifiedPredicateContext ctx) {
    // reifiedPredicate :  iriRef? REIFIER predicateRef  factFilterPattern?  dereifier? ; #statementFilterPattern
    PredicateElement reifiedPredicateElement = new PredicateElement(this.repositoryContext);
    reifiedPredicateElement.setIsReified(true);
    if (ctx.iriRef() != null) {
        reifiedPredicateElement.setReification(((IriRefValueElement) visit(ctx.iriRef())).getIri());
    }
    if (ctx.predicateRef() != null) {
        reifiedPredicateElement.setPredicate(((IriRefValueElement) visit(ctx.predicateRef())).getIri());
    }
    if (ctx.factFilterPattern() != null) {
        reifiedPredicateElement.setObjectFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
    }
    if (ctx.dereifier() != null) {
        reifiedPredicateElement.setIsDereified(true);
    }
    return reifiedPredicateElement;
}
Also used : PredicateElement(com.inova8.pathql.element.PredicateElement)

Example 3 with IriRefValueElement

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

the class PathPatternVisitor method visitQname.

/**
 * Visit qname.
 *
 * @param ctx the ctx
 * @return the iri ref value element
 */
@Override
public IriRefValueElement visitQname(QnameContext ctx) {
    // qname : PNAME_NS PN_LOCAL;
    IriRefValueElement qnameElement = new IriRefValueElement(this.repositoryContext);
    IRI qname = this.repositoryContext.convertQName(ctx.getText(), getPrefixes());
    if (qname != null) {
        qnameElement.setIri(qname);
        return qnameElement;
    } else {
        if (thing != null)
            thing.getEvaluationContext().getTracer().traceQNameError(ctx.getText());
        throw new ScriptFailedException(String.format("Error identifying namespace of qName %s", ctx.getText()));
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException)

Example 4 with IriRefValueElement

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

the class PathPatternVisitor method visitPname_ns.

/**
 * Visit pname ns.
 *
 * @param ctx the ctx
 * @return the iri ref value element
 */
@Override
public IriRefValueElement visitPname_ns(Pname_nsContext ctx) {
    // pname_ns : PNAME_NS ;
    IriRefValueElement pname_nsElement = new IriRefValueElement(this.repositoryContext);
    Prefixes prefixes = null;
    prefixes = this.repositoryContext.getPrefixes();
    // if(thing!=null) prefixes=thing.getPrefixes();
    IRI qname = this.repositoryContext.convertQName(ctx.getText(), prefixes);
    if (qname != null) {
        pname_nsElement.setIri(qname);
        return pname_nsElement;
    } else {
        if (thing != null)
            thing.getEvaluationContext().getTracer().traceQNameError(ctx.getText());
        throw new ScriptFailedException(String.format("Error identifying namespace of qName %s", ctx.getText()));
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException) Prefixes(com.inova8.pathql.context.Prefixes)

Example 5 with IriRefValueElement

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

the class PathPatternVisitor method visitPredicate.

/**
 * Visit predicate.
 *
 * @param ctx the ctx
 * @return the predicate element
 */
@Override
public PredicateElement visitPredicate(PredicateContext ctx) {
    // predicate :   ( reifiedPredicate | predicateRef | rdfType | '*' ) factFilterPattern? #objectFilterPattern
    PredicateElement predicateElement = null;
    if (ctx.reifiedPredicate() != null) {
        predicateElement = (PredicateElement) visit(ctx.reifiedPredicate());
        predicateElement.setOperator(PathConstants.Operator.PREDICATE);
    } else if (ctx.predicateRef() != null) {
        predicateElement = new PredicateElement(this.repositoryContext);
        predicateElement.setOperator(PathConstants.Operator.PREDICATE);
        IriRefValueElement predicateRef = ((IriRefValueElement) visit(ctx.predicateRef()));
        predicateElement.setPredicate(predicateRef.getIri());
    } else if (ctx.rdfType() != null) {
        predicateElement = new PredicateElement(this.repositoryContext);
        predicateElement.setOperator(PathConstants.Operator.PREDICATE);
        predicateElement.setPredicate((iri("http://rdftype")));
    } else if (ctx.anyPredicate() != null) {
        predicateElement = new PredicateElement(this.repositoryContext);
        predicateElement.setOperator(PathConstants.Operator.PREDICATE);
        predicateElement.setAnyPredicate(true);
    }
    if (ctx.factFilterPattern() != null) {
        if (ctx.reifiedPredicate() != null) {
            predicateElement.setStatementFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
        } else {
            predicateElement.setObjectFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
        }
    }
    return predicateElement;
}
Also used : PredicateElement(com.inova8.pathql.element.PredicateElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement)

Aggregations

IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)8 ScriptFailedException (com.inova8.intelligentgraph.exceptions.ScriptFailedException)3 PredicateElement (com.inova8.pathql.element.PredicateElement)3 IRI (org.eclipse.rdf4j.model.IRI)3 LiteralValueElement (com.inova8.pathql.element.LiteralValueElement)2 PathElement (com.inova8.pathql.element.PathElement)2 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)2 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)2 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)2 CharStream (org.antlr.v4.runtime.CharStream)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)1 Prefixes (com.inova8.pathql.context.Prefixes)1 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)1 IriRefContext (com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)1 PathEltOrInverseContext (com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext)1 QueryOptionContext (com.inova8.pathql.pathPattern.PathPatternParser.QueryOptionContext)1 PathPatternException (com.inova8.pathql.processor.PathPatternException)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 Literal (org.eclipse.rdf4j.model.Literal)1