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;
}
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());
}
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());
}
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;
}
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;
}
Aggregations