Search in sources :

Example 1 with PathBinding

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;
}
Also used : StatementBinding(com.inova8.intelligentgraph.path.StatementBinding)

Example 2 with 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());
}
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 3 with PathBinding

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());
}
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 4 with PathBinding

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());
}
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 5 with PathBinding

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;
}
Also used : StatementBinding(com.inova8.intelligentgraph.path.StatementBinding)

Aggregations

PathBinding (com.inova8.intelligentgraph.path.PathBinding)7 PathElement (com.inova8.pathql.element.PathElement)5 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 StatementBinding (com.inova8.intelligentgraph.path.StatementBinding)2 Fact (com.inova8.intelligentgraph.model.Fact)1 Resource (com.inova8.intelligentgraph.model.Resource)1 EdgeBinding (com.inova8.intelligentgraph.path.EdgeBinding)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Model (org.eclipse.rdf4j.model.Model)1 ModelBuilder (org.eclipse.rdf4j.model.util.ModelBuilder)1 BindingSet (org.eclipse.rdf4j.query.BindingSet)1