Fork me on GitHub
#clara
<
2021-02-11
>
bherrmann13:02:16

I've recently been thinking of playing with rules engines (perhaps I need a hobby?) I recently watched and enjoyed (@sekao is a funny character. ) this presentation on O'Doyle - https://youtu.be/XONRaJJAhpA The talk references Clara a lot. I wondered though does O'Dolyle have the ability to explain why a rule was executed... I'm starting to think about using a rules engine, and the idea of being able to trace why a rule fired seems important. Also did O'Dolye not have retraction? He mentioned you can "replace" a fact.

mikerod16:02:06

@bherrmann I still need to watch that talk on O’Doyle. It did sound to me like what it wasn’t planned to have is a truth maintenance system. This is a key part of Clara’s feature sets/priority. It allows rules to be written in a way that is less coupled to order of evaluation and instead a more “declarative logic system”. Also, there is retraction, but typically external to the rules retraction tends to be the more stable given the truth maintenance system mentioned.

mikerod16:02:14

There is no concept in clara of fact “replacement/modification”

bherrmann16:02:10

Thanks!

👍 4
mikerod16:02:34

In terms of “tracing why” something happened

mikerod16:02:01

Clara has a few built in facilities to give back various granularity detailed traces of what happened within the rules engine - which can include inserts and retract etc. For a higher-level view though, it often is enough to just write rules in a way that track their “supporting facts” directly

(defrule do-thing-with-support
  [?a <- A]
  [?b <- B]
  =>
  (r/insert! (map->C {:value :something
                      :support [?a ?b]})))

(defrule do-other-with-support
  [?c <- C]
  [?d <- D]
  =>
  (r/insert! (map->E {:value :other
                      :support [?c ?d]})))

;;; Later

(defn get-supporting-facts [{:keys [support] :as fact}]
  (into support
        (mapcat get-supporting-facts)
        support))

mikerod16:02:12

get-suporting-facts could remove duplicates etc as needed

mikerod16:02:26

and you can also just build helpers for these sorts of things to not be so repetitive in rules

mikerod16:02:22

With truth maintenance, a nice part is if facts becomes invalidated because newer insertions cause formerly fired rules to become false, then they are automatically retracted and the rule network re-establishes consistency across the rules - which would fix these supporting facts as well.