英文:
How to detect patterns involving multiple unordered conditions
问题
让我们假设我想检测这样的模式:
from every A -> B or C or D # P0,Siddhi 不接受
其中 B、C 和 D 可以以任何顺序发生。根据文档:
Siddhi 只能同时使用关键词如 and、or 和 not 逻辑相关两个条件。当需要逻辑相关超过两个条件时,可以使用多个模式查询以链式方式进行,同时将两个逻辑条件相关联并将输出流到下游查询,以与其他逻辑条件相关联。
所以,我猜我应该这样做:
from every A -> B # P1
from every A -> C # P2
from every A -> D # P3
然而,上述重写与原始模式不完全等价。例如,给定事件序列
A1 D1 C1 B1
P3 在 D1 之后触发,P2 在 C1 之后触发,P1 在 B1 之后触发,而原始模式 P0 只会在 D1 之后触发一次(假设 P0 有效)。
类似地,如何处理以下形式的模式?
from every A -> B and C and D # Siddhi 也不接受
一般来说,是否有计划支持同时相关多于两个条件的情况?否则,这些模式的实现可能会变得相当混乱和容易出错。在此期间,文档可以扩展一些内容,以说明如何实现本问题中考虑的几种简单情况。
英文:
Let's say I want to detect a pattern like this:
from every A -> B or C or D # P0, not accepted by Siddhi
where B, C, and D can happen in any order. From the docs:
> Siddhi can only logically correlate two conditions at a time using keywords such as and, or, and not. When more than two conditions need to be logically correlated, use multiple pattern queries in a chaining manner, at a time correlating two logical conditions and streaming the output to a downstream query to logically correlate the results with other logical conditions.
So, I guess that I should do something like this:
from every A -> B # P1
from every A -> C # P2
from every A -> D # P3
However, the above rewrite is not strictly equivalent to the original pattern. For example, given the sequence of events
A1 D1 C1 B1
P3 will trigger after D1, P2 after C1, and P1 after B1, whereas the original pattern P0 would only trigger once after D1 (assuming that P0 was valid).
Similarly, how should one deal with patters of the form
from every A -> B and C and D # not accepted by Siddhi either
In general, are there plans to support correlating more than two conditions at a time? Otherwise the implementation of these patterns can get quite messy and error-prone. In the meantime, the documentation could be extended a bit to illustrate how to implement a couple of simple cases as the ones considered in this question.
答案1
得分: 1
谢谢您对文档的反馈,我们将在新的示例部分中加入复杂示例,目前正在进行中。
在GitHub中回答问题。
是的,这是Siddhi模式实现中的设计级限制。我们有一些计划来改进这一点,它已经包含在我们的路线图中。
如果您考虑您的示例,(A and B and C) or (D and E and F)
,那么您必须编写5个模式查询,如下所示。
A and B -> output1
output1 and C -> output2
D and E -> output3
output3 and F -> output4
output2 or output4 -> finalOutput
同样地,根据要求,我们必须将查询写入多个子查询中。我明白这会增加一些负担,但不幸的是,这是目前唯一的选项。
英文:
Thank you for the feedback on documentation, we will incorporate complex example in the new Examples section currently in the progress
Yes, it is a design level limitation in Siddhi pattern implementation. There are some plans to improve this and it is in our roadmap.
If you consider your example, (A and B and C) or (D and E and F)
then you have to write 5 pattern queries as shown below.
A and B -> output1
output1 and C -> output2
D and E -> output3
output3 and F -> output4
output2 or output4 -> finalOutput
Likewise, we have to write the queries into multiple subqueries based on the requirement. I do understand that it adds some burden but unfortunately, this is the only option for now.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论