use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class AtomicTest method testUnification_ParentHasFewerRelationPlayers.
@Test
public void testUnification_ParentHasFewerRelationPlayers() {
EmbeddedGraknTx<?> graph = unificationTestSet.tx();
String childString = "{(subRole1: $y, subRole2: $x) isa binary;}";
String parentString = "{(subRole1: $x) isa binary;}";
String parentString2 = "{(subRole2: $y) isa binary;}";
ReasonerAtomicQuery childQuery = ReasonerQueries.atomic(conjunction(childString, graph), graph);
ReasonerAtomicQuery parentQuery = ReasonerQueries.atomic(conjunction(parentString, graph), graph);
ReasonerAtomicQuery parentQuery2 = ReasonerQueries.atomic(conjunction(parentString2, graph), graph);
Atom childAtom = childQuery.getAtom();
Atom parentAtom = parentQuery.getAtom();
Atom parentAtom2 = parentQuery2.getAtom();
List<Answer> childAnswers = childQuery.getQuery().execute();
List<Answer> parentAnswers = parentQuery.getQuery().execute();
List<Answer> parentAnswers2 = parentQuery2.getQuery().execute();
Unifier unifier = childAtom.getUnifier(parentAtom);
Unifier unifier2 = childAtom.getUnifier(parentAtom2);
assertCollectionsEqual(parentAnswers, childAnswers.stream().map(a -> a.unify(unifier)).map(a -> a.project(parentQuery.getVarNames())).distinct().collect(Collectors.toList()));
assertCollectionsEqual(parentAnswers2, childAnswers.stream().map(a -> a.unify(unifier2)).map(a -> a.project(parentQuery2.getVarNames())).distinct().collect(Collectors.toList()));
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingRelationVariableWithMaterialisation_requeryingDoesntCreateDuplicates.
@Test
public void testReasoningWithQueryContainingRelationVariableWithMaterialisation_requeryingDoesntCreateDuplicates() {
String queryString = "match $x isa is-located-in; get;";
String queryString2 = "match $x (geo-entity: $x1, entity-location: $x2) isa is-located-in; get $x;";
String queryString3 = "match $x ($x1, $x2) isa is-located-in; get $x;";
GetQuery query = geoKB.tx().graql().infer(true).parse(queryString);
GetQuery query2 = geoKB2.tx().graql().infer(true).parse(queryString2);
GetQuery query3 = geoKB3.tx().graql().infer(true).parse(queryString3);
assertQueriesEqual(query, query2);
assertQueriesEqual(query2, query3);
List<Answer> requeriedAnswers = query.execute();
List<Answer> requeriedAnswers2 = query2.execute();
List<Answer> requeriedAnswers3 = query3.execute();
assertCollectionsEqual(requeriedAnswers, requeriedAnswers2);
assertCollectionsEqual(requeriedAnswers2, requeriedAnswers3);
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingContradiction.
@Test
public void testReasoningWithQueryContainingContradiction() {
GraknTx graph = nonMaterialisedGeoKB.tx();
// geoObject sub city always returns an empty set
String queryString = "match ($x, $y) isa is-located-in;geoObject sub city; get;";
QueryBuilder iqb = graph.graql().infer(true);
List<Answer> answers = iqb.<GetQuery>parse(queryString).execute();
assertThat(answers, empty());
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfTypesThatCanHaveAGivenResourceType.
/**
* HasAtom *
*/
@Test
public void allInstancesOfTypesThatCanHaveAGivenResourceType() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type has name; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
// 1 x noRoleEntity + 3 x 3 (hierarchy) anotherTwoRoleEntities
assertEquals(answers.size(), 10);
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults.
@Test
public void allInstancesOfTypesThatAreSubTypeOfGivenType_needInferenceToGetAllResults() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type sub relationship; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), tx.getRelationshipType("relationship").subs().flatMap(RelationshipType::instances).count());
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
Aggregations