Search in sources :

Example 1 with Iterations

use of com.inova8.pathql.element.Iterations in project com.inova8.intelligentgraph by peterjohnlawrence.

the class MultiPathPatternQueryExpressionTests method test_2.

/**
 * Test 2.
 */
@Test
@Order(2)
void test_2() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, ":hasProductBatteryLimit{1, 8}");
        Iterations iterations = Iterations.create(element);
        assertEquals("{0=1, 1=2, 2=3, 3=4, 4=5, 5=6, 6=7, 7=8}", iterations.toString());
        @SuppressWarnings("unused") Iterations sortedIterations = iterations.sortByPathLength();
        PathTupleExpr pathTupleExpr = element.pathPatternQuery(2, null);
        // Query.assertEqualsWOSpaces
        assertEquals("Join\r\n" + "   Join\r\n" + "      StatementPattern\r\n" + "         Variable (name=n0)\r\n" + "         Variable (name=p_n0_n1, value=http://default/hasProductBatteryLimit)\r\n" + "         Variable (name=n1_i1)\r\n" + "      StatementPattern\r\n" + "         Variable (name=n1_i1)\r\n" + "         Variable (name=p_n0_n1, value=http://default/hasProductBatteryLimit)\r\n" + "         Variable (name=n1_i2)\r\n" + "   StatementPattern\r\n" + "      Variable (name=n1_i2)\r\n" + "      Variable (name=p_n0_n1, value=http://default/hasProductBatteryLimit)\r\n" + "      Variable (name=n1)\r\n" + "", pathTupleExpr.toString());
        assertEquals("[n0,http://default/hasProductBatteryLimit,n1_i1,DIRECT]\r\n" + "[n1_i1,http://default/hasProductBatteryLimit,n1_i2,DIRECT]\r\n" + "[n1_i2,http://default/hasProductBatteryLimit,n1,DIRECT]\r\n" + "", // element.getPathBindings().get(2).toString());
        pathTupleExpr.pathToString());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) Iterations(com.inova8.pathql.element.Iterations) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 2 with Iterations

use of com.inova8.pathql.element.Iterations in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathIterationTests method test_6.

/**
 * Test 6.
 */
@Test
@Order(6)
void test_6() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, ":hasParent{0,4}/:hasParent[:hasGender :Female]");
        assertEquals("<http://default/hasParent>{0,4} / <http://default/hasParent>[<http://default/hasGender> <http://default/Female> ]", element.toString());
        assertEquals("{0=1, 1=2, 2=3, 3=4, 4=5}", element.getIterations().toString());
        Iterations sortedIterations = element.getIterations().sortByPathLength();
        assertEquals("{0=1, 1=2, 2=3, 3=4, 4=5}", sortedIterations.toString());
        assertEquals("({0,0,4}/{1,1,1}){1,1,1}", element.getPathShareString(0));
        assertEquals("({0,1,4}/{1,1,1}){1,1,1}", element.getPathShareString(1));
        assertEquals("({0,3,4}/{1,1,1}){1,1,1}", element.getPathShareString(3));
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) Iterations(com.inova8.pathql.element.Iterations) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 3 with Iterations

use of com.inova8.pathql.element.Iterations in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathIterationTests method test_2.

/**
 * Test 2.
 */
@Test
@Order(2)
void test_2() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, ":hasProductBatteryLimit{1, 4}/:massThroughput{1,2}");
        assertEquals("<http://default/hasProductBatteryLimit>{1,4} / <http://default/massThroughput>{1,2}", element.toString());
        assertEquals("{0=2, 1=3, 2=3, 3=4, 4=4, 5=5, 6=5, 7=6}", element.getIterations().toString());
        Iterations sortedIterations = element.getIterations().sortByPathLength();
        assertEquals("{0=2, 1=3, 2=3, 3=4, 4=4, 5=5, 6=5, 7=6}", sortedIterations.toString());
        assertEquals("({1,1,4}/{1,2,2}){1,1,1}", element.getPathShareString(1));
        assertEquals("({1,2,4}/{1,2,2}){1,1,1}", element.getPathShareString(3));
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) Iterations(com.inova8.pathql.element.Iterations) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 4 with Iterations

use of com.inova8.pathql.element.Iterations in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathIterationTests method test_0.

/**
 * Test 0.
 */
@Test
@Order(0)
void test_0() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, ":hasProductBatteryLimit{1, 4}");
        assertEquals("<http://default/hasProductBatteryLimit>{1,4}", element.toString());
        ;
        assertEquals("{0=1, 1=2, 2=3, 3=4}", element.getIterations().toString());
        Iterations sortedIterations = element.getIterations().sortByPathLength();
        assertEquals("{0=1, 1=2, 2=3, 3=4}", sortedIterations.toString());
        assertEquals("{1,2,4}", element.getPathShareString(1));
        assertEquals("{1,4,4}", element.getPathShareString(3));
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) Iterations(com.inova8.pathql.element.Iterations) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 5 with Iterations

use of com.inova8.pathql.element.Iterations in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathIterationTests method test_3.

/**
 * Test 3.
 */
@Test
@Order(3)
void test_3() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, ":hasProductBatteryLimit{1, 2}/:massThroughput{1,2}/:massThroughput{1,2}");
        assertEquals("<http://default/hasProductBatteryLimit>{1,2} / <http://default/massThroughput>{1,2} / <http://default/massThroughput>{1,2}", element.toString());
        assertEquals("{0=3, 1=4, 2=4, 3=5, 4=4, 5=5, 6=5, 7=6}", element.getIterations().toString());
        Iterations sortedIterations = element.getIterations().sortByPathLength();
        assertEquals("{0=3, 1=4, 2=4, 4=4, 3=5, 5=5, 6=5, 7=6}", sortedIterations.toString());
        assertEquals("(({1,1,2}/{1,1,2}){1,1,1}/{1,2,2}){1,1,1}", element.getPathShareString(1));
        assertEquals("(({1,1,2}/{1,2,2}){1,1,1}/{1,2,2}){1,1,1}", element.getPathShareString(3));
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) Iterations(com.inova8.pathql.element.Iterations) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

Iterations (com.inova8.pathql.element.Iterations)7 PathElement (com.inova8.pathql.element.PathElement)7 Order (org.junit.jupiter.api.Order)7 Test (org.junit.jupiter.api.Test)7 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)7 PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)1