use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testValidatePlaysStructureUnique.
@Test
public void testValidatePlaysStructureUnique() {
Role role1 = tx.putRole("role1");
Role role2 = tx.putRole("role2");
RelationshipType relationshipType = tx.putRelationshipType("rt").relates(role1).relates(role2);
EntityType entityType = tx.putEntityType("et");
((EntityTypeImpl) entityType).plays(role1, true);
((EntityTypeImpl) entityType).plays(role2, false);
Entity other1 = entityType.addEntity();
Entity other2 = entityType.addEntity();
EntityImpl entity = (EntityImpl) entityType.addEntity();
RelationshipImpl relation1 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other1).addRolePlayer(role1, entity);
// Valid with only a single relation
relation1.reified().get().castingsRelation().forEach(rolePlayer -> assertTrue(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
RelationshipImpl relation2 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other2).addRolePlayer(role1, entity);
// Invalid with multiple relations
relation1.reified().get().castingsRelation().forEach(rolePlayer -> {
if (rolePlayer.getRole().equals(role1)) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
}
});
relation2.reified().get().castingsRelation().forEach(rolePlayer -> {
if (rolePlayer.getRole().equals(role1)) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
}
});
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testValidatePlaysStructure.
@Test
public void testValidatePlaysStructure() throws Exception {
EntityTypeImpl wolf = (EntityTypeImpl) tx.putEntityType("wolf");
EntityTypeImpl creature = (EntityTypeImpl) tx.putEntityType("creature");
EntityTypeImpl hunter = (EntityTypeImpl) tx.putEntityType("hunter");
RelationshipType hunts = tx.putRelationshipType("hunts");
RoleImpl witcher = (RoleImpl) tx.putRole("witcher");
RoleImpl monster = (RoleImpl) tx.putRole("monster");
Thing geralt = hunter.addEntity();
ThingImpl werewolf = (ThingImpl) wolf.addEntity();
RelationshipImpl assertion = (RelationshipImpl) hunts.addRelationship().addRolePlayer(witcher, geralt).addRolePlayer(monster, werewolf);
assertion.reified().get().castingsRelation().forEach(rolePlayer -> assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
hunter.plays(witcher);
boolean[] flags = { false, false };
int count = 0;
for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
flags[count] = !ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty();
count++;
}
assertTrue(flags[0] && flags[1]);
wolf.sup(creature);
creature.plays(monster);
for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty());
}
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testAbstractConceptValidation.
@Test
public void testAbstractConceptValidation() {
Role role = tx.putRole("relates");
RelationshipType relationshipType = tx.putRelationshipType("relationTypes");
assertTrue(ValidateGlobalRules.validateHasSingleIncomingRelatesEdge(role).isPresent());
assertTrue(ValidateGlobalRules.validateHasMinimumRoles(relationshipType).isPresent());
relationshipType.setAbstract(true);
assertTrue(ValidateGlobalRules.validateHasSingleIncomingRelatesEdge(role).isPresent());
assertFalse(ValidateGlobalRules.validateHasMinimumRoles(relationshipType).isPresent());
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testValidateRelationTypeRelates.
@Test
public void testValidateRelationTypeRelates() throws Exception {
Role hunter = tx.putRole("hunter");
RelationshipType kills = tx.putRelationshipType("kills");
assertTrue(ValidateGlobalRules.validateHasMinimumRoles(kills).isPresent());
kills.relates(hunter);
assertFalse(ValidateGlobalRules.validateHasMinimumRoles(kills).isPresent());
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class GraknTxTest method whenGettingSubTypesFromRootMeta_IncludeAllTypes.
@Test
public void whenGettingSubTypesFromRootMeta_IncludeAllTypes() {
EntityType sampleEntityType = tx.putEntityType("Sample Entity Type");
RelationshipType sampleRelationshipType = tx.putRelationshipType("Sample Relationship Type");
assertThat(tx.getMetaConcept().subs().collect(toSet()), containsInAnyOrder(tx.getMetaConcept(), tx.getMetaRelationType(), tx.getMetaEntityType(), tx.getMetaAttributeType(), sampleEntityType, sampleRelationshipType));
}
Aggregations