@Override final Rule asCurrentBaseType(Concept other) { return other.asRule(); }
@Override final Rule asSelf(Concept concept) { return concept.asRule(); }
@Override public Rule putRule(Label label, Pattern when, Pattern then) { return client().putRule(label, when, then).asRule(); }
@Override Label transform(MatchableConcept item) { Concept concept = item.get(); return concept.isRule() ? concept.asRule().label() : null; } };
/** * * @param concept The element to be later validated */ public void trackForValidation(Concept concept) { if (concept.isThing()) { modifiedThings.add(concept.asThing()); } else if (concept.isRole()) { modifiedRoles.add(concept.asRole()); } else if (concept.isRelationshipType()) { modifiedRelationshipTypes.add(concept.asRelationshipType()); } else if (concept.isRule()){ modifiedRules.add(concept.asRule()); } } public void trackForValidation(Casting casting) {
@Override public Rule putRule(Label label, Pattern when, Pattern then) { transceiver.send(RequestBuilder.Transaction.putRule(label, when, then)); return RemoteConcept.of(responseOrThrow().getPutRuleRes().getRule(), this).asRule(); }
@Override public String toString() { if (concept.isAttribute()) { return "hasValue(" + valueToString(concept.asAttribute().value()) + ")"; } else if (concept.isThing()) { Thing thing = concept.asThing(); Stream<Attribute<?>> resources = thing.attributes(); Optional<?> value = resources .filter(resource -> NAME_TYPES.contains(resource.type().label())) .map(Attribute::value).findFirst(); return "instance(" + value.map(StringUtil::valueToString).orElse("") + ") isa " + thing.type().label(); } else if (concept.isType()) { return "type(" + concept.asType().label() + ")"; } else if (concept.isRole()) { return "role(" + concept.asRole().label() + ")"; } else if (concept.isRule()) { return "rule(" + concept.asRule().label() + ")"; } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }
@Override protected Json concept(Concept concept) { Json json = Json.object("id", concept.id().getValue()); if (concept.isSchemaConcept()) { json.set("name", concept.asSchemaConcept().label().getValue()); SchemaConcept superConcept = concept.asSchemaConcept().sup(); if (superConcept != null) json.set("sub", superConcept.label().getValue()); } else if (concept.isThing()) { json.set("isa", concept.asThing().type().label().getValue()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } if (concept.isAttribute()) { json.set("value", concept.asAttribute().value()); } if (concept.isRule()) { Pattern when = concept.asRule().when(); if (when != null) { json.set("when", when.toString()); } Pattern then = concept.asRule().then(); if (then != null) { json.set("then", then.toString()); } } return json; }