clara

http://www.clara-rules.org/
yyoncho 2018-02-12T16:16:07.000534Z

Here is simplified example of what I am trying to accomplish: I have fact FnHolder which contains how the Temperature facts will be compared/processed. I want to have a rule which produces another fact from the FnHolder and the Temperature but it doesn't trigger the depending rules when a new Temperature which doesn't change the produced value(thus I cannot do the accumulation in the body). This behavior is similar to acc/max which does not trigger if a non-maximal Temperature is inserted. Ideally I would have been able to write the following code but it doesn't run since ?fn is not visible in the custom-accum block. Can you advice? code (defrecord Temperature [location temperature]) (defrecord FnHolder [location other-params]) (defrule chaning [?fn <- FnHolder (= location ?loc)] [?t <- (custom-accum ?fn) :from [Temperature]] => ;; insert facts... ) code

2018-02-12T17:53:27.000219Z

@yyoncho I don’t have an immediate complete answer to that question, but perhaps you could accomplish what you are wanting with a :test condition after the accumulation. Accumulate with something that doesn’t need to be “parameterized”.

2018-02-12T17:54:15.000397Z

Another possibility is to use a sort of joined fact. I’m not sure how appropriate it will be for you, but it would look like:

2018-02-12T17:55:54.000055Z

(defrecord Temperature [location temperature])
(defrecord FnHolder [location other-params])
(defrecord TempWithFn [temp fn-holder])

(defrule combine
  [?fn &lt;- FnHolder  (= location ?loc)]
  [?t &lt;- Temperature]
  =&gt;
  (insert (-&gt;TempWithFn ?t ?fn)))

(defrule chaning
  [?t &lt;- (custom-accum :fn-holder) :from [TempWithFn]]
  =&gt;
  ;; insert facts...
)

2018-02-12T17:56:35.000549Z

I think the custom-accum doesn’t really need the :fn-holder key anymore though. it has the whole fact with all that info on it.