use of ai.grakn.concept.RelationshipType 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.RelationshipType in project grakn by graknlabs.
the class ValidatorTest method whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes2.
@Test
public void whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes2() throws InvalidKBException {
Role relative = tx.putRole("relative");
Role parent = tx.putRole("parent").sup(relative);
Role father = tx.putRole("father").sup(parent);
Role mother = tx.putRole("mother").sup(parent);
Role pChild = tx.putRole("pChild").sup(relative);
Role fmChild = tx.putRole("fChild").sup(pChild);
// This is to bypass a specific validation rule
tx.putRelationshipType("filler").relates(relative);
tx.putEntityType("animal").plays(relative).plays(parent).plays(father).plays(mother).plays(pChild).plays(fmChild);
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(pChild);
tx.putRelationshipType("fathermotherhood").sup(parenthood).relates(father).relates(mother).relates(fmChild);
tx.commit();
}
use of ai.grakn.concept.RelationshipType 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.RelationshipType in project grakn by graknlabs.
the class ValidatorTest method whenCreatingRelationWithSubTypeHierarchyAndNoMatchingRoleTypeHierarchy_Throw1.
@Test
public void whenCreatingRelationWithSubTypeHierarchyAndNoMatchingRoleTypeHierarchy_Throw1() throws InvalidKBException {
Role pChild = tx.putRole("pChild");
Role fChild = tx.putRole("fChild").sup(pChild);
Role parent = tx.putRole("parent");
Role father = tx.putRole("father").sup(parent);
Role inContext = tx.putRole("in-context");
tx.putEntityType("animal").plays(parent).plays(father).plays(pChild).plays(fChild);
tx.putEntityType("context").plays(inContext);
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(pChild);
RelationshipType fatherhood = tx.putRelationshipType("fatherhood").sup(parenthood).relates(father).relates(fChild).relates(inContext);
expectedException.expect(InvalidKBException.class);
expectedException.expectMessage(ErrorMessage.VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(inContext.getLabel(), fatherhood.getLabel(), "super", "super", parenthood.getLabel()));
tx.commit();
}
use of ai.grakn.concept.RelationshipType 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