Search in sources :

Example 91 with QueryBuilder

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));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 92 with QueryBuilder

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);
}
Also used : Answer(ai.grakn.graql.admin.Answer) SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 93 with QueryBuilder

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));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 94 with QueryBuilder

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));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 95 with QueryBuilder

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));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Aggregations

QueryBuilder (ai.grakn.graql.QueryBuilder)208 Test (org.junit.Test)202 Answer (ai.grakn.graql.admin.Answer)101 GetQuery (ai.grakn.graql.GetQuery)60 GraknTx (ai.grakn.GraknTx)51 SampleKBContext (ai.grakn.test.rule.SampleKBContext)20 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)18 Concept (ai.grakn.concept.Concept)16 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)9 Ignore (org.junit.Ignore)8 Var (ai.grakn.graql.Var)5 VarPattern (ai.grakn.graql.VarPattern)5 List (java.util.List)5 Label (ai.grakn.concept.Label)4 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)4 Sets (com.google.common.collect.Sets)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 RelationshipType (ai.grakn.concept.RelationshipType)3 Graql (ai.grakn.graql.Graql)3 Graql.var (ai.grakn.graql.Graql.var)3