Drools - 使用累积来查找最小值和最大值
我有一个流口水的问题,已经困扰我一段时间了。我想使用累积从 Item 对象列表(包含价格)中找出最低和最高价格。插入一个包含 Item 列表的 Member 对象(包含 Item 对象列表)。
groovy/java source pseudo code
-------------------------------
class Item {
BigDecimal price
}
class Member {
List<Item>> items
}
...
droolsStatefulSession.insert(member)
session.fireAllRules()
...
rule.drl
---------
rule "rule1"
when
member : Member ($itemList : items)
/*
*/
then
System.out.println("condition met...")
end
现在的问题是上述规则是否可能,如果可以,我如何使用流口水累积功能找出具有最低价格和最高价格的商品。我不想使用 java/groovy 实用函数。
我看到“收集”功能允许使用“来自”,然后使用数据源。我想知道“积累”是否与收集相似。
I have a drools question which has been troubling me for some time. I want to find out the min and max price from a list of Item objects (contains price) using accumulate. A Member object (which contails list of Item objects) is inserted which contains the list of Items.
groovy/java source pseudo code
-------------------------------
class Item {
BigDecimal price
}
class Member {
List<Item>> items
}
...
droolsStatefulSession.insert(member)
session.fireAllRules()
...
rule.drl
---------
rule "rule1"
when
member : Member ($itemList : items)
/*
*/
then
System.out.println("condition met...")
end
Now the questions is in the above rule is it possible to if so how do I find out the item with the minimum Price and maximum price using drools accumulate feature. I do not want to use an java/groovy utility functions.
I see the "collect" feature allows to use "from" and then a datasource. I wonder if "accumulate" is similar to collect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需使用“accumulate”,只需执行类似
“That's if your Items is inserted into theworking memory”的操作即可。
No need to use
accumulate
, just do something likeThat's if your Items are inserted into the working memory.
我是流口水规则的新手,我正在尝试解决这个问题。
您可以简单地找出商品的最低和最高价格 - 您必须编写一些规则并需要在 Order 类中添加两个变量:
使用以下规则您可以计算商品的最低和最大值:
输出:---
As我是流口水规则的新手,我想问这是否是正确的程序?或者有其他方法可以解决这个问题吗?
I'm new to the drool rule and I'm trying to solve this issue.
You can find out min and max price of item simply - you have to write some rules and need to add two variable in the Order class:
Using the following rule you can calculate min and max value of an item:
output:---
As I'm new to the drool rule I would like to ask if this is the correct procedure? Or is there another way to solve this problem?