Search in sources :

Example 21 with PathPatternException

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

the class Local_Sparql_IntelligentGraphTests method addGraph3.

/**
 * Adds the graph 3.
 *
 * @return the thing
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private Thing addGraph3() throws RecognitionException, PathPatternException {
    source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph4>");
    Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph3>");
    Thing myCountry = graph.getThing(":Country3");
    myCountry.addFact(":sales", "10");
    myCountry.addFact(":sales", "20");
    myCountry.addFact(":sales", "30");
    myCountry.addFact(":sales", "40");
    myCountry.addFact(":sales", "50");
    String totalSalesScript = "return _this.getFacts(\":sales\").total();";
    myCountry.addFact(":totalSales", totalSalesScript, SCRIPT.GROOVY);
    return myCountry;
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing)

Example 22 with PathPatternException

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

the class PathPatternPathTests method test_4.

/**
 * Test 4.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(4)
void test_4() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":Location@:appearsOn[ eq [ rdfs:label \"Calc2Graph1\"] ]#/^:lat/:long/^:left/:right");
    PathBinding pathBinding = new PathBinding();
    pathBinding = element.visitPathBinding(pathBinding, 0);
    assertEquals("[n0,r1:<http://default/Location>@http://default/appearsOn,r1,DIRECT,true]\r\n" + "[r1,http://default/lat,n2,INVERSE]\r\n" + "[n2,http://default/long,n3,DIRECT]\r\n" + "[n3,http://default/left,n4,INVERSE]\r\n" + "[n4,http://default/right,n5,DIRECT]\r\n" + "", pathBinding.toString());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathBinding(com.inova8.intelligentgraph.path.PathBinding) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 23 with PathPatternException

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

the class PathPatternPathTests method test_2.

/**
 * Test 2.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(2)
void test_2() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":parent1[:gender :female]/^:child2[:gender :male; :birthplace [rdfs:label 'Maidstone']]/:parent3");
    PathBinding pathBinding = new PathBinding();
    pathBinding = element.visitPathBinding(pathBinding, 0);
    assertEquals("[n0,http://default/parent1,n1,DIRECT]\r\n" + "[n1,http://default/child2,n2,INVERSE]\r\n" + "[n2,http://default/parent3,n3,DIRECT]\r\n" + "", pathBinding.toString());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathBinding(com.inova8.intelligentgraph.path.PathBinding) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 24 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException 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)

Example 25 with PathPatternException

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

the class PathParser method pathPatternParser.

/**
 * Path pattern parser.
 *
 * @param pathPattern the path pattern
 * @param pathPatternVisitor the path pattern visitor
 * @return the path element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private static PathElement pathPatternParser(String pathPattern, PathPatternVisitor pathPatternVisitor) throws RecognitionException, PathPatternException {
    PathErrorListener errorListener = new PathErrorListener(pathPattern);
    CharStream input = CharStreams.fromString(pathPattern);
    PathPatternLexer lexer = new PathPatternLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PathPatternParser parser = new PathPatternParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    QueryStringContext queryStringTree = parser.queryString();
    PathElement pathElement = pathPatternVisitor.visit(queryStringTree);
    if (errorListener.toString() != null) {
        if (parser.getNumberOfSyntaxErrors() == 0) {
            // Lexer only error
            throw new PathPatternException(errorListener.toString(), ErrorCode.LEXER);
        } else {
            // Parser error
            throw new PathPatternException(errorListener.toString(), ErrorCode.PARSER);
        }
    }
    pathElement.setPathPattern(pathPattern);
    pathElement.indexVisitor(null, 0, null);
    pathElement.setIterations(Iterations.create(pathElement));
    // pathElement.setPathBindings(PathBindings.create(pathElement));
    return pathElement;
}
Also used : 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) PathPatternException(com.inova8.pathql.processor.PathPatternException) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathErrorListener(com.inova8.pathql.processor.PathErrorListener) CharStream(org.antlr.v4.runtime.CharStream)

Aggregations

PathElement (com.inova8.pathql.element.PathElement)25 Order (org.junit.jupiter.api.Order)17 Test (org.junit.jupiter.api.Test)17 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)17 Thing (com.inova8.intelligentgraph.model.Thing)15 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)9 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)6 PathBinding (com.inova8.intelligentgraph.path.PathBinding)5 PredicateElement (com.inova8.pathql.element.PredicateElement)4 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)3 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)3 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)3 CharStream (org.antlr.v4.runtime.CharStream)3 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)3 IRI (org.eclipse.rdf4j.model.IRI)3 ReificationType (com.inova8.pathql.context.ReificationType)2 PathPatternException (com.inova8.pathql.processor.PathPatternException)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)1 IriRefContext (com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)1 PathEltOrInverseContext (com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext)1