clara.tools.inspect

Tooling to inspect a rule session. The two major methods here are:

  • inspect, which returns a data structure describing the session that can be used by tooling.
  • explain-activations, which uses inspect and prints a human-readable description covering why each rule activation or query match occurred.

->Explanation

(->Explanation matches bindings)

Positional factory function for class clara.tools.inspect.Explanation.

explain-activations

(explain-activations session & {:keys [rule-filter-fn], :as options})

Prints a human-friend explanation of why rules and queries matched in the given session. A caller my optionally pass a :rule-filter-fn, which is a predicate

(clara.tools.inspect/explain-activations session :rule-filter-fn (fn [rule] (re-find my-rule-regex (:name rule))))

inspect

(inspect session)

Inputs: [session]

Returns a representation of the given rule session useful to understand the state of the underlying rules.

The returned structure includes the following keys:

  • :rule-matches – a map of rule structures to their matching explanations.
  • :query-matches – a map of query structures to their matching explanations.
  • :condition-matches – a map of conditions pulled from each rule to facts they match.
  • :insertions – a map of rules to a sequence of {:explanation E, :fact F} records to allow inspection of why a given fact was inserted.
  • :fact->explanations – a map of facts inserted to a sequence of maps of the form {:rule rule-structure :explanation explanation}, where each such map justifies a single insertion of the fact.

Users may inspect the entire structure for troubleshooting or explore it for specific cases. For instance, the following code snippet could look at all matches for some example rule:

(defrule example-rule … )

(get-in (inspect example-session) [:rule-matches example-rule])

The above segment will return matches for the rule in question.

InspectionSchema

map->Explanation

(map->Explanation m11318)

Factory function for class Explanation, taking a map of keywords to field values, but not much slower than ->x like the clojure.core version. (performance is fixed in Clojure 1.7, so this should eventually be removed.)

strict-map->Explanation

(strict-map->Explanation m11319 & [drop-extra-keys?__2257__auto__])

Factory function for class Explanation, taking a map of keywords to field values. All keys are required, and no extra keys are allowed. Even faster than map->