Search in sources :

Example 11 with Label

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

the class DegreeTest method testSubIsAccountedForInSubgraph.

@Test
public void testSubIsAccountedForInSubgraph() {
    Role pet = tx.putRole("pet");
    Role owner = tx.putRole("owner");
    Entity person = tx.putEntityType("person").plays(owner).addEntity();
    EntityType animal = tx.putEntityType("animal").plays(pet);
    Entity dog = tx.putEntityType("dog").sup(animal).addEntity();
    tx.putRelationshipType("mans-best-friend").relates(pet).relates(owner).addRelationship().addRolePlayer(pet, dog).addRolePlayer(owner, person);
    Map<Long, Set<String>> correctDegrees = new HashMap<>();
    correctDegrees.put(1L, Sets.newHashSet(person.getId().getValue(), dog.getId().getValue()));
    tx.commit();
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        // set subgraph, use animal instead of dog
        Set<Label> ct = Sets.newHashSet(Label.of("person"), Label.of("animal"), Label.of("mans-best-friend"));
        Map<Long, Set<String>> degrees = graph.graql().compute().centrality().usingDegree().in(ct).execute();
        // check that dog has a degree to confirm sub has been inferred
        assertEquals(correctDegrees, degrees);
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) GraknTx(ai.grakn.GraknTx) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 12 with Label

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

the class GraknTxPutPropertyTest method whenCallingPutResourceTypeWithAnExistingNonUniqueResourceTypeLabelButADifferentDataType_Throw.

@Property
public void whenCallingPutResourceTypeWithAnExistingNonUniqueResourceTypeLabelButADifferentDataType_Throw(@Open GraknTx graph, @FromTx AttributeType<?> attributeType, AttributeType.DataType<?> dataType) {
    assumeThat(dataType, not(is(attributeType.getDataType())));
    Label label = attributeType.getLabel();
    exception.expect(GraknTxOperationException.class);
    if (isMetaLabel(label)) {
        exception.expectMessage(GraknTxOperationException.metaTypeImmutable(label).getMessage());
    } else {
        exception.expectMessage(GraknTxOperationException.immutableProperty(attributeType.getDataType(), dataType, Schema.VertexProperty.DATA_TYPE).getMessage());
    }
    graph.putAttributeType(label, dataType);
}
Also used : MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Label(ai.grakn.concept.Label) Property(com.pholser.junit.quickcheck.Property)

Example 13 with Label

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

the class SchemaConceptPropertyTest method whenCallingGetLabel_TheResultCanBeUsedToRetrieveTheSameConcept.

@Property
public void whenCallingGetLabel_TheResultCanBeUsedToRetrieveTheSameConcept(@Open GraknTx graph, @FromTx SchemaConcept concept) {
    Label label = concept.getLabel();
    assertEquals(concept, graph.getSchemaConcept(label));
}
Also used : MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Label(ai.grakn.concept.Label) Property(com.pholser.junit.quickcheck.Property)

Example 14 with Label

use of ai.grakn.concept.Label 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 15 with Label

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

the class ConceptControllerTest method whenCallingRuleEndpointAndRequestingJSON_ReturnJSON.

@Test
public void whenCallingRuleEndpointAndRequestingJSON_ReturnJSON() {
    Label label = MetaSchema.RULE.getLabel();
    given().accept(ContentType.JSON).pathParam("keyspace", keyspace.getValue()).pathParam("label", label.getValue()).when().get("/kb/{keyspace}/rule/{label}").then().statusCode(SC_OK).contentType(ContentType.JSON);
}
Also used : Label(ai.grakn.concept.Label) Test(org.junit.Test)

Aggregations

Label (ai.grakn.concept.Label)87 Test (org.junit.Test)41 Role (ai.grakn.concept.Role)25 GraknTx (ai.grakn.GraknTx)22 ConceptId (ai.grakn.concept.ConceptId)21 Concept (ai.grakn.concept.Concept)20 Set (java.util.Set)20 RelationshipType (ai.grakn.concept.RelationshipType)19 SchemaConcept (ai.grakn.concept.SchemaConcept)19 AttributeType (ai.grakn.concept.AttributeType)17 EntityType (ai.grakn.concept.EntityType)17 Relationship (ai.grakn.concept.Relationship)14 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 Type (ai.grakn.concept.Type)12 Stream (java.util.stream.Stream)12 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)11 Schema (ai.grakn.util.Schema)11 Collection (java.util.Collection)11 Pattern (ai.grakn.graql.Pattern)10