use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class SchemaConceptPropertyTest method whenSettingTheDirectSuperToAnIndirectSub_Throw.
// TODO
@Ignore("Test fails due to incorrect error message")
@Property
public void whenSettingTheDirectSuperToAnIndirectSub_Throw(@NonMeta SchemaConcept concept, long seed) {
SchemaConcept newSuperConcept = PropertyUtil.choose(concept.subs(), seed);
// Check if the mutation can be performed in a valid manner
if (newSuperConcept.isType())
assumeThat(newSuperConcept.asType().plays().collect(Collectors.toSet()), is(empty()));
exception.expect(GraknTxOperationException.class);
exception.expectMessage(GraknTxOperationException.loopCreated(concept, newSuperConcept).getMessage());
setDirectSuper(concept, newSuperConcept);
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class JsonPrinter method build.
@Override
public Json build(Concept concept) {
Json json = Json.object("id", concept.getId().getValue());
if (concept.isSchemaConcept()) {
json.set("name", concept.asSchemaConcept().getLabel().getValue());
SchemaConcept superConcept = concept.asSchemaConcept().sup();
if (superConcept != null)
json.set("sub", superConcept.getLabel().getValue());
} else if (concept.isThing()) {
json.set("isa", concept.asThing().type().getLabel().getValue());
} else {
throw CommonUtil.unreachableStatement("Unrecognised concept " + concept);
}
if (concept.isAttribute()) {
json.set("value", concept.asAttribute().getValue());
}
if (concept.isRule()) {
Pattern when = concept.asRule().getWhen();
if (when != null) {
json.set("when", when.toString());
}
Pattern then = concept.asRule().getThen();
if (then != null) {
json.set("then", then.toString());
}
}
return json;
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class InsertQueryImpl method getSchemaConcepts.
@Override
public Set<SchemaConcept> getSchemaConcepts() {
GraknTx theGraph = getTx().orElseThrow(GraqlQueryException::noTx);
Set<SchemaConcept> types = allVarPatterns().map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).map(theGraph::<Type>getSchemaConcept).collect(Collectors.toSet());
match().ifPresent(mq -> types.addAll(mq.admin().getSchemaConcepts()));
return types;
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class RelationshipProperty method checkValidProperty.
@Override
public void checkValidProperty(GraknTx graph, VarPatternAdmin var) throws GraqlQueryException {
Set<Label> roleTypes = relationPlayers().stream().map(RelationPlayer::getRole).flatMap(CommonUtil::optionalToStream).map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).collect(toSet());
Optional<Label> maybeLabel = var.getProperty(IsaProperty.class).map(IsaProperty::type).flatMap(VarPatternAdmin::getTypeLabel);
maybeLabel.ifPresent(label -> {
SchemaConcept schemaConcept = graph.getSchemaConcept(label);
if (schemaConcept == null || !schemaConcept.isRelationshipType()) {
throw GraqlQueryException.notARelationType(label);
}
});
// Check all role types exist
roleTypes.forEach(roleId -> {
SchemaConcept schemaConcept = graph.getSchemaConcept(roleId);
if (schemaConcept == null || !schemaConcept.isRole()) {
throw GraqlQueryException.notARoleType(roleId);
}
});
}
use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.
the class TinkerComputeQueryRunner method run.
public ComputeJob<Map<Long, Set<String>>> run(DegreeQuery query) {
return runCompute(query, tinkerComputeQuery -> {
Set<Label> ofLabels;
// Check if ofType is valid before returning emptyMap
if (query.targetLabels().isEmpty()) {
ofLabels = tinkerComputeQuery.subLabels();
} else {
ofLabels = query.targetLabels().stream().flatMap(typeLabel -> {
Type type = tx.getSchemaConcept(typeLabel);
if (type == null)
throw GraqlQueryException.labelNotFound(typeLabel);
return type.subs();
}).map(SchemaConcept::getLabel).collect(Collectors.toSet());
}
Set<Label> subLabels = Sets.union(tinkerComputeQuery.subLabels(), ofLabels);
if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
return Collections.emptyMap();
}
Set<LabelId> subLabelIds = convertLabelsToIds(subLabels);
Set<LabelId> ofLabelIds = convertLabelsToIds(ofLabels);
ComputerResult result = tinkerComputeQuery.compute(new DegreeVertexProgram(ofLabelIds), new DegreeDistributionMapReduce(ofLabelIds, DegreeVertexProgram.DEGREE), subLabelIds);
return result.memory().get(DegreeDistributionMapReduce.class.getName());
});
}
Aggregations