Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass node, token arguments to all listener methods #366

Merged
merged 5 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This is a history of changes to clara-rules.

### 0.17.0-SNAPSHOT
* Breaking change affecting clara.rules.listener and clara.tools.tracing namespaces. `insert-facts!` and `retract-facts!` listener methods are now called with `node` and `token` arguments. See [PR 366](https://github.com/cerner/clara-rules/pull/366).
* Add clear-ns-productions! functionality to support clean reloading of rule and query definitions. See [issue 316](https://github.com/cerner/clara-rules/issues/316) for details.
* Support session inspection and fact-graph in ClojureScript. See [issue 307](https://github.com/cerner/clara-rules/issues/307) for details.
* Fix issue when compiling CLJS and session, rules, and fact-types are not in the same namespace or explicitly referred. See [issue 359](https://github.com/cerner/clara-rules/issues/359).
Expand Down
14 changes: 7 additions & 7 deletions src/main/clojure/clara/rules/engine.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@
This should only be used for facts explicitly retracted in a RHS.
It should not be used for retractions that occur as part of automatic truth maintenance."
[facts]
(let [{:keys [rulebase transient-memory transport insertions get-alphas-fn listener]} *current-session*]

(let [{:keys [rulebase transient-memory transport insertions get-alphas-fn listener]} *current-session*
{:keys [node token]} *rule-context*]
;; Update the count so the rule engine will know when we have normalized.
(swap! insertions + (count facts))

(when listener
(l/retract-facts! listener facts))
(l/retract-facts! listener node token facts))

(doseq [[alpha-roots fact-group] (get-alphas-fn facts)
root alpha-roots]
Expand All @@ -320,7 +320,7 @@

;; Track this insertion in our transient memory so logical retractions will remove it.
(if unconditional
(l/insert-facts! listener facts)
(l/insert-facts! listener node token facts)
(do
(mem/add-insertions! transient-memory node token facts)
(l/insert-facts-logical! listener node token facts)))
Expand Down Expand Up @@ -1873,7 +1873,7 @@

:insertion
(do
(l/insert-facts! transient-listener facts)
(l/insert-facts! transient-listener nil nil facts)

(binding [*pending-external-retractions* (atom [])]
;; Bind the external retractions cache so that any logical retractions as a result
Expand All @@ -1887,7 +1887,7 @@

:retraction
(do
(l/retract-facts! transient-listener facts)
(l/retract-facts! transient-listener nil nil facts)

(binding [*pending-external-retractions* (atom facts)]
(external-retract-loop get-alphas-fn transient-memory transport transient-listener)))))
Expand Down Expand Up @@ -1967,7 +1967,7 @@
(map (fn [{bindings :bindings}]

;; Filter generated symbols. We check first since this is an uncommon flow.
(if (some #(re-find #"__gen" (name %)) (keys bindings) )
(if (some #(re-find #"__gen" (name %)) (keys bindings))

(into {} (remove (fn [[k v]] (re-find #"__gen" (name k)))
bindings))
Expand Down
16 changes: 8 additions & 8 deletions src/main/clojure/clara/rules/listener.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
(left-retract! [listener node tokens])
(right-activate! [listener node elements])
(right-retract! [listener node elements])
(insert-facts! [listener facts])
(insert-facts! [listener node token facts])
(alpha-activate! [listener node facts])
(insert-facts-logical! [listener node token facts])
(retract-facts! [listener facts])
(retract-facts! [listener node token facts])
(alpha-retract! [listener node facts])
(retract-facts-logical! [listener node token facts])
(add-accum-reduced! [listener node join-bindings result fact-bindings])
Expand All @@ -35,13 +35,13 @@
listener)
(right-retract! [listener node elements]
listener)
(insert-facts! [listener facts]
(insert-facts! [listener node token facts]
listener)
(alpha-activate! [listener node facts]
listener)
(insert-facts-logical! [listener node token facts]
listener)
(retract-facts! [listener facts]
(retract-facts! [listener node token facts]
listener)
(alpha-retract! [listener node facts]
listener)
Expand Down Expand Up @@ -85,9 +85,9 @@
(doseq [child children]
(right-retract! child node elements)))

(insert-facts! [listener facts]
(insert-facts! [listener node token facts]
(doseq [child children]
(insert-facts! child facts)))
(insert-facts! child node token facts)))

(alpha-activate! [listener node facts]
(doseq [child children]
Expand All @@ -97,9 +97,9 @@
(doseq [child children]
(insert-facts-logical! child node token facts)))

(retract-facts! [listener facts]
(retract-facts! [listener node token facts]
(doseq [child children]
(retract-facts! child facts)))
(retract-facts! child node token facts)))

(alpha-retract! [listener node facts]
(doseq [child children]
Expand Down
8 changes: 4 additions & 4 deletions src/main/clojure/clara/tools/inspect.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
RootJoinNode :join
NegationNode :negation
NegationWithJoinFilterNode :negation} (type node)))
join-node-ids (for [beta-node nodes

join-node-ids (for [beta-node nodes
:let [node-type (node-class->node-type beta-node)]
;; Unsupported and irrelevant node types will have a node-type of nil
;; since the map in node-class->node-type won't contain an entry
Expand All @@ -96,7 +96,7 @@
;; that is contained in rule and query data structures created by defrule
;; and that conforms to the Condition schema.
:negation
[[:not condition]])
[[:not condition]])
concat (map :fact (mem/get-elements-all memory {:id node-id}))))
{}
join-node-ids)))
Expand Down Expand Up @@ -232,7 +232,7 @@
(println prefix " where" constraints))))))

(defn explain-activations
"Prints a human-friend explanation of why rules and queries matched in the given session.
"Prints a human-friendly 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
Expand Down
14 changes: 7 additions & 7 deletions src/main/clojure/clara/tools/tracing.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
(right-retract! [listener node elements]
(append-trace listener {:type :right-retract :node-id (:id node) :elements elements}))

(insert-facts! [listener facts]
(append-trace listener {:type :add-facts :facts facts}))
(insert-facts! [listener node token facts]
(append-trace listener {:type :add-facts :node node :token token :facts facts}))

(alpha-activate! [listener node facts]
(append-trace listener {:type :alpha-activate :facts facts}))

(insert-facts-logical! [listener node token facts]
(append-trace listener {:type :add-facts-logical :token token :facts facts}))
(append-trace listener {:type :add-facts-logical :node node :token token :facts facts}))

(retract-facts! [listener facts]
(append-trace listener {:type :retract-facts :facts facts}))
(retract-facts! [listener node token facts]
(append-trace listener {:type :retract-facts :node node :token token :facts facts}))

(alpha-retract! [listener node facts]
(append-trace listener {:type :alpha-retract :facts facts}))

(retract-facts-logical! [listener node token facts]
(append-trace listener {:type :retract-facts-logical :token token :facts facts}))
(append-trace listener {:type :retract-facts-logical :node node :token token :facts facts}))

(add-accum-reduced! [listener node join-bindings result fact-bindings]
(append-trace listener {:type :accum-reduced
Expand Down Expand Up @@ -115,7 +115,7 @@
[session]
(if-let [listener (->> (eng/components session)
:listeners
(filter #(instance? PersistentTracingListener %) )
(filter #(instance? PersistentTracingListener %))
(first))]
(.-trace ^PersistentTracingListener listener)
(throw (ex-info "No tracing listener attached to session." {:session session}))))