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);
}
}
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);
}
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));
}
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);
}
}
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);
}
Aggregations