use of ai.grakn.concept.Entity 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.Entity 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.Entity 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.Entity 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();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class ValidatorTest method whenManuallyCreatingCorrectBinaryRelation_Commit.
@Test
public void whenManuallyCreatingCorrectBinaryRelation_Commit() throws InvalidKBException {
Role characterBeingPlayed = tx.putRole("Character being played");
Role personPlayingCharacter = tx.putRole("Person Playing Char");
RelationshipType playsChar = tx.putRelationshipType("Plays Char").relates(characterBeingPlayed).relates(personPlayingCharacter);
EntityType person = tx.putEntityType("person").plays(characterBeingPlayed).plays(personPlayingCharacter);
EntityType character = tx.putEntityType("character").plays(characterBeingPlayed);
Entity matt = person.addEntity();
Entity walker = character.addEntity();
playsChar.addRelationship().addRolePlayer(personPlayingCharacter, matt).addRolePlayer(characterBeingPlayed, walker);
tx.commit();
}
Aggregations