use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.
the class BenchmarkTests method testTransitiveMatrixLinear.
/**
* 2-rule transitive test with transitivity expressed in terms of two linear rules
* The rules are defined as:
*
* (Q-from: $x, Q-to: $y) isa Q;
* ->
* (P-from: $x, P-to: $y) isa P;
*
* (Q-from: $x, Q-to: $z) isa Q;
* (P-from: $z, P-to: $y) isa P;
* ->
* (P-from: $z, P-to: $y) isa P;
*
* 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 [1, N]
* j e [1, N]
*/
@Test
public void testTransitiveMatrixLinear() {
final int N = 10;
final int limit = 100;
LOG.debug(new Object() {
}.getClass().getEnclosingMethod().getName());
// DJ IC FO
// results @N = 15 14400 3-5s
// results @N = 20 44100 15s 8 s 8s
// results @N = 25 105625 48s 27 s 31s
// results @N = 30 216225 132s 65 s
SampleKBContext kb = LinearTransitivityMatrixKB.context(N, N);
String queryString = "match (P-from: $x, P-to: $y) isa P; get;";
executeQuery(queryString, kb.tx(), "full");
executeQuery(kb.tx().graql().<GetQuery>parse(queryString).match().limit(limit).get(), "limit " + limit);
}
use of ai.grakn.test.rule.SampleKBContext in project grakn by graknlabs.
the class BenchmarkTests method testTransitiveChain.
/**
* single-rule transitivity test with initial data arranged in a chain of length N
* 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 neighbouring grid points are related in the following fashion:
*
* a_{i} - Q - a_{i + 1}
*
* i e [0, N)
*/
@Test
public void testTransitiveChain() {
final int N = 100;
final int limit = 10;
final int answers = (N + 1) * N / 2;
LOG.debug(new Object() {
}.getClass().getEnclosingMethod().getName());
SampleKBContext kb = TransitivityChainKB.context(N);
QueryBuilder iqb = kb.tx().graql().infer(true).materialise(false);
String queryString = "match (Q-from: $x, Q-to: $y) isa Q; get;";
GetQuery query = iqb.parse(queryString);
String queryString2 = "match (Q-from: $x, Q-to: $y) isa Q;$x has index 'a'; get;";
GetQuery query2 = iqb.parse(queryString2);
assertEquals(executeQuery(query, "full").size(), answers);
assertEquals(executeQuery(query2, "With specific resource").size(), N);
executeQuery(query.match().limit(limit).get(), "limit " + limit);
executeQuery(query2.match().limit(limit).get(), "limit " + limit);
}
Aggregations