use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenCreatingRelationWithoutLinkingRelates_Throw.
@Test
public void whenCreatingRelationWithoutLinkingRelates_Throw() {
Role hunter = tx.putRole("hunter");
Role monster = tx.putRole("monster");
EntityType stuff = tx.putEntityType("Stuff").plays(hunter).plays(monster);
RelationshipType kills = tx.putRelationshipType("kills").relates(hunter);
Entity myHunter = stuff.addEntity();
Entity myMonster = stuff.addEntity();
Relationship relation = kills.addRelationship().addRolePlayer(hunter, myHunter).addRolePlayer(monster, myMonster);
expectedException.expect(InvalidKBException.class);
expectedException.expectMessage(containsString(ErrorMessage.VALIDATION_RELATION_CASTING_LOOP_FAIL.getMessage(relation.getId(), monster.getLabel(), kills.getLabel())));
tx.commit();
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw1.
@Test
public void whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw1() throws InvalidKBException {
Role parent = tx.putRole("parent");
Role child = tx.putRole("child");
EntityType person = tx.putEntityType("person").plays(parent).plays(child);
EntityType man = tx.putEntityType("man");
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
Entity x = man.addEntity();
Entity y = person.addEntity();
parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
expectedException.expect(InvalidKBException.class);
expectedException.expectMessage(ErrorMessage.VALIDATION_CASTING.getMessage(man.getLabel(), x.getId(), parent.getLabel()));
tx.commit();
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenCommittingWithRoleTypeHierarchy_EnsureInstancesCanPlayRelevantRoles1.
/*-------------------------------- Entity Type to Role Type Validation (Data) ------------------------------------*/
@Test
public void whenCommittingWithRoleTypeHierarchy_EnsureInstancesCanPlayRelevantRoles1() throws InvalidKBException {
Role parent = tx.putRole("parent");
Role child = tx.putRole("child");
EntityType person = tx.putEntityType("person").plays(parent).plays(child);
EntityType man = tx.putEntityType("man").sup(person);
EntityType oneEyedMan = tx.putEntityType("oneEyedMan").sup(man);
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
Entity x = oneEyedMan.addEntity();
Entity y = person.addEntity();
parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
tx.commit();
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenARoleInARelationIsPlayedAZillionTimes_TheGraphIsValid.
@Test
public void whenARoleInARelationIsPlayedAZillionTimes_TheGraphIsValid() {
Role role1 = tx.putRole("role-1");
Role role2 = tx.putRole("role-2");
RelationshipType relationshipType = tx.putRelationshipType("my-relationship").relates(role1).relates(role2);
EntityType entityType = tx.putEntityType("my-entity").plays(role1);
Relationship relationship = relationshipType.addRelationship();
Set<Thing> things = new HashSet<>();
int oneZillion = 100;
for (int i = 0; i < oneZillion; i++) {
Thing thing = entityType.addEntity();
things.add(thing);
relationship.addRolePlayer(role1, thing);
}
assertEquals(things, relationship.rolePlayers(role1).collect(toSet()));
tx.commit();
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidatorTest method whenRemovingInvalidRolePlayers_EnsureValidationPasses.
@Test
public void whenRemovingInvalidRolePlayers_EnsureValidationPasses() {
Role chased = tx.putRole("chased");
Role chaser = tx.putRole("chaser");
RelationshipType chases = tx.putRelationshipType("chases").relates(chased).relates(chaser);
EntityType puppy = tx.putEntityType("puppy").plays(chaser);
Entity dunstan = puppy.addEntity();
Relationship rel = chases.addRelationship();
rel.addRolePlayer(chaser, dunstan);
rel.addRolePlayer(chased, dunstan).removeRolePlayer(chased, dunstan);
tx.commit();
}
Aggregations