Search in sources :

Example 86 with RelationshipType

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

the class RelationshipTypeTest method whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned.

@Test
public void whenCallingInstancesOnImplicitRelationType_RelationEdgesAreReturned() {
    AttributeType<String> attributeType = tx.putAttributeType("My Special Attribute Type", AttributeType.DataType.STRING);
    Attribute<String> attribute = attributeType.putAttribute("Ad thing");
    EntityType entityType = tx.putEntityType("My Special Entity Type").attribute(attributeType);
    Entity entity = entityType.addEntity();
    RelationshipType implicitRelationshipType = tx.getRelationshipType(Schema.ImplicitType.HAS.getLabel(attributeType.getLabel()).getValue());
    assertNotNull(implicitRelationshipType);
    assertThat(implicitRelationshipType.instances().collect(toSet()), empty());
    entity.attribute(attribute);
    assertEquals(1, implicitRelationshipType.instances().count());
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 87 with RelationshipType

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

the class RelationshipTypeTest method whenSettingAnImplicitRelationTypeWithInstancesAbstract_Throw.

@Test
public void whenSettingAnImplicitRelationTypeWithInstancesAbstract_Throw() {
    AttributeType<String> attributeType = tx.putAttributeType("My Special Attribute Type", AttributeType.DataType.STRING);
    Attribute<String> attribute = attributeType.putAttribute("Ad thing");
    EntityType entityType = tx.putEntityType("My Special Entity Type").attribute(attributeType);
    entityType.addEntity().attribute(attribute);
    RelationshipType implicitRelationshipType = tx.getRelationshipType(Schema.ImplicitType.HAS.getLabel(attributeType.getLabel()).getValue());
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.addingInstancesToAbstractType(implicitRelationshipType).getMessage());
    implicitRelationshipType.setAbstract(true);
}
Also used : EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 88 with RelationshipType

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

the class LinearTransitivityMatrixKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n, int m) {
    Role Qfrom = graph.getRole("Q-from");
    Role Qto = graph.getRole("Q-to");
    EntityType aEntity = graph.getEntityType("a-entity");
    RelationshipType Q = graph.getRelationshipType("Q");
    ConceptId[][] aInstancesIds = new ConceptId[n + 1][m + 1];
    Thing aInst = putEntityWithResource(graph, "a", graph.getEntityType("entity2"), key);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            aInstancesIds[i][j] = putEntityWithResource(graph, "a" + i + "," + j, aEntity, key).getId();
        }
    }
    Q.addRelationship().addRolePlayer(Qfrom, aInst).addRolePlayer(Qto, graph.getConcept(aInstancesIds[1][1]));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i < n) {
                Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i + 1][j]));
            }
            if (j < m) {
                Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i][j + 1]));
            }
        }
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId)

Example 89 with RelationshipType

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

the class GrpcServerIT method whenGettingARelationshipType_TheInformationOnTheRelationshipTypeIsCorrect.

@Test
public void whenGettingARelationshipType_TheInformationOnTheRelationshipTypeIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").label("has-cast")).get();
        RelationshipType remoteConcept = query.stream().findAny().get().get("x").asRelationshipType();
        RelationshipType localConcept = localTx.getConcept(remoteConcept.getId()).asRelationshipType();
        assertEqualConcepts(localConcept, remoteConcept, RelationshipType::relates);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 90 with RelationshipType

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

the class GraknTxJanusTest method whenDeletingARelationshipTypeWithRoles_TheRelationshipTypeIsDeleted.

@Test
public void whenDeletingARelationshipTypeWithRoles_TheRelationshipTypeIsDeleted() {
    Role murderer = graknTx.putRole("murderer");
    Role victim = graknTx.putRole("victim");
    RelationshipType murder = graknTx.putRelationshipType("murder").relates(murderer).relates(victim);
    murder.delete();
    assertTrue(murder.isDeleted());
    assertThat(murderer.relationshipTypes().toArray(), emptyArray());
    assertThat(victim.relationshipTypes().toArray(), emptyArray());
}
Also used : Role(ai.grakn.concept.Role) 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