use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class RecursiveInferenceTest method testAncestor.
/*single-directional*/
/**
*from Bancilhon - An Amateur's Introduction to Recursive Query Processing Strategies p. 25
*/
@Test
public void testAncestor() {
QueryBuilder qb = ancestorContext.tx().graql().infer(false);
QueryBuilder iqb = ancestorContext.tx().graql().infer(true);
String queryString = "match (ancestor: $X, descendant: $Y) isa Ancestor;$X has name 'aa';" + "$Y has name $name;get $Y, $name;";
String explicitQuery = "match $Y isa person, has name $name;" + "{$name val 'aaa';} or {$name val 'aab';} or {$name val 'aaaa';};get $Y, $name;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class RecursiveInferenceTest method testNguyen.
/**
*test3 from Nguyen (similar to test 6.5 from Cao)
* N(x, y) :- R(x, y)
* N(x, y) :- P(x, z), N(z, w), Q(w, y)
*
* c -- P -- d -- R -- e -- Q -- a0
* \ /
* P Q
* \ \ /
* b0 -- Q -- a1
* \ /
* P Q
* \ /
* b1 -- Q -- a2
* .
* .
* .
* bN -- Q -- aN+1
*/
@Test
public void testNguyen() {
final int N = 9;
SampleKBContext kb = NguyenKB.context(N);
QueryBuilder qb = kb.tx().graql().infer(false);
QueryBuilder iqb = kb.tx().graql().infer(true);
String queryString = "match (N-rA: $x, N-rB: $y) isa N; $x has index 'c'; get $y;";
String explicitQuery = "match $y isa a-entity; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> explicitAnswers = qb.<GetQuery>parse(explicitQuery).execute();
assertCollectionsEqual(answers, explicitAnswers);
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class RecursiveInferenceTest method testAncestorFriend__secondVariantPrime.
/**
*from Vieille - Recursive Axioms in Deductive Databases (QSQ approach) p. 186
*/
@Test
public void testAncestorFriend__secondVariantPrime() {
QueryBuilder qb = ancestorFriendContext.tx().graql().infer(false);
QueryBuilder iqb = ancestorFriendContext.tx().graql().infer(true);
String queryString = "match ($X, $Y) isa Ancestor-friend;$Y has name 'd'; get $X;";
String explicitQuery = "match $X has name $name;" + "{$name val 'a';} or {$name val 'b';} or {$name val 'c';}; get $X;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class RecursiveInferenceTest method testSameGenerationCao.
/**
*test 6.6 from Cao p.76
*/
@Test
public void testSameGenerationCao() {
QueryBuilder qb = sameGenerationContext.tx().graql().infer(false);
QueryBuilder iqb = sameGenerationContext.tx().graql().infer(true);
String queryString = "match ($x, $y) isa SameGen;$x has name 'ann';get $y;";
String explicitQuery = "match $y has name $name;" + "{$name val 'ann';} or {$name val 'bill';} or {$name val 'peter';};get $y;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class AdmissionsInferenceTest method testProvisionalAdmission.
@Test
public void testProvisionalAdmission() {
QueryBuilder qb = admissionsKB.tx().graql().infer(false);
QueryBuilder iqb = admissionsKB.tx().graql().infer(true);
String queryString = "match $x isa applicant;$x has admissionStatus 'provisional'; get;";
String explicitQuery = "match $x isa applicant, has name 'Denis'; get;";
assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Aggregations