Search in sources :

Example 1 with PathPatternContext

use of com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext 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 PathPatternContext

use of com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext 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 PathPatternContext

use of com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternTests method test_11.

/**
 * Test 11.
 */
@Test
@Order(11)
void test_11() {
    try {
        String expression = ":Location@:appearsOn[eq id:Calc2Graph2]#";
        CharStream input = CharStreams.fromString(expression);
        PathPatternLexer lexer = new PathPatternLexer(input);
        PathErrorListener errorListener = new PathErrorListener(expression);
        lexer.removeErrorListeners();
        lexer.addErrorListener(errorListener);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        PathPatternParser parser = new PathPatternParser(tokens);
        parser.removeErrorListeners();
        parser.addErrorListener(errorListener);
        PathPatternContext pathPatternTree = parser.pathPattern();
        PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
        PathElement element = pathPatternVisitor.visit(pathPatternTree);
        assertEquals("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ]#", element.toString());
    } catch (Exception e) {
        assertEquals("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ;]#", "");
    }
}
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) PathErrorListener(com.inova8.pathql.processor.PathErrorListener) PathPatternContext(com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext) CharStream(org.antlr.v4.runtime.CharStream) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 4 with PathPatternContext

use of com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class QueryStringParserTests 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();
    QueryStringContext queryStringTree = parser.queryString();
    PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
    PathElement element = pathPatternVisitor.visit(queryStringTree);
    return element;
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) QueryStringContext(com.inova8.pathql.pathPattern.PathPatternParser.QueryStringContext) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer)

Example 5 with PathPatternContext

use of com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternQueryExpressionTests method test_11.

/**
 * Test 11.
 */
@Test
@Order(11)
void test_11() {
    try {
        String expression = ":Location@:appearsOn[eq id:Calc2Graph2]#";
        CharStream input = CharStreams.fromString(expression);
        PathPatternLexer lexer = new PathPatternLexer(input);
        PathErrorListener errorListener = new PathErrorListener(expression);
        lexer.removeErrorListeners();
        lexer.addErrorListener(errorListener);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        PathPatternParser parser = new PathPatternParser(tokens);
        parser.removeErrorListeners();
        parser.addErrorListener(errorListener);
        PathPatternContext pathPatternTree = parser.pathPattern();
        PathPatternVisitor pathPatternVisitor = new PathPatternVisitor(repositoryContext);
        PathElement element = pathPatternVisitor.visit(pathPatternTree);
        // Query.assertEqualsWOSpaces
        assertEquals("Join\r\n" + "   Join\r\n" + "      StatementPattern\r\n" + "         Variable (name=rnull)\r\n" + "         Variable (name=subjectnull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#subject)\r\n" + "         Variable (name=nnull)\r\n" + "      StatementPattern\r\n" + "         Variable (name=rnull)\r\n" + "         Variable (name=propertynull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate)\r\n" + "         Variable (name=p_nnull_nnull, value=http://default/appearsOn)\r\n" + "   StatementPattern\r\n" + "      Variable (name=rnull)\r\n" + "      Variable (name=objectnull, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + "      Variable (name=nnull, value=http://id/Calc2Graph2)\r\n" + "", element.pathPatternQuery().toString());
    } catch (Exception e) {
        Query.assertEqualsWOSpaces("<http://default/Location>@<http://default/appearsOn>[eq <http://id/Calc2Graph2> ;]#", "");
    }
}
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) PathErrorListener(com.inova8.pathql.processor.PathErrorListener) PathPatternContext(com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext) CharStream(org.antlr.v4.runtime.CharStream) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

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