clara-rules icon indicating copy to clipboard operation
clara-rules copied to clipboard

Duplicate paths in :or condition not leading to multiple facts being inserted

Open WilliamParker opened this issue 5 years ago • 1 comments

This test fails:

(def-rules-test test-or-sharing-same-condition-in-same-production-duplicate-path
    {:rules [single-rule [[[:or
                            [:and [:or
                                   [::a]
                                   [::b]]
                             [::d]
                             ]
                            [:and
                             [::a]
                             [::d]]]]

                          (insert! {:fact-type ::c})]]

     :queries [c-query [[] [[?c <- ::c]]]]

     :sessions [empty-session [single-rule c-query] {:fact-type-fn :fact-type}]}

    (let [session (-> empty-session
                      (insert {:fact-type ::a})
                      (insert {:fact-type ::d})
                      fire-rules)]

      (is (= (query session c-query)
             [{:?c {:fact-type ::c}}
              {:?c {:fact-type ::c}}]))))

This test was created for issue 436 but commented out since it fails. If fails both before and after the fixes for issue 433.

WilliamParker avatar Nov 05 '19 08:11 WilliamParker

@WilliamParker, This does seem counter intuitive compared to the behavior of :or in most other contexts, if i am not mistaken this seems to be a side effect of the dnf standardization that clara performs on productions, ie.

(or 
  (and 
     (or ::a ::b)
      ::d)
  (and ::a ::d))

becomes

(or 
  (and ::a ::d)
  (and ::b ::d)
  (and ::a ::d))

The top and bottom and are seen as the same thus clara "de-dupes" them via node sharing. This also means that technically this trivial rule shares the same problem (sans clara's dnf conversion):

(defrule simple-rule 
  [:or 
     [::a]
     [::a]]
  =>
  (insert! something))

EthanEChristian avatar Feb 01 '20 04:02 EthanEChristian