Search in sources :

Example 31 with RelationshipType

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();
}
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 32 with RelationshipType

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

Example 33 with RelationshipType

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();
}
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 34 with RelationshipType

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

Example 35 with RelationshipType

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();
}
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

RelationshipType (ai.grakn.concept.RelationshipType)127 Role (ai.grakn.concept.Role)105 Test (org.junit.Test)91 EntityType (ai.grakn.concept.EntityType)80 Entity (ai.grakn.concept.Entity)52 GraknTx (ai.grakn.GraknTx)39 Relationship (ai.grakn.concept.Relationship)25 ConceptId (ai.grakn.concept.ConceptId)23 Label (ai.grakn.concept.Label)21 HashSet (java.util.HashSet)20 Set (java.util.Set)20 AttributeType (ai.grakn.concept.AttributeType)17 Thing (ai.grakn.concept.Thing)17 Attribute (ai.grakn.concept.Attribute)16 Schema (ai.grakn.util.Schema)12 Collectors (java.util.stream.Collectors)12 List (java.util.List)11 GraknSession (ai.grakn.GraknSession)10 GraknTxType (ai.grakn.GraknTxType)10 Concept (ai.grakn.concept.Concept)10