use of ai.grakn.util.CommonUtil 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.util.CommonUtil in project grakn by graknlabs.
the class GraqlPrinter method build.
@Override
public Function<StringBuilder, StringBuilder> build(Concept concept) {
return sb -> {
// Display values for resources and ids for everything else
if (concept.isAttribute()) {
sb.append(colorKeyword("val ")).append(StringUtil.valueToString(concept.asAttribute().getValue()));
} else if (concept.isSchemaConcept()) {
SchemaConcept ontoConcept = concept.asSchemaConcept();
sb.append(colorKeyword("label ")).append(colorType(ontoConcept));
SchemaConcept superConcept = ontoConcept.sup();
if (superConcept != null) {
sb.append(colorKeyword(" sub ")).append(colorType(superConcept));
}
} else {
sb.append(colorKeyword("id ")).append(idToString(concept.getId()));
}
if (concept.isRelationship()) {
String relationString = concept.asRelationship().allRolePlayers().entrySet().stream().flatMap(entry -> {
Role role = entry.getKey();
Set<Thing> things = entry.getValue();
return things.stream().map(instance -> Optional.of(colorType(role) + ": id " + idToString(instance.getId())));
}).flatMap(CommonUtil::optionalToStream).collect(Collectors.joining(", "));
sb.append(" (").append(relationString).append(")");
}
// Display type of each instance
if (concept.isThing()) {
Type type = concept.asThing().type();
sb.append(colorKeyword(" isa ")).append(colorType(type));
}
// Display when and then for rules
if (concept.isRule()) {
sb.append(colorKeyword(" when ")).append("{ ").append(concept.asRule().getWhen()).append(" }");
sb.append(colorKeyword(" then ")).append("{ ").append(concept.asRule().getThen()).append(" }");
}
// Display any requested resources
if (concept.isThing() && attributeTypes.length > 0) {
concept.asThing().attributes(attributeTypes).forEach(resource -> {
String resourceType = colorType(resource.type());
String value = StringUtil.valueToString(resource.getValue());
sb.append(colorKeyword(" has ")).append(resourceType).append(" ").append(value);
});
}
return sb;
};
}
Aggregations