Search in sources :

Example 31 with EntityType

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

Example 32 with EntityType

use of ai.grakn.concept.EntityType 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 33 with EntityType

use of ai.grakn.concept.EntityType 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 34 with EntityType

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

Example 35 with EntityType

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

Aggregations

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7