Search in sources :

Example 6 with Type

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

the class ConceptController method getTypeInstances.

private String getTypeInstances(Request request, Response response) throws JsonProcessingException {
    response.type(APPLICATION_JSON);
    Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
    Label label = Label.of(mandatoryPathParameter(request, LABEL_PARAMETER));
    int offset = getOffset(request);
    int limit = getLimit(request);
    try (GraknTx tx = factory.tx(keyspace, READ);
        Timer.Context context = instancesGetTimer.time()) {
        Type type = tx.getType(label);
        if (type == null) {
            response.status(SC_NOT_FOUND);
            return "";
        }
        // Get the wrapper
        Things things = ConceptBuilder.buildThings(type, offset, limit);
        response.status(SC_OK);
        return objectMapper.writeValueAsString(things);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Type(ai.grakn.concept.Type) Timer(com.codahale.metrics.Timer) Keyspace(ai.grakn.Keyspace) Things(ai.grakn.engine.controller.response.Things) Label(ai.grakn.concept.Label)

Example 7 with Type

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

the class RemoteConceptsTest method whenCallingPlayedByTypes_GetTheExpectedResult.

@Test
public void whenCallingPlayedByTypes_GetTheExpectedResult() {
    Type a = RemoteConcepts.createEntityType(tx, A);
    Type b = RemoteConcepts.createRelationshipType(tx, B);
    Type c = RemoteConcepts.createAttributeType(tx, C);
    mockConceptMethod(ConceptMethods.GET_TYPES_THAT_PLAY_ROLE, Stream.of(a, b, c));
    assertThat(role.playedByTypes().collect(toSet()), containsInAnyOrder(a, b, c));
}
Also used : 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) Test(org.junit.Test)

Example 8 with Type

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

the class RemoteConceptsTest method whenCallingType_GetTheExpectedResult.

@Test
public void whenCallingType_GetTheExpectedResult() {
    Type type = RemoteConcepts.createEntityType(tx, A);
    mockConceptMethod(GET_DIRECT_TYPE, type);
    assertEquals(type, thing.type());
}
Also used : 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) Test(org.junit.Test)

Example 9 with Type

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

the class RemoteConceptsTest method whenCallingSubs_GetTheExpectedResult.

@Test
public void whenCallingSubs_GetTheExpectedResult() {
    Type me = relationshipType;
    Type mySub = RemoteConcepts.createRelationshipType(tx, A);
    Type mySubsSub = RemoteConcepts.createRelationshipType(tx, B);
    mockConceptMethod(ConceptMethods.GET_SUB_CONCEPTS, Stream.of(me, mySub, mySubsSub));
    assertThat(relationshipType.subs().collect(toSet()), containsInAnyOrder(me, mySub, mySubsSub));
}
Also used : 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) Test(org.junit.Test)

Example 10 with Type

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

the class RemoteConceptsTest method whenCallingSups_GetTheExpectedResult.

@Test
public void whenCallingSups_GetTheExpectedResult() {
    Type me = entityType;
    Type mySuper = RemoteConcepts.createEntityType(tx, A);
    Type mySupersSuper = RemoteConcepts.createEntityType(tx, B);
    Type metaType = RemoteConcepts.createMetaType(tx, C);
    mockConceptMethod(ConceptMethods.GET_SUPER_CONCEPTS, Stream.of(me, mySuper, mySupersSuper, metaType));
    Set<Type> sups = entityType.sups().collect(toSet());
    assertThat(sups, containsInAnyOrder(me, mySuper, mySupersSuper));
    assertThat(sups, not(hasItem(metaType)));
}
Also used : 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) 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