Search in sources :

Example 31 with Role

use of ai.grakn.concept.Role in project grakn by graknlabs.

the class TypePropertyTest method whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole.

@Property
public void whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole(@NonMeta Type type, long seed) {
    Role role = PropertyUtil.choose(type.sup() + " plays no roles", type.sup().plays().collect(toSet()), seed);
    type.deletePlays(role);
    assertThat(type.plays().collect(toSet()), hasItem(role));
}
Also used : Role(ai.grakn.concept.Role) Property(com.pholser.junit.quickcheck.Property)

Example 32 with Role

use of ai.grakn.concept.Role in project grakn by graknlabs.

the class ValidatorTest method whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes3.

@Test
public void whenARelationTypeHasASubTypeHierarchy_EnsureThatWhenARelationTypeHasMatchingRoleTypes3() throws InvalidKBException {
    Role relative = tx.putRole("relative");
    Role parent = tx.putRole("parent").sup(relative);
    Role father = tx.putRole("father").sup(parent);
    Role pChild = tx.putRole("pChild").sup(relative);
    Role fChild = tx.putRole("fChild").sup(pChild);
    tx.putEntityType("animal").plays(relative).plays(parent).plays(father).plays(pChild).plays(fChild);
    RelationshipType parentrelativehood = tx.putRelationshipType("parentrelativehood").relates(relative).relates(parent).relates(pChild);
    tx.putRelationshipType("fatherhood").sup(parentrelativehood).relates(father).relates(fChild);
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 33 with Role

use of ai.grakn.concept.Role in project grakn by graknlabs.

the class ValidatorTest method whenCreatingAbstractRelationshipWithSubType_EnsureValidationRuleForMatchingSubRolesIsSkipped.

@Test
public void whenCreatingAbstractRelationshipWithSubType_EnsureValidationRuleForMatchingSubRolesIsSkipped() {
    Role role1 = tx.putRole("my role");
    Role role2 = tx.putRole("my role 2");
    RelationshipType abstractRelationType = tx.putRelationshipType("my abstract relation type").relates(role1).setAbstract(true);
    tx.putRelationshipType("my relation type").sup(abstractRelationType).relates(role2);
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 34 with Role

use of ai.grakn.concept.Role in project grakn by graknlabs.

the class ValidatorTest method whenCommittingGraphWhichFollowsValidationRules_Commit.

@Test
public void whenCommittingGraphWhichFollowsValidationRules_Commit() {
    RelationshipType cast = tx.putRelationshipType("Cast");
    Role feature = tx.putRole("Feature");
    Role actor = tx.putRole("Actor");
    EntityType movie = tx.putEntityType("Movie");
    EntityType person = tx.putEntityType("Person");
    Thing pacino = person.addEntity();
    Thing godfather = movie.addEntity();
    EntityType genre = tx.putEntityType("Genre");
    Role movieOfGenre = tx.putRole("Movie of Genre");
    Role movieGenre = tx.putRole("Movie Genre");
    Thing crime = genre.addEntity();
    RelationshipType movieHasGenre = tx.putRelationshipType("Movie Has Genre");
    // Construction
    cast.relates(feature);
    cast.relates(actor);
    cast.addRelationship().addRolePlayer(feature, godfather).addRolePlayer(actor, pacino);
    movieHasGenre.addRelationship().addRolePlayer(movieOfGenre, godfather).addRolePlayer(movieGenre, crime);
    movieHasGenre.relates(movieOfGenre);
    movieHasGenre.relates(movieGenre);
    movie.plays(movieOfGenre);
    person.plays(actor);
    movie.plays(feature);
    genre.plays(movieGenre);
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 35 with Role

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

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