use of ai.grakn.concept.RelationshipType 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.RelationshipType 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.RelationshipType in project grakn by graknlabs.
the class ValidatorTest method whenCreatingRelationWithSubTypeHierarchyAndNoMatchingRoleTypeHierarchy_Throw2.
@Test
public void whenCreatingRelationWithSubTypeHierarchyAndNoMatchingRoleTypeHierarchy_Throw2() throws InvalidKBException {
Role parent = tx.putRole("parent");
Role father = tx.putRole("father").sup(parent);
Role pChild = tx.putRole("pChild");
Role fChild = tx.putRole("fChild").sup(pChild);
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).relates(inContext);
RelationshipType fatherhood = tx.putRelationshipType("fatherhood").sup(parenthood).relates(father).relates(fChild);
expectedException.expect(InvalidKBException.class);
expectedException.expectMessage(ErrorMessage.VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(inContext.getLabel(), parenthood.getLabel(), "sub", "sub", fatherhood.getLabel()));
tx.commit();
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidatorTest method whenARoleInARelationIsNotPlayed_TheGraphIsValid.
@Test
public void whenARoleInARelationIsNotPlayed_TheGraphIsValid() {
Role role1 = tx.putRole("role-1");
Role role2 = tx.putRole("role-2");
RelationshipType relationshipType = tx.putRelationshipType("my-relation").relates(role1).relates(role2);
Thing thing = tx.putEntityType("my-entity").plays(role1).addEntity();
relationshipType.addRelationship().addRolePlayer(role1, thing);
tx.commit();
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ValidatorTest method whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes1.
/*------------------------------- Relationship Type to Role Type Validation (Schema) ---------------------------------*/
@Test
public void whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes1() 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 fChild = tx.putRole("fChild").sup(pChild);
Role mChild = tx.putRole("mChild").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(fChild).plays(mChild);
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(pChild);
tx.putRelationshipType("fatherhood").sup(parenthood).relates(father).relates(fChild);
tx.putRelationshipType("motherhood").sup(parenthood).relates(mother).relates(mChild);
tx.commit();
}
Aggregations