Search in sources :

Example 31 with Entity

use of ai.grakn.concept.Entity 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 Entity

use of ai.grakn.concept.Entity 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 Entity

use of ai.grakn.concept.Entity 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 Entity

use of ai.grakn.concept.Entity 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)

Example 35 with Entity

use of ai.grakn.concept.Entity 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();
}
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)

Aggregations

Entity (ai.grakn.concept.Entity)99 Test (org.junit.Test)81 EntityType (ai.grakn.concept.EntityType)74 Role (ai.grakn.concept.Role)53 RelationshipType (ai.grakn.concept.RelationshipType)50 GraknTx (ai.grakn.GraknTx)44 Attribute (ai.grakn.concept.Attribute)18 Set (java.util.Set)16 Relationship (ai.grakn.concept.Relationship)14 Label (ai.grakn.concept.Label)11 ConceptId (ai.grakn.concept.ConceptId)10 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)8 AttributeType (ai.grakn.concept.AttributeType)7 List (java.util.List)7 GraknSession (ai.grakn.GraknSession)6 Before (org.junit.Before)6 GraknTxType (ai.grakn.GraknTxType)5 Concept (ai.grakn.concept.Concept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5