Search in sources :

Example 21 with RelationshipType

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

the class KCoreTest method testDisconnectedCores.

@Test
public void testDisconnectedCores() {
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        EntityType entityType1 = graph.putEntityType(thing);
        EntityType entityType2 = graph.putEntityType(anotherThing);
        Role role1 = graph.putRole("role1");
        Role role2 = graph.putRole("role2");
        RelationshipType relationshipType1 = graph.putRelationshipType(related).relates(role1).relates(role2);
        Role role3 = graph.putRole("role3");
        Role role4 = graph.putRole("role4");
        RelationshipType relationshipType2 = graph.putRelationshipType(veryRelated).relates(role3).relates(role4);
        entityType1.plays(role1).plays(role2).plays(role3).plays(role4);
        entityType2.plays(role1).plays(role2).plays(role3).plays(role4);
        Entity entity0 = entityType1.addEntity();
        Entity entity1 = entityType1.addEntity();
        Entity entity2 = entityType1.addEntity();
        Entity entity3 = entityType1.addEntity();
        Entity entity4 = entityType1.addEntity();
        Entity entity5 = entityType1.addEntity();
        Entity entity6 = entityType1.addEntity();
        Entity entity7 = entityType1.addEntity();
        Entity entity8 = entityType1.addEntity();
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity2);
        relationshipType1.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity3);
        relationshipType1.addRelationship().addRolePlayer(role1, entity3).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity3);
        relationshipType1.addRelationship().addRolePlayer(role1, entity1).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity2).addRolePlayer(role2, entity4);
        relationshipType1.addRelationship().addRolePlayer(role1, entity5).addRolePlayer(role2, entity6);
        relationshipType2.addRelationship().addRolePlayer(role3, entity5).addRolePlayer(role4, entity7);
        relationshipType2.addRelationship().addRolePlayer(role3, entity5).addRolePlayer(role4, entity8);
        relationshipType2.addRelationship().addRolePlayer(role3, entity6).addRolePlayer(role4, entity7);
        relationshipType2.addRelationship().addRolePlayer(role3, entity6).addRolePlayer(role4, entity8);
        relationshipType2.addRelationship().addRolePlayer(role3, entity7).addRolePlayer(role4, entity8);
        relationshipType1.addRelationship().addRolePlayer(role1, entity0).addRolePlayer(role2, entity1);
        relationshipType1.addRelationship().addRolePlayer(role1, entity0).addRolePlayer(role2, entity8);
        graph.commit();
    }
    Map<String, Set<String>> result;
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        result = graph.graql().compute().cluster().usingKCore().kValue(3L).execute();
        assertEquals(2, result.size());
        assertEquals(4, result.values().iterator().next().size());
        System.out.println("result = " + result);
        result = graph.graql().compute().cluster().usingKCore().kValue(2L).execute();
        assertEquals(1, result.size());
        assertEquals(9, result.values().iterator().next().size());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) Set(java.util.Set) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 22 with RelationshipType

use of ai.grakn.concept.RelationshipType 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 23 with RelationshipType

use of ai.grakn.concept.RelationshipType 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 24 with RelationshipType

use of ai.grakn.concept.RelationshipType 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 25 with RelationshipType

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

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