Search in sources :

Example 71 with Role

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

the class NguyenKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n) {
    Role Rfrom = graph.getRole("R-rA");
    Role Rto = graph.getRole("R-rB");
    Role qfrom = graph.getRole("Q-rA");
    Role qto = graph.getRole("Q-rB");
    Role Pfrom = graph.getRole("P-rA");
    Role Pto = graph.getRole("P-rB");
    EntityType entity = graph.getEntityType("entity2");
    EntityType aEntity = graph.getEntityType("a-entity");
    EntityType bEntity = graph.getEntityType("b-entity");
    RelationshipType r = graph.getRelationshipType("R");
    RelationshipType p = graph.getRelationshipType("P");
    RelationshipType q = graph.getRelationshipType("Q");
    ConceptId cId = putEntityWithResource(graph, "c", entity, key).getId();
    ConceptId dId = putEntityWithResource(graph, "d", entity, key).getId();
    ConceptId eId = putEntityWithResource(graph, "e", entity, key).getId();
    ConceptId[] aInstancesIds = new ConceptId[n + 2];
    ConceptId[] bInstancesIds = new ConceptId[n + 2];
    aInstancesIds[n + 1] = putEntityWithResource(graph, "a" + (n + 1), aEntity, key).getId();
    for (int i = 0; i <= n; i++) {
        aInstancesIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
        bInstancesIds[i] = putEntityWithResource(graph, "b" + i, bEntity, key).getId();
    }
    p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(dId));
    r.addRelationship().addRolePlayer(Rfrom, graph.getConcept(dId)).addRolePlayer(Rto, graph.getConcept(eId));
    q.addRelationship().addRolePlayer(qfrom, graph.getConcept(eId)).addRolePlayer(qto, graph.getConcept(aInstancesIds[0]));
    for (int i = 0; i <= n; i++) {
        p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(Pto, graph.getConcept(cId));
        p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(bInstancesIds[i]));
        q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstancesIds[i])).addRolePlayer(qto, graph.getConcept(bInstancesIds[i]));
        q.addRelationship().addRolePlayer(qfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(qto, graph.getConcept(aInstancesIds[i + 1]));
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) ConceptId(ai.grakn.concept.ConceptId)

Example 72 with Role

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

the class EntityTypeTest method whenCreatingEntityTypeUsingLabelTakenByAnotherType_Throw.

@Test
public void whenCreatingEntityTypeUsingLabelTakenByAnotherType_Throw() {
    Role original = tx.putRole("Role Type");
    expectedException.expect(PropertyNotUniqueException.class);
    expectedException.expectMessage(PropertyNotUniqueException.cannotCreateProperty(original, Schema.VertexProperty.SCHEMA_LABEL, original.getLabel()).getMessage());
    tx.putEntityType(original.getLabel());
}
Also used : Role(ai.grakn.concept.Role) Test(org.junit.Test)

Example 73 with Role

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

the class EntityTypeTest method whenGettingTheRolesPlayedByType_ReturnTheRoles.

@Test
public void whenGettingTheRolesPlayedByType_ReturnTheRoles() throws Exception {
    Role monster = tx.putRole("monster");
    Role animal = tx.putRole("animal");
    Role monsterEvil = tx.putRole("evil monster").sup(monster);
    EntityType creature = tx.putEntityType("creature").plays(monster).plays(animal);
    EntityType creatureMysterious = tx.putEntityType("mysterious creature").sup(creature).plays(monsterEvil);
    assertThat(creature.plays().collect(toSet()), containsInAnyOrder(monster, animal));
    assertThat(creatureMysterious.plays().collect(toSet()), containsInAnyOrder(monster, animal, monsterEvil));
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 74 with Role

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

the class RelationshipTypeTest method whenMutatingRolesOfRelationType_EnsureRelationTypeRolesAreAlwaysUpdated.

@Test
public void whenMutatingRolesOfRelationType_EnsureRelationTypeRolesAreAlwaysUpdated() {
    RelationshipType relationshipType = tx.putRelationshipType("c1");
    Role role1 = tx.putRole("c2");
    Role role2 = tx.putRole("c3");
    assertThat(relationshipType.relates().collect(toSet()), empty());
    relationshipType.relates(role1).relates(role2);
    assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role1, role2));
    relationshipType.deleteRelates(role1);
    assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role2));
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 75 with Role

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

the class RelationshipTypeTest method whenGettingTheRolesOfRelationTypes_AllTheRolesAreReturned.

@Test
public void whenGettingTheRolesOfRelationTypes_AllTheRolesAreReturned() throws Exception {
    RelationshipType relationshipType = tx.putRelationshipType("relationTypes");
    Role role1 = tx.putRole("role1");
    Role role2 = tx.putRole("role2");
    Role role3 = tx.putRole("role3");
    relationshipType.relates(role1).relates(role2).relates(role3);
    assertThat(relationshipType.relates().collect(toSet()), containsInAnyOrder(role1, role2, role3));
}
Also used : Role(ai.grakn.concept.Role) 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