use of ai.grakn.concept.Role in project grakn by graknlabs.
the class TypePropertyTest method whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole.
@Property
public void whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole(@NonMeta Type type, long seed) {
Role role = PropertyUtil.choose(type.sup() + " plays no roles", type.sup().plays().collect(toSet()), seed);
type.deletePlays(role);
assertThat(type.plays().collect(toSet()), hasItem(role));
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class ValidatorTest method whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes3.
@Test
public void whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes3() throws InvalidKBException {
Role relative = tx.putRole("relative");
Role parent = tx.putRole("parent").sup(relative);
Role father = tx.putRole("father").sup(parent);
Role pChild = tx.putRole("pChild").sup(relative);
Role fChild = tx.putRole("fChild").sup(pChild);
tx.putEntityType("animal").plays(relative).plays(parent).plays(father).plays(pChild).plays(fChild);
RelationshipType parentrelativehood = tx.putRelationshipType("parentrelativehood").relates(relative).relates(parent).relates(pChild);
tx.putRelationshipType("fatherhood").sup(parentrelativehood).relates(father).relates(fChild);
tx.commit();
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class ValidatorTest method whenCreatingAbstractRelationshipWithSubType_EnsureValidationRuleForMatchingSubRolesIsSkipped.
@Test
public void whenCreatingAbstractRelationshipWithSubType_EnsureValidationRuleForMatchingSubRolesIsSkipped() {
Role role1 = tx.putRole("my role");
Role role2 = tx.putRole("my role 2");
RelationshipType abstractRelationType = tx.putRelationshipType("my abstract relation type").relates(role1).setAbstract(true);
tx.putRelationshipType("my relation type").sup(abstractRelationType).relates(role2);
tx.commit();
}
use of ai.grakn.concept.Role in project grakn by graknlabs.
the class ValidatorTest method whenCommittingGraphWhichFollowsValidationRules_Commit.
@Test
public void whenCommittingGraphWhichFollowsValidationRules_Commit() {
RelationshipType cast = tx.putRelationshipType("Cast");
Role feature = tx.putRole("Feature");
Role actor = tx.putRole("Actor");
EntityType movie = tx.putEntityType("Movie");
EntityType person = tx.putEntityType("Person");
Thing pacino = person.addEntity();
Thing godfather = movie.addEntity();
EntityType genre = tx.putEntityType("Genre");
Role movieOfGenre = tx.putRole("Movie of Genre");
Role movieGenre = tx.putRole("Movie Genre");
Thing crime = genre.addEntity();
RelationshipType movieHasGenre = tx.putRelationshipType("Movie Has Genre");
// Construction
cast.relates(feature);
cast.relates(actor);
cast.addRelationship().addRolePlayer(feature, godfather).addRolePlayer(actor, pacino);
movieHasGenre.addRelationship().addRolePlayer(movieOfGenre, godfather).addRolePlayer(movieGenre, crime);
movieHasGenre.relates(movieOfGenre);
movieHasGenre.relates(movieGenre);
movie.plays(movieOfGenre);
person.plays(actor);
movie.plays(feature);
genre.plays(movieGenre);
tx.commit();
}
use of ai.grakn.concept.Role 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();
}
Aggregations