clara

http://www.clara-rules.org/
Joel 2019-05-03T14:21:29.056700Z

Couple of questions 1) I see there is no "update!" --- is retract! followed by insert! considered non-idiomatic?

eraserhd 2019-05-03T14:37:39.066800Z

In general, updating a fact would make truth maintenance really hard, if not impossible. If you find yourself retracting and inserting a fact on a right-hand-side, you are probably also going to run afoul of truth maintenance, likely by creating an infinite loop.

👍 2
eraserhd 2019-05-03T14:38:26.067700Z

Logically, if a fact is no longer true because of a new piece of data, you should have an additional condition on the left-hand-side of the original rule.

eraserhd 2019-05-03T14:38:51.068300Z

Which allows truth maintenance to clear it up.

💯 1
🙂 1
Joel 2019-05-03T14:39:05.068800Z

2) I have a case where I take measurements of events something like {"eventX" [ (:limit 5 :prior (5 hrs)) (:limit 10 :prior (1 day)) ]} also I need to +1 those measures if they just now happened based on rule. (I don't have a list of events over that time, just the prior totals) I'm guessing the short answer is I need to "normalize the list" into individual facts and leverage insert-all! as well as use an accumulator (prior total + 1?), but then I need to accumulate and match against the limit, and how to do this with a flexible list is the part I'm not currently seeing. Particularly totaling over each period to compare against limit.

eraserhd 2019-05-03T14:43:33.069400Z

I would absolutely break down the measurements into independent facts.

eraserhd 2019-05-03T14:44:57.071300Z

I'm not sure how you are saying :prior works. Do you want a rule to fire a rule if you get an event more than :limit in the last :prior?

Joel 2019-05-03T14:45:51.072500Z

so there's the existing count (from DB) if that count + (just now happened) > limit fire rule.

eraserhd 2019-05-03T14:47:18.073600Z

You've inserted multiple facts that has the database count of events of a particular type?

Joel 2019-05-03T14:48:33.074900Z

i can do that... currently the logic is the LHS side fetches the info (uses cache)

Joel 2019-05-03T14:48:41.075100Z

(java call)

Joel 2019-05-03T14:49:10.075700Z

the final piece is maybe something like [ EventCount (?name name)(?limit limit)(?period period) (>= ?limit ( accumulate total for ?period ?name)) ; pseudocode

Joel 2019-05-03T14:50:08.076600Z

but then accumulating will be redundant.

eraserhd 2019-05-03T14:50:33.077200Z

Assuming you aren't using an immutable, global database, you will likely have trouble with consistency if you put database calls on the left-hand-side.

Joel 2019-05-03T14:51:41.078500Z

(the cache fixes that part, only refetches for another session)

Joel 2019-05-03T14:52:16.079200Z

but that doesn't give me a flexible list of periods

eraserhd 2019-05-03T14:52:28.079500Z

You have access to the session on the left-hand-side?

eraserhd 2019-05-03T14:52:36.079700Z

(in a rule at all, in fact?)

Joel 2019-05-03T14:52:48.080Z

no... its a java bean inserted into WM

eraserhd 2019-05-03T14:53:09.080400Z

what's a WM?

Joel 2019-05-03T14:53:24.080800Z

but a new one for each ... sorry firing. (working memory : clara currently drools 🙂 )

Joel 2019-05-03T14:54:00.081400Z

basically the bean is inserted before fire rules.

eraserhd 2019-05-03T14:54:07.081600Z

ah, right. But this will have the consistency issue I'm talking about. If the count changes in the database, it will not refire a rule.

Joel 2019-05-03T14:54:16.081800Z

not an issue.

Joel 2019-05-03T14:54:30.082400Z

it caches the call and keeps it for rest of that firing.

Joel 2019-05-03T14:54:40.082700Z

and that's acceptable.

eraserhd 2019-05-03T14:54:45.082900Z

Ahhh, I see.

eraserhd 2019-05-03T14:55:05.083300Z

It presents an immutable snapshot to the session. That's kind of neat.

Joel 2019-05-03T14:55:44.084Z

but currently we write rules and add to them if we add more periods, that sort of thing... rather have the list of periods flexible and rules take care of.

Joel 2019-05-03T14:56:31.084900Z

I think I need two defrecords one for name/period combo and another for keeping the count?

Joel 2019-05-03T14:57:48.085900Z

so match on all periods records and accumulate on the counting records (i think).

Joel 2019-05-03T14:58:19.086900Z

i think i was trying to keep this all kind of in one structure, and that's not do-able.

eraserhd 2019-05-03T14:58:23.087100Z

I think doing arbitrary, data-driven periods will be hard without generating rules from data.

eraserhd 2019-05-03T14:59:19.087500Z

Well, maybe not the way you are doing it.

Joel 2019-05-03T15:00:32.088900Z

yeah, i'm going to see what that looks like if I can get it working refine from there... Thanks!