Search in sources :

Example 61 with GetQuery

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

the class QueryBuilderTest method whenBuildingMatchWithGraphLast_ItExecutes.

@Test
public void whenBuildingMatchWithGraphLast_ItExecutes() {
    GetQuery query = match(x.isa("movie")).withTx(movieKB.tx()).get();
    assertThat(query, variable(x, containsAllMovies));
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 62 with GetQuery

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

the class ExplanationTest method testExplanationConsistency.

@Test
public void testExplanationConsistency() {
    GraknTx genealogyGraph = genealogyKB.tx();
    final long limit = 3;
    QueryBuilder iqb = genealogyGraph.graql().infer(true);
    String queryString = "match " + "($x, $y) isa cousins;" + "limit " + limit + ";" + "get;";
    List<Answer> answers = iqb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), limit);
    answers.forEach(answer -> {
        testExplanation(answer);
        String specificQuery = "match " + "$x id '" + answer.get(var("x")).getId().getValue() + "';" + "$y id '" + answer.get(var("y")).getId().getValue() + "';" + "(cousin: $x, cousin: $y) isa cousins;" + "limit 1; get;";
        Answer specificAnswer = Iterables.getOnlyElement(iqb.<GetQuery>parse(specificQuery).execute());
        assertEquals(answer, specificAnswer);
        testExplanation(specificAnswer);
    });
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 63 with GetQuery

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

the class ExplanationTest method testExplainingConjunctiveQueryWithTwoIdPredicates.

@Test
public void testExplainingConjunctiveQueryWithTwoIdPredicates() {
    String queryString = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "(geo-entity: $y, entity-location: $z) isa is-located-in;" + "$x id '" + polibuda.getId() + "';" + "$z id '" + masovia.getId() + "';" + "get $y;";
    GetQuery query = iqb.parse(queryString);
    List<Answer> answers = query.execute();
    assertEquals(answers.size(), 1);
    testExplanation(answers);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 64 with GetQuery

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

the class QueryValidityTest method whenQueryingForInexistentRelationTypeId_emptyResultReturned.

@Test
public void whenQueryingForInexistentRelationTypeId_emptyResultReturned() {
    QueryBuilder qb = testContext.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa $type; $type id 'V123'; get;";
    String queryString2 = "match $r ($x, $y) isa $type; $r id 'V123'; get;";
    assertThat(qb.<GetQuery>parse(queryString).execute(), empty());
    assertThat(qb.<GetQuery>parse(queryString2).execute(), empty());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 65 with GetQuery

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

the class QueryValidityTest method whenQueryingForIllegalRolePlayer_emptyResultReturned.

@Test
public void whenQueryingForIllegalRolePlayer_emptyResultReturned() {
    QueryBuilder qb = testContext.tx().graql().infer(true);
    String queryString = "match ($x, $y) isa binary; $x isa anotherNoRoleEntity; get;";
    assertThat(qb.<GetQuery>parse(queryString).execute(), empty());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Aggregations

GetQuery (ai.grakn.graql.GetQuery)163 Test (org.junit.Test)161 Answer (ai.grakn.graql.admin.Answer)65 QueryBuilder (ai.grakn.graql.QueryBuilder)61 GraknTx (ai.grakn.GraknTx)51 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)23 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)12 Concept (ai.grakn.concept.Concept)9 List (java.util.List)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Set (java.util.Set)6 Label (ai.grakn.concept.Label)5 RelationshipType (ai.grakn.concept.RelationshipType)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)5 Sets (com.google.common.collect.Sets)5 Collectors (java.util.stream.Collectors)5 Collectors.toSet (java.util.stream.Collectors.toSet)5