Touchstone
How-to guides

Read individuals from code

A plugin, a Groovy script in the tool or a test reads a Concept's individuals and the values of its Attributes and Relations through Ontology, the one class of the runtime a caller learns.

From Kotlin

import com.mbseconsulting.touchstone.ontology.Ontology

val ontology = Ontology(project)
val functions: Set<Element> = ontology.individuals(functionConcept)
val isOne: Boolean = ontology.isIndividual(someActivity, functionConcept)
val fromOneMapping: Set<Element> = ontology.selection(functionByActivityMapping)
val costs: List<Any> = ontology.attributeValues(someActivity, costAttribute)
val performers: Set<Element> = ontology.relationTargets(someActivity, performedByRelation)
val holds: Boolean? = ontology.verdict(rule, someActivity)
val everyVerdict: Map<Element, Boolean>? = ontology.verdicts(rule)
val findings: Set<Element> = ontology.failing(rule)
val ratio: Double? = ontology.score(rule)
val figure: Double? = ontology.completeness(functionConcept)

individuals answers what the Concept's mappings select, or the union of its specializations' individuals when it has no mapping. attributeValues answers a list even for an Attribute declared [1..1]; read .singleOrNull() when the ontology says one. It answers an EnumerationLiteral for an Enumeration-typed Attribute, and drops any other model element among the values. relationTargets keeps only targets that are individuals of the Relation's type. selection answers what one «ConceptMapping» contributes on its own, before the union; a Class that is not a mapping answers nothing. isIndividual decides for one element without traversing the model.

verdict answers null for an element that is not an individual of the rule's context Concept, and for a rule without verdicts. passing and failing partition the individuals of that Concept by verdict, and verdicts answers the whole partition in one evaluation, null for a rule without verdicts; read it when a caller needs several figures of the same rule. score and completeness are absent, null, when nothing was measured: a Concept with no individuals, a rule without verdicts, or an element none of whose rules has a score.

No filter, query, accessor or derived-property failure escapes a call. A mapping whose filter, query, accessor or derived-property read fails, or whose query names a behavior the tool cannot run, yields nothing and writes one line per mapping per call under the Touchstone log category, naming the mapping and the cause. A project that does not use the profile answers empty results. A malformed expression, a rule constraining nothing or several elements, a dangling hyperlink, a reference cycle among rules, or a rule with neither an expression nor a reachable «MaturityRuleImplementation» leaves the rule without verdicts and writes one line naming the rule.

Nothing is cached. Each call reads the model as it stands, so a loop over many individuals reading the same Relation pays the mapping's evaluation each time; hold the results you need in your own collection.

From a Groovy script in the tool

def ontology = new com.mbseconsulting.touchstone.ontology.Ontology(project)
ontology.individuals(concept).each { println it.name }

The plugin's classes are visible to a script because plugins and their libraries load in one classloader unless a descriptor declares its own, and Touchstone's does not.

From an expression

The derived property individuals on every Concept answers the same set as Ontology.individuals, and individuals on every «ConceptMapping» the same set as Ontology.selection; both are Binary expressions inside the customization whose bodies name the plugin's adapter classes.

passing, failing and score on a rule, and completeness on a Concept, an Attribute, a Relation or an Objective, are Binary expressions in the customization too, backed by adapter classes under ontology/binding.

On this page