use of ai.grakn.GraknTx 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());
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfMetaRelation.
@Test
public void allInstancesOfMetaRelation() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa relationship;get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 13);
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfTypesThatPlayGivenRole.
/**
* PlaysAtom *
*/
@Test
public void allInstancesOfTypesThatPlayGivenRole() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type plays role1; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
List<Answer> reifiableRelations = qb.<GetQuery>parse("match $x isa reifiable-relation;get;").execute();
assertEquals(answers.size(), tx.getEntityType("noRoleEntity").subs().flatMap(EntityType::instances).count() + reifiableRelations.size());
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class OntologicalQueryTest method allTypesOfRolePlayerInASpecificRelationWithUnspecifiedRoles.
@Test
public void allTypesOfRolePlayerInASpecificRelationWithUnspecifiedRoles() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match ($x, $y) isa reifiable-relation;$x isa $type; get;";
// 3 instances * {anotherTwoRoleEntity, anotherSingleRoleEntity, noRoleEntity, entity, Thing} * arity
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), qb.<GetQuery>parse("match $x isa reifiable-relation; get;").stream().count() * 5 * 2);
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfRelationsThatRelateGivenRole.
/**
* RelatesAtom *
*/
@Test
public void allInstancesOfRelationsThatRelateGivenRole() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
String queryString = "match $x isa $type; $type relates role1; get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
List<Answer> relations = qb.<GetQuery>parse("match $x isa relationship;get;").execute();
// plus extra 3 cause there are 3 binary relations which are not extra counted as reifiable-relations
assertEquals(answers.size(), relations.stream().filter(ans -> !ans.get("x").asRelationship().type().isImplicit()).count() + 3);
}
Aggregations