use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class InsertQueryTest method whenInsertingMultipleRolePlayers_BothRolePlayersAreAdded.
@Test
public void whenInsertingMultipleRolePlayers_BothRolePlayersAreAdded() {
List<Answer> results = qb.match(var("g").has("title", "Godfather"), var("m").has("title", "The Muppets")).insert(var("c").isa("cluster").has("name", "2"), var("r").rel("cluster-of-production", "c").rel("production-with-cluster", "g").rel("production-with-cluster", "m").isa("has-cluster")).execute();
Thing cluster = results.get(0).get("c").asThing();
Thing godfather = results.get(0).get("g").asThing();
Thing muppets = results.get(0).get("m").asThing();
Relationship relationship = results.get(0).get("r").asRelationship();
Role clusterOfProduction = movieKB.tx().getRole("cluster-of-production");
Role productionWithCluster = movieKB.tx().getRole("production-with-cluster");
assertEquals(relationship.rolePlayers().collect(toSet()), ImmutableSet.of(cluster, godfather, muppets));
assertEquals(relationship.rolePlayers(clusterOfProduction).collect(toSet()), ImmutableSet.of(cluster));
assertEquals(relationship.rolePlayers(productionWithCluster).collect(toSet()), ImmutableSet.of(godfather, muppets));
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class GraqlPrinterTest method testEmptyResult.
@Test
public void testEmptyResult() {
Printer printer = Printers.graql(true);
Answer emptyResult = new QueryAnswer();
assertEquals("{}", printer.graqlString(emptyResult));
}
use of ai.grakn.graql.admin.Answer 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.admin.Answer 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.admin.Answer in project grakn by graknlabs.
the class QueryCacheTest method getUpdateRetrieveAnswerStream.
@Test
public void getUpdateRetrieveAnswerStream() {
QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
Answer answer = recordQuery.getQuery().stream().findFirst().orElse(null);
Answer retrieveAnswer = answer.unify(recordToRetrieveUnifier);
Answer retrieveSingleAnswer = singleAnswer.unify(recordToRetrieveUnifier);
Stream<Answer> recordStream = cache.getAnswerStream(recordQuery);
Stream<Answer> retrieveStream = cache.getAnswerStream(retrieveQuery);
cache.recordAnswer(recordQuery, singleAnswer);
QueryAnswers recordAnswers = new QueryAnswers(recordStream.collect(Collectors.toSet()));
QueryAnswers retrieveAnswers = new QueryAnswers(retrieveStream.collect(Collectors.toSet()));
// NB: not expecting the update in the stream
assertTrue(recordAnswers.contains(answer));
assertTrue(retrieveAnswers.contains(retrieveAnswer));
assertFalse(recordAnswers.contains(singleAnswer));
assertFalse(retrieveAnswers.contains(retrieveSingleAnswer));
assertTrue(cache.getAnswers(recordQuery).contains(singleAnswer));
assertTrue(cache.getAnswers(retrieveQuery).contains(retrieveSingleAnswer));
}
Aggregations