Search in sources :

Example 1 with PathPatternVisitor

use of com.inova8.pathql.processor.PathPatternVisitor in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternQueryExpressionTests method prepareElement.

/**
 * Prepare element.
 *
 * @param input the input
 * @return the path element
 * @throws RecognitionException the recognition exception
 */
private PathElement prepareElement(CharStream input) throws RecognitionException {
    PathPatternLexer lexer = new PathPatternLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    PathPatternContext pathPatternTree = parser.pathPattern();
    PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    PathElement element = pathPatternVisitor.visit(pathPatternTree);
    element.indexVisitor(null, 0, null);
    element.setIterations(Iterations.create(element));
    // element.setPathBindings(PathBindings.create(element));
    return element;
}
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) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathPatternContext(com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext)

Example 2 with PathPatternVisitor

use of com.inova8.pathql.processor.PathPatternVisitor in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternTests method prepareElement.

/**
 * Prepare element.
 *
 * @param input the input
 * @return the path element
 * @throws RecognitionException the recognition exception
 */
private PathElement prepareElement(CharStream input) throws RecognitionException {
    PathPatternLexer lexer = new PathPatternLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    PathPatternContext pathPatternTree = parser.pathPattern();
    PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    PathElement element = pathPatternVisitor.visit(pathPatternTree);
    return element;
}
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) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathPatternContext(com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext)

Example 3 with PathPatternVisitor

use of com.inova8.pathql.processor.PathPatternVisitor 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 4 with PathPatternVisitor

use of com.inova8.pathql.processor.PathPatternVisitor 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 5 with PathPatternVisitor

use of com.inova8.pathql.processor.PathPatternVisitor in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathParser method parsePathPattern.

// @Deprecated
// public static PathElement parsePathPattern(Thing thing, String pathPattern)
// throws RecognitionException, PathPatternException {
// PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(thing);
// PathElement pathElement = pathPatternParser(pathPattern, pathPatternVisitor);
// return pathElement;
// }
// public static PathElement parsePathPattern(String pathPattern)
// throws RecognitionException, PathPatternException {
// PathPatternVisitor pathPatternVisitor = new PathPatternVisitor();
// PathElement pathElement = pathPatternParser(pathPattern, pathPatternVisitor);
// return pathElement;
// }
/**
 * Parses the path pattern.
 *
 * @param repositoryContext the repository context
 * @param pathPattern the path pattern
 * @return the path element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
public static PathElement parsePathPattern(RepositoryContext repositoryContext, String pathPattern) throws RecognitionException, PathPatternException {
    PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    PathElement pathElement = pathPatternParser(pathPattern, pathPatternVisitor);
    return pathElement;
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) PathElement(com.inova8.pathql.element.PathElement)

Aggregations

PathElement (com.inova8.pathql.element.PathElement)9 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)8 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)8 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)8 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)8 CharStream (org.antlr.v4.runtime.CharStream)5 PathPatternContext (com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext)4 PathErrorListener (com.inova8.pathql.processor.PathErrorListener)3 RecognitionException (org.antlr.v4.runtime.RecognitionException)3 QueryStringContext (com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext)2 PathPatternException (com.inova8.pathql.processor.PathPatternException)2 Order (org.junit.jupiter.api.Order)2 Test (org.junit.jupiter.api.Test)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)1 PredicateElement (com.inova8.pathql.element.PredicateElement)1 IriRefContext (com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)1 PathEltOrInverseContext (com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext)1