Search in sources :

Example 11 with SampleKBContext

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

the class RecursiveInferenceTest method testPathMatrix.

@Test
public /*modified test 6.10 from Cao p. 82*/
void testPathMatrix() {
    final int N = 3;
    SampleKBContext kb = PathMatrixKB.context(N, N);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match (path-from: $x, path-to: $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 12 with SampleKBContext

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

the class RecursiveInferenceTest method testPathMatrixPrime.

@Test
public /*modified test 6.10 from Cao p. 82*/
void testPathMatrixPrime() {
    final int N = 3;
    SampleKBContext kb = PathMatrixKB.context(N, N);
    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'; $y has index $ind;get $y, $ind;";
    String explicitQuery = "match $y isa vertex;$y has index $ind; 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 13 with SampleKBContext

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

the class RecursiveInferenceTest method testTransitiveChain.

@Test
public void testTransitiveChain() {
    final int N = 10;
    SampleKBContext kb = TransitivityChainKB.context(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 14 with SampleKBContext

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

the class RecursiveInferenceTest method testLinearTransitivityMatrix.

/**
 *test 6.9 from Cao p.82
 */
@Test
public void testLinearTransitivityMatrix() {
    final int N = 5;
    final int M = 5;
    SampleKBContext kb = LinearTransitivityMatrixKB.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 '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 15 with SampleKBContext

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

the class BenchmarkTests method testTransitiveMatrix.

/**
 * single-rule transitivity test with initial data arranged in a N x N square grid.
 * The rule is given as:
 *
 * (Q-from: $x, Q-to: $z) isa Q;
 * (Q-from: $z, Q-to: $y) isa Q;
 * ->
 * (Q-from: $x, Q-to: $y) isa Q;
 *
 * Each pair of neighbouring grid points is related in the following fashion:
 *
 *  a_{i  , j} -  Q  - a_{i, j + 1}
 *       |                    |
 *       Q                    Q
 *       |                    |
 *  a_{i+1, j} -  Q  - a_{i+1, j+1}
 *
 *  i e [0, N)
 *  j e [0, N)
 */
@Test
public void testTransitiveMatrix() {
    LOG.debug(new Object() {
    }.getClass().getEnclosingMethod().getName());
    final int N = 10;
    int limit = 100;
    // DJ       IC     FO
    // results @N = 15 14400     ?
    // results @N = 20 44100     ?       ?     12s     4 s
    // results @N = 25 105625    ?       ?     50s    11 s
    // results @N = 30 216225    ?       ?      ?     30 s
    // results @N = 35 396900   ?        ?      ?     76 s
    SampleKBContext kb = TransitivityMatrixKB.context(N, N);
    QueryBuilder iqb = kb.tx().graql().infer(true).materialise(false);
    // full result
    String queryString = "match (Q-from: $x, Q-to: $y) isa Q; get;";
    GetQuery query = iqb.parse(queryString);
    // with specific resource
    String queryString2 = "match (Q-from: $x, Q-to: $y) isa Q;$x has index 'a'; get;";
    GetQuery query2 = iqb.parse(queryString2);
    // with substitution
    Concept id = iqb.<GetQuery>parse("match $x has index 'a'; get;").execute().iterator().next().get("x");
    String queryString3 = "match (Q-from: $x, Q-to: $y) isa Q;$x id '" + id.getId().getValue() + "'; get;";
    GetQuery query3 = iqb.parse(queryString3);
    executeQuery(query, "full");
    executeQuery(query2, "With specific resource");
    executeQuery(query3, "Single argument bound");
    executeQuery(query.match().limit(limit).get(), "limit " + limit);
}
Also used : Concept(ai.grakn.concept.Concept) SampleKBContext(ai.grakn.test.rule.SampleKBContext) GetQuery(ai.grakn.graql.GetQuery) 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