use of com.inova8.intelligentgraph.path.PathBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method visitPredicatePathBinding.
/**
* Visit predicate path binding.
*
* @param pathBinding the path binding
* @param pathIteration the path iteration
* @return the path binding
*/
private PathBinding visitPredicatePathBinding(PathBinding pathBinding, Integer pathIteration) {
StatementBinding predicateEdge;
Variable sourceVariable = this.getSourceVariable();
Variable targetVariable = this.getTargetVariable();
Variable intermediateSourceVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
for (int iteration = 1; iteration <= getCardinality(pathIteration); iteration++) {
if (iteration == 1) {
intermediateSourceVariable = sourceVariable;
}
if (iteration < getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = new Variable(targetVariable.getName() + "_i" + iteration);
priorIntermediateTargetVariable = intermediateTargetVariable;
}
if (iteration == getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = targetVariable;
}
predicateEdge = new StatementBinding(intermediateSourceVariable, getPredicateVariable(), intermediateTargetVariable, getIsInverseOf());
pathBinding.add(predicateEdge);
}
return pathBinding;
}
use of com.inova8.intelligentgraph.path.PathBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternPathTests method test_3.
/**
* Test 3.
*
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
@Test
@Order(3)
void test_3() throws RecognitionException, PathPatternException {
PathElement element = PathParser.parsePathPattern(repositoryContext, "^:hasProductBatteryLimit>:massThroughput");
PathBinding pathBinding = new PathBinding();
pathBinding = element.visitPathBinding(pathBinding, 0);
assertEquals("[n0,http://default/hasProductBatteryLimit,n1,INVERSE]\r\n" + "[n1,http://default/massThroughput,n2,DIRECT]\r\n" + "", pathBinding.toString());
}
use of com.inova8.intelligentgraph.path.PathBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternPathTests method test_1.
/**
* Test 1.
*
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
@Test
@Order(1)
void test_1() throws RecognitionException, PathPatternException {
PathElement element = PathParser.parsePathPattern(repositoryContext, ":parent1/:parent2/:parent3");
PathBinding pathBinding = new PathBinding();
pathBinding = element.visitPathBinding(pathBinding, 0);
assertEquals("[n0,http://default/parent1,n1,DIRECT]\r\n" + "[n1,http://default/parent2,n2,DIRECT]\r\n" + "[n2,http://default/parent3,n3,DIRECT]\r\n" + "", pathBinding.toString());
}
use of com.inova8.intelligentgraph.path.PathBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternPathTests method test_5.
/**
* Test 5.
*
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
@Test
@Order(5)
void test_5() throws RecognitionException, PathPatternException {
PathElement element = PathParser.parsePathPattern(repositoryContext, ":connectedTo{1,3}");
PathBinding pathBinding = new PathBinding();
pathBinding = element.visitPathBinding(pathBinding, 2);
assertEquals("[n0,http://default/connectedTo,n1_i1,DIRECT]\r\n" + "[n1_i1,http://default/connectedTo,n1_i2,DIRECT]\r\n" + "[n1_i2,http://default/connectedTo,n1,DIRECT]\r\n" + "", pathBinding.toString());
}
use of com.inova8.intelligentgraph.path.PathBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method visitReifiedPredicatePathBinding.
/**
* Visit reified predicate path binding.
*
* @param pathBinding the path binding
* @param pathIteration the path iteration
* @return the path binding
*/
private PathBinding visitReifiedPredicatePathBinding(PathBinding pathBinding, Integer pathIteration) {
StatementBinding predicateEdge;
Variable sourceVariable = this.getSourceVariable();
Variable targetVariable = this.getTargetVariable();
Variable reificationVariable = this.getReifiedVariable();
Variable intermediateSourceVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
Variable intermediateReificationVariable = null;
for (int iteration = 1; iteration <= getCardinality(pathIteration); iteration++) {
if (iteration == 1) {
intermediateSourceVariable = sourceVariable;
}
if (iteration < getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = new Variable(targetVariable.getName() + "_i" + iteration);
priorIntermediateTargetVariable = intermediateTargetVariable;
}
if (iteration == getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = targetVariable;
intermediateReificationVariable = reificationVariable;
} else {
intermediateReificationVariable = new Variable(reificationVariable.getName() + "_i" + iteration);
}
predicateEdge = new StatementBinding(intermediateSourceVariable, this.reification, intermediateReificationVariable, getPredicateVariable(), getIsDereified() ? this.getReifiedVariable() : intermediateTargetVariable, getIsInverseOf(), getIsDereified());
pathBinding.add(predicateEdge);
}
return pathBinding;
}
Aggregations