oracle-samples/clara-rules

Multiple results are returned when a fact matches multiple constraints in a rule

xiuwyang opened this issue · 3 comments

Hi,

Is this a bug or by design that when a fact matches multiple constraints in one rule, the query returns multiple same result?

For example, when I executed https://github.com/cerner/clara-examples/blob/master/src/main/clojure/clara/examples/java/shopping.clj, it gave me

JavaBean Shopping examples from Clojure:     
Promotion: Awesome promotion for our favorite VIP!

and then when I modified that rule to contain an or constraint

(defrule awesome-promotion-for-vips
   "Creates an awesome promotion for VIPs that spend more than $200"
   [:or [Customer (= true VIP)]
   [Order (> total 200)]]
   =>
   (insert! (Promotion. "Awesome promotion for our favorite VIP!")))

it gave me

JavaBean Shopping examples from Clojure:
Promotion: Awesome promotion for our favorite VIP!
Promotion: Awesome promotion for our favorite VIP!

Is the number of results tied with the number of constraints matched in the rules instead of the number of rules? Thank you

@xiuwyang ,
The use of :or as described in your example could be thought of as 2 separate rules.

(defrule awesome-promotion-for-vips-A
   "Creates an awesome promotion for VIPs that spend more than $200"
   [Customer (= true VIP)]
   =>
   (insert! (Promotion. "Awesome promotion for our favorite VIP!")))

and

(defrule awesome-promotion-for-vips-B
   "Creates an awesome promotion for VIPs that spend more than $200"
   [Order (> total 200)]
   =>
   (insert! (Promotion. "Awesome promotion for our favorite VIP!")))

When the example runs it inserts both, a VIP customer and Order > 200 thus both LHS are satisfied and progress to the RHS and each insert a Promotion fact. Therefore there would be two Promotions captured by the query and cause the println twice.

From my understanding of clara's DSL, this would be expected as the top level :or operator doesn't support short circuiting.

Edit: Additional info about top level boolean statements can be found here http://www.clara-rules.org/docs/booleans

@xiuwyang,
Can I close this issue out?

@EthanEChristian,

yeah, thank you for answering the question.