是否可以通过DRL文件中的规则调用查询?

问题描述 投票:1回答:1

我需要将窗口规则链接到窗口规则。我的用例是:

如果在5分钟的窗口中出现温度> 50大于10,则在该窗口框架或该窗口数据上的任何其他链规则中找到温度的最大值(平均值)。

我尝试了以下方法:

query getFactFromMemory(long time)
   $fact : Fact(timepoing < (drools.getWorkingMemory().getSessionClock().getCurrentTime() + time))
end

rule "window rule"
when
   //condition
then
   //action
end

rule "chain rule"
when
   //condition
then
  getFactFromMemory(1000L)
 //loop over facts and then perform some action
end

调用查询时出现错误。我尝试在部分时间调用查询并将其分配给变量,但同时也会出现错误(Query's must use positional or bindings, not field constraints:1000LQuery binding is not supported by non-abductive queries : $variable)。

有人可以帮助我解决此错误或建议其他解决方法吗?

drools drools-fusion
1个回答
0
投票

我们可以通过调用drools.getKieRuntime()在drl中获取drools运行时对象。因此,该问题的工作规则是:

query getFactFromMemory(long time)
   $fact : Fact(timepoing < (drools.getWorkingMemory().getSessionClock().getCurrentTime() + time))
end

rule "window rule"
when
   //condition
then
   //action
end

rule "chain rule"
when
   //condition
then
  getFactFromMemory(1000L)
 //loop over facts and then perform some action
end
© www.soinside.com 2019 - 2024. All rights reserved.