Search in sources :

Example 96 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class AdmissionsInferenceTest method testAdmissions.

@Test
public void testAdmissions() {
    QueryBuilder qb = admissionsKB.tx().graql().infer(false);
    QueryBuilder iqb = admissionsKB.tx().graql().infer(true);
    String queryString = "match $x has admissionStatus $y;$x has name $name; get;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(queryString));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(queryString));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 97 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class RecursiveInferenceTest method testDualLinearTransitivityMatrix.

/**
 * test 6.1 from Cao p 71
 */
@Test
public void testDualLinearTransitivityMatrix() {
    final int N = 5;
    SampleKBContext kb = DualLinearTransitivityMatrixKB.context(N, N);
    QueryBuilder qb = kb.tx().graql().infer(false);
    QueryBuilder iqb = kb.tx().graql().infer(true);
    String queryString = "match (Q1-from: $x, Q1-to: $y) isa Q1; $x has index 'a0'; get $y;";
    String explicitQuery = "match $y isa a-entity or $y isa end; 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 98 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class RecursiveInferenceTest method testAncestorPrime.

/**
 *as above but both directions
 */
@Test
public void testAncestorPrime() {
    QueryBuilder qb = ancestorContext.tx().graql().infer(false);
    QueryBuilder iqb = ancestorContext.tx().graql().infer(true);
    String queryString = "match ($X, $Y) isa Ancestor;$X has name 'aa'; get $Y;";
    String explicitQuery = "match $Y isa person, has name $name;" + "{$name val 'a';} or {$name val 'aaa';} or {$name val 'aab';} or {$name val 'aaaa';};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 99 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class RecursiveInferenceTest method testAncestorFriendPrime.

/**
 *from Vieille - Recursive Axioms in Deductive Databases (QSQ approach) p. 186
 */
@Test
public void testAncestorFriendPrime() {
    QueryBuilder qb = ancestorFriendContext.tx().graql().infer(false);
    QueryBuilder iqb = ancestorFriendContext.tx().graql().infer(true);
    String queryString = "match ($X, $Y) isa Ancestor-friend;$X has name 'a'; get $Y;";
    String explicitQuery = "match $Y has name $name;{$name val 'd';} or {$name val 'g';}; 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 100 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class RecursiveInferenceTest method testReverseSameGeneration2.

@Test
public void testReverseSameGeneration2() {
    QueryBuilder qb = recursivityRSGContext.tx().graql().infer(false);
    QueryBuilder iqb = recursivityRSGContext.tx().graql().infer(true);
    String queryString = "match (RSG-from: $x, RSG-to: $y) isa RevSG; get;";
    String explicitQuery = "match $x has name $nameX;$y has name $nameY;" + "{$nameX val 'a';$nameY val 'b';} or {$nameX val 'a';$nameY val 'c';} or" + "{$nameX val 'a';$nameY val 'd';} or {$nameX val 'm';$nameY val 'n';} or" + "{$nameX val 'm';$nameY val 'o';} or {$nameX val 'p';$nameY val 'm';} or" + "{$nameX val 'g';$nameY val 'f';} or {$nameX val 'h';$nameY val 'f';} or" + "{$nameX val 'i';$nameY val 'f';} or {$nameX val 'j';$nameY val 'f';} or" + "{$nameX val 'f';$nameY val 'k';};get $x, $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)

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