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

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

Open
WilliamParker opened this issue Nov 5, 2019 · 1 comment
Labels

Comments

@WilliamParker
Copy link
Collaborator

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.

@EthanEChristian
Copy link
Contributor

@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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants