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));
}
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);
});
}
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);
}
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());
}
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());
}
Aggregations