Search in sources :

Example 6 with SampleKBContext

use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.

the class RecursiveInferenceTest method testTransitiveMatrix.

@Test
public void testTransitiveMatrix() {
    final int N = 5;
    SampleKBContext kb = TransitivityMatrixKB.context(N, N);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match (Q-from: $x, Q-to: $y) isa Q;$x has index 'a'; get $y;";
    String explicitQuery = "match $y isa a-entity; get;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 7 with SampleKBContext

use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.

the class RecursiveInferenceTest method testPathTreePrime.

@Test
public void testPathTreePrime() {
    final int N = 3;
    SampleKBContext kb = PathTreeKB.context(N, 3);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa path;$x has index 'a0'; get $y;";
    String explicitQuery = "match $y isa vertex; get;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 8 with SampleKBContext

use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.

the class RecursiveInferenceTest method testPathTree.

/**
 *test 6.10 from Cao p. 82
 */
@Test
public void testPathTree() {
    final int N = 3;
    SampleKBContext kb = PathTreeKB.context(N, 3);
    GraknTx tx = kb.tx();
    QueryBuilder qb = tx.graql().infer(false);
    QueryBuilder iqb = tx.graql().infer(true);
    Concept a0 = getConcept(tx, "index", "a0");
    String queryString = "match (path-from: $x, path-to: $y) isa path;" + "$x has index 'a0';" + "get $y;";
    String explicitQuery = "match $y isa vertex; get;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    List<Answer> explicitAnswers = qb.<GetQuery>parse(explicitQuery).execute();
    List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
    assertCollectionsEqual(answers, explicitAnswers);
    assertCollectionsEqual(answers, answers2);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 9 with SampleKBContext

use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.

the class RecursiveInferenceTest method testTailRecursion.

/**
 *  test 6.3 from Cao p 75
 */
@Test
public void testTailRecursion() {
    final int N = 10;
    final int M = 5;
    SampleKBContext kb = TailRecursionKB.context(N, M);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match (P-from: $x, P-to: $y) isa P; $x has index 'a0'; get $y;";
    String explicitQuery = "match $y isa b-entity; get;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 10 with SampleKBContext

use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.

the class RecursiveInferenceTest method testDiagonal.

@Test
public void testDiagonal() {
    final int N = 10;
    SampleKBContext kb = DiagonalKB.context(N, N);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match (rel-from: $x, rel-to: $y) isa diagonal; get;";
    assertEquals(iqb.materialise(false).<GetQuery>parse(queryString).execute().size(), 64);
    assertEquals(iqb.materialise(true).<GetQuery>parse(queryString).execute().size(), 64);
}
Also used : SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Aggregations

SampleKBContext (ai.grakn.test.rule.SampleKBContext)17 Test (org.junit.Test)17 QueryBuilder (ai.grakn.graql.QueryBuilder)15 GetQuery (ai.grakn.graql.GetQuery)4 GraknTx (ai.grakn.GraknTx)2 Concept (ai.grakn.concept.Concept)2 Answer (ai.grakn.graql.admin.Answer)2