clara

http://www.clara-rules.org/
tcarls 2018-01-29T01:18:06.000157Z

If I have records having a field used for ordering -- like a timestamp -- and want to make rules that reason about or refer to "the immediately preceding X", or "the most recent X to have attribute Y", is Clara well-suited to the purpose?

tcarls 2018-01-29T01:18:34.000149Z

("immediately preceding" relative to another record, that is, as opposed to, say, an accumulator reflecting the globally most recent insert/assertion).

2018-01-29T02:54:32.000013Z

It can be, I’m currently using it to reason about entities that change over time. I have to admit though that I don’t find it that easy to model (although I could be doing things horribly wrong).

2018-01-29T02:56:02.000119Z

e.g., I have entities of type A that can change over time (tracked through a timestamp), and other entities of type B that can change over time in response to the changes to type A (that is, there is a relation B = f(A)), and other entities of type C = f(B) that also change over time in response to changes in B

2018-01-29T02:57:06.000038Z

I find the rules I’m writing to be quite.. cumbersome, and I find myself inserting special facts just to facilitate rule propagation, to prevent e.g., infinite activations

2018-01-29T02:59:05.000134Z

however, the challenges I face come from the /fact/ that changes are inserted as a consequence of rules, if all history was known prior to rule activation, and I wasn’t inserting new facts from rules (that is, growing/extending time within a given session’s fire-rules), and I was simply querying certain states throughout a known and unchanging history, that would be perfectly suitable

2018-01-29T15:20:47.000212Z

@tcarls I think that @dadair has some good things to think about in terms of what you are trying to accomplish. Some of it varies according to the situation. Here is an example that I think meets at least one part of your question though

(defrule immediately-preceding
  [A (= timestamp ?ts)]
  [?preceding <- (acc/max :timestamp :returns-fact true) :from [B (< timestamp ?ts)]]
  =>
  <etc>)

2018-01-29T15:21:57.000312Z

You can use an accumulator that constrains the facts that it accumulates over. By doing this, you can match things more specific/localized/“parameterized”, rather than “global” accumulations.

2👍
tcarls 2018-01-29T16:03:48.000303Z

@mikerod, that's extremely helpful; thank you.

1👍