Search in sources :

Example 6 with IriRefValueElement

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

the class PathParser method parseIriRef.

/**
 * Parses the iri ref.
 *
 * @param repositoryContext the repository context
 * @param uriPattern the uri pattern
 * @return the iri ref value element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
public static IriRefValueElement parseIriRef(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
    try {
        pathPatternVisitor = new PathPatternVisitor(repositoryContext);
        CharStream input = CharStreams.fromString(uriPattern);
        PathPatternLexer lexer = new PathPatternLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        PathPatternParser parser = new PathPatternParser(tokens);
        IriRefContext pathPatternTree = parser.iriRef();
        PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
        return (IriRefValueElement) iriRefValueElement;
    } catch (Exception qe) {
        throw new PathPatternException(qe.getMessage(), null);
    }
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) PathPatternException(com.inova8.pathql.processor.PathPatternException) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) CharStream(org.antlr.v4.runtime.CharStream) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) IriRefContext(com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)

Example 7 with IriRefValueElement

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

the class PathParser method parsePredicate.

/**
 * Parses the predicate.
 *
 * @param repositoryContext the repository context
 * @param uriPattern the uri pattern
 * @return the predicate element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
public static PredicateElement parsePredicate(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
    pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    CharStream input = CharStreams.fromString(uriPattern);
    PathPatternLexer lexer = new PathPatternLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    PathEltOrInverseContext pathPatternTree = parser.pathEltOrInverse();
    PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
    return (PredicateElement) iriRefValueElement;
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PathElement(com.inova8.pathql.element.PathElement) PredicateElement(com.inova8.pathql.element.PredicateElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathEltOrInverseContext(com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext) CharStream(org.antlr.v4.runtime.CharStream)

Example 8 with IriRefValueElement

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

the class PathPatternVisitor method visitPredicateRef.

/**
 * Visit predicate ref.
 *
 * @param ctx the ctx
 * @return the iri ref value element
 */
@Override
public IriRefValueElement visitPredicateRef(PredicateRefContext ctx) {
    // predicateRef :  IRI_REF  | rdfType  |  qname | pname_ns ;
    IriRefValueElement predicateRefElement;
    if (ctx.qname() != null) {
        predicateRefElement = (IriRefValueElement) visit(ctx.qname());
    } else if (ctx.pname_ns() != null) {
        predicateRefElement = (IriRefValueElement) visit(ctx.pname_ns());
    } else if (ctx.rdfType() != null) {
        predicateRefElement = new IriRefValueElement(this.repositoryContext);
        predicateRefElement.setIri(iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
    } else {
        predicateRefElement = new IriRefValueElement(this.repositoryContext);
        String iri = ctx.IRI_REF().getText();
        iri = iri.substring(1, iri.length() - 1);
        predicateRefElement.setIri(iri(iri));
    }
    return predicateRefElement;
}
Also used : IriRefValueElement(com.inova8.pathql.element.IriRefValueElement)

Example 9 with IriRefValueElement

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

the class PathPatternVisitor method visitIriRef.

/**
 * Visit iri ref.
 *
 * @param ctx the ctx
 * @return the iri ref value element
 */
@Override
public IriRefValueElement visitIriRef(IriRefContext ctx) {
    // iriRef  : IRI_REF  |  qname | pname_ns ;
    IriRefValueElement iriRefElement = new IriRefValueElement(this.repositoryContext);
    if (ctx.qname() != null) {
        iriRefElement.setIri(((IriRefValueElement) visit(ctx.qname())).getIri());
    } else if (ctx.pname_ns() != null) {
        iriRefElement.setIri(((IriRefValueElement) visit(ctx.pname_ns())).getIri());
    } else if (ctx.IRI_REF() != null) {
        String iri = ctx.IRI_REF().getText();
        iri = iri.substring(1, iri.length() - 1);
        iriRefElement.setIri(iri(iri));
    } else {
        throw new ScriptFailedException(String.format("Error identifying iriRef %s", ctx.getText()));
    }
    return iriRefElement;
}
Also used : IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException)

Example 10 with IriRefValueElement

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