Search in sources :

Example 36 with Role

use of ai.grakn.concept.Role 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();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 37 with Role

use of ai.grakn.concept.Role 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();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 38 with Role

use of ai.grakn.concept.Role 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();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 39 with Role

use of ai.grakn.concept.Role 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();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 40 with Role

use of ai.grakn.concept.Role 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();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Aggregations

Role (ai.grakn.concept.Role)189 Test (org.junit.Test)124 RelationshipType (ai.grakn.concept.RelationshipType)114 EntityType (ai.grakn.concept.EntityType)92 Entity (ai.grakn.concept.Entity)55 GraknTx (ai.grakn.GraknTx)48 Relationship (ai.grakn.concept.Relationship)37 Set (java.util.Set)36 ConceptId (ai.grakn.concept.ConceptId)33 Label (ai.grakn.concept.Label)33 Thing (ai.grakn.concept.Thing)32 HashSet (java.util.HashSet)31 Var (ai.grakn.graql.Var)25 AttributeType (ai.grakn.concept.AttributeType)21 Concept (ai.grakn.concept.Concept)20 Schema (ai.grakn.util.Schema)17 Collectors (java.util.stream.Collectors)17 Attribute (ai.grakn.concept.Attribute)16 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Type (ai.grakn.concept.Type)16