Search in sources :

Example 36 with Type

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

the class EntityTypeTest method whenGettingTheLabelOfType_TheTypeLabelIsReturned.

@Test
public void whenGettingTheLabelOfType_TheTypeLabelIsReturned() {
    Type test = tx.putEntityType("test");
    assertEquals(Label.of("test"), test.getLabel());
}
Also used : Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 37 with Type

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

the class EntityTypeTest method whenAddingRoleToMetaType_Throw.

@Test
public void whenAddingRoleToMetaType_Throw() {
    Type meta = tx.getMetaEntityType();
    Role role = tx.putRole("A Role");
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.metaTypeImmutable(meta.getLabel()).getMessage());
    meta.plays(role);
}
Also used : Role(ai.grakn.concept.Role) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 38 with Type

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

the class EntityTypeTest method whenGettingTheSuperSetViaSupsMethod_ReturnAllOfItsSuperTypes.

@Test
public void whenGettingTheSuperSetViaSupsMethod_ReturnAllOfItsSuperTypes() {
    EntityType child = tx.putEntityType("child");
    EntityType p2 = tx.putEntityType("p2").sub(child);
    EntityType p3 = tx.putEntityType("p3").sub(p2);
    EntityType p4 = tx.putEntityType("p4").sub(p3);
    EntityType entity = tx.getMetaEntityType();
    Type thing = tx.getMetaConcept();
    assertThat(child.sups().collect(toSet()), containsInAnyOrder(child, p2, p3, p4, entity));
    assertThat(p2.sups().collect(toSet()), containsInAnyOrder(p2, p3, p4, entity));
    assertThat(p3.sups().collect(toSet()), containsInAnyOrder(p3, p4, entity));
    assertThat(p4.sups().collect(toSet()), containsInAnyOrder(p4, entity));
    assertThat(entity.sups().collect(toSet()), containsInAnyOrder(entity));
    assertThat(thing.sups().collect(toSet()), empty());
}
Also used : EntityType(ai.grakn.concept.EntityType) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 39 with Type

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

the class GraknMatchers method getTypes.

private static Set<Type> getTypes(Thing thing) {
    Set<Type> types = Sets.newHashSet();
    Type type = thing.type();
    while (type != null) {
        types.add(type);
        type = type.sup();
    }
    return types;
}
Also used : Type(ai.grakn.concept.Type)

Example 40 with Type

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

the class GrpcServerIT method whenGettingAType_TheInformationOnTheTypeIsCorrect.

@Test
public void whenGettingAType_TheInformationOnTheTypeIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").label("person")).get();
        Type remoteConcept = query.stream().findAny().get().get("x").asType();
        Type localConcept = localTx.getConcept(remoteConcept.getId()).asType();
        assertEquals(localConcept.isAbstract(), remoteConcept.isAbstract());
        assertEqualConcepts(localConcept, remoteConcept, Type::plays);
        assertEqualConcepts(localConcept, remoteConcept, Type::instances);
        assertEqualConcepts(localConcept, remoteConcept, Type::attributes);
        assertEqualConcepts(localConcept, remoteConcept, Type::keys);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) GraknTxType(ai.grakn.GraknTxType) DataType(ai.grakn.concept.AttributeType.DataType) AttributeType(ai.grakn.concept.AttributeType) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Aggregations

Type (ai.grakn.concept.Type)47 RelationshipType (ai.grakn.concept.RelationshipType)28 AttributeType (ai.grakn.concept.AttributeType)25 Test (org.junit.Test)23 EntityType (ai.grakn.concept.EntityType)21 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Label (ai.grakn.concept.Label)15 Set (java.util.Set)15 GraknTx (ai.grakn.GraknTx)14 Concept (ai.grakn.concept.Concept)13 Collectors (java.util.stream.Collectors)13 Role (ai.grakn.concept.Role)12 ConceptId (ai.grakn.concept.ConceptId)11 Schema (ai.grakn.util.Schema)10 HashSet (java.util.HashSet)10 Stream (java.util.stream.Stream)10 GraqlQueryException (ai.grakn.exception.GraqlQueryException)9 Map (java.util.Map)9 Answer (ai.grakn.graql.admin.Answer)8 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)8