Search in sources :

Example 31 with QueryBuilder

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

the class TypeInferenceQueryTest method typeInferenceQueries.

private void typeInferenceQueries(List<RelationshipType> possibleTypes, String pattern, EmbeddedGraknTx<?> graph) {
    QueryBuilder qb = graph.graql();
    List<Answer> typedAnswers = typedAnswers(possibleTypes, pattern, graph);
    List<Answer> unTypedAnswers = qb.match(qb.parser().parsePattern(pattern)).get().execute();
    assertEquals(typedAnswers.size(), unTypedAnswers.size());
    GraqlTestUtil.assertCollectionsEqual(typedAnswers, unTypedAnswers);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryBuilder(ai.grakn.graql.QueryBuilder)

Example 32 with QueryBuilder

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

the class CWInferenceTest method testTransactionQuery.

@Test
public void testTransactionQuery() {
    QueryBuilder qb = cwKB2.tx().graql().infer(false);
    String queryString = "match ($t1, $t2, $t3) isa transaction; get;";
    String explicitQuery = "match " + "{$t1 has name 'colonelWest';$t2 has name 'Tomahawk';$t3 has name 'Nono';} or " + "{$t1 has name 'colonelWest';$t3 has name 'Tomahawk';$t2 has name 'Nono';} or " + "{$t2 has name 'colonelWest';$t1 has name 'Tomahawk';$t3 has name 'Nono';} or " + "{$t2 has name 'colonelWest';$t3 has name 'Tomahawk';$t1 has name 'Nono';} or " + "{$t3 has name 'colonelWest';$t2 has name 'Tomahawk';$t1 has name 'Nono';} or " + "{$t3 has name 'colonelWest';$t1 has name 'Tomahawk';$t2 has name 'Nono';};" + "get;";
    assertQueriesEqual(iqb.parse(queryString), qb.parse(explicitQuery));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 33 with QueryBuilder

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

the class GeoInferenceTest method testRelationVarQuery_Closure_withAndWithoutRelationPlayers.

@Test
public void testRelationVarQuery_Closure_withAndWithoutRelationPlayers() {
    QueryBuilder iqb = geoKB.tx().graql().infer(true);
    String queryString = "match $x isa is-located-in; get;";
    String queryString2 = "match $x ($x1, $x2) isa is-located-in;get $x;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
    List<Answer> answers3 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
    List<Answer> answers4 = iqb.materialise(true).<GetQuery>parse(queryString2).execute();
    assertCollectionsEqual(answers, answers2);
    assertCollectionsEqual(answers3, answers4);
    assertEquals(answers.size(), 51);
    assertEquals(answers3.size(), 51);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 34 with QueryBuilder

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

the class GeoInferenceTest method testTransitiveQuery_Closure_NoRoles.

@Test
public void testTransitiveQuery_Closure_NoRoles() {
    QueryBuilder iqb = geoKB.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa is-located-in; get;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 102);
    assertCollectionsEqual(answers, answers2);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 35 with QueryBuilder

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

the class GeoInferenceTest method testTransitiveQuery_Closure_singleVariableRole.

@Test
public void testTransitiveQuery_Closure_singleVariableRole() {
    QueryBuilder iqb = geoKB.tx().graql().infer(true);
    String queryString = "match ($x, $r2: $y) isa is-located-in; get;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
    answers.forEach(ans -> assertEquals(ans.size(), 3));
    assertEquals(answers.size(), 204);
    answers2.forEach(ans -> assertEquals(ans.size(), 3));
    assertCollectionsEqual(answers, answers2);
}
Also used : Answer(ai.grakn.graql.admin.Answer) 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