use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class MatchTest method testGraqlPlaysSemanticsMatchGraphAPI.
@Test
public void testGraqlPlaysSemanticsMatchGraphAPI() {
GraknTx tx = emptyKB.tx();
QueryBuilder qb = tx.graql();
Label a = Label.of("a");
Label b = Label.of("b");
Label c = Label.of("c");
Label d = Label.of("d");
Label e = Label.of("e");
Label f = Label.of("f");
qb.define(Graql.label(c).sub(Graql.label(b).sub(Graql.label(a).sub("entity"))), Graql.label(f).sub(Graql.label(e).sub(Graql.label(d).sub("role"))), Graql.label(b).plays(Graql.label(e))).execute();
Stream.of(a, b, c, d, e, f).forEach(type -> {
Set<Concept> graqlPlays = qb.match(Graql.label(type).plays(x)).get(x).collect(Collectors.toSet());
Collection<Role> graphAPIPlays;
SchemaConcept schemaConcept = tx.getSchemaConcept(type);
if (schemaConcept.isType()) {
graphAPIPlays = schemaConcept.asType().plays().collect(toSet());
} else {
graphAPIPlays = Collections.EMPTY_SET;
}
assertEquals(graqlPlays, graphAPIPlays);
});
Stream.of(d, e, f).forEach(type -> {
Set<Concept> graqlPlayedBy = qb.match(x.plays(Graql.label(type))).get(x).collect(toSet());
Collection<Type> graphAPIPlayedBy = tx.<Role>getSchemaConcept(type).playedByTypes().collect(toSet());
assertEquals(graqlPlayedBy, graphAPIPlayedBy);
});
}
use of ai.grakn.graql.QueryBuilder 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.QueryBuilder in project grakn by graknlabs.
the class QueryValidityTest method whenQueryingForMismatchedRelationTypeLabel_Throws.
@Test
public void whenQueryingForMismatchedRelationTypeLabel_Throws() throws GraqlQueryException {
QueryBuilder qb = testContext.tx().graql().infer(true);
String queryString = "match ($x, $y) isa name; get;";
expectedException.expect(GraqlQueryException.class);
qb.<GetQuery>parse(queryString).execute();
}
use of ai.grakn.graql.QueryBuilder 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.QueryBuilder 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