oracle-samples/clara-rules

Allow ties in comparison-based accumulators

Opened this issue · 0 comments

We have accumulators that allow logic like "Get the maximum WindSpeed. If there is a tie choose any WindSpeed." This would be written like

(defrecord WindSpeed [windspeed location])
(defrule max-windspeed
      [?windspeeds <- (acc/max :windspeed :returns-fact true) WindSpeed]
      => ;; RHS logic)

However, if the desired behavior is to get every WindSpeed with the maximum windspeed this won't work. For example, suppose we have

(-> (mk-session [max-windspeed])
       (insert (->WindSpeed 10 "LGA") (->WindSpeed 10 "JFK") (->WindSpeed 5 "DFW"))
       fire-rules)

The accumulator will select one of the two; none of our built-in accumulators will select both windspeeds of 10.

To be clear, I am not proposing that we change the existing behavior of our accumulators, but adding the option for this kind of behavior. My first thought would be to add a :returns-all-facts option similar to the :returns-fact option but other API options could be considered (and I certainly haven't given the naming any more than cursory thought).