Drools约束对象不存在,其成员字段包含除P之外的值 [英] Drools constraint object does not exist whose member field contains a value other than P

查看:769
本文介绍了Drools约束对象不存在,其成员字段包含除P之外的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到标题是疯狂的,但它真的是我能想到的最好的。

I realize the title is crazy, but it really is the best I could think of. If anyone has better suggestions please leave them in the comments and I'll edit.

这个问题是这里问题的后续:除了P之外的Drools约束对象在集合

This question is a followup to the question asked here : Drools Constraint object other than P is found in collection

对于那些不想点击的人,那篇文章描述了你想知道的CustomType的事实有一个成员字段包含除了P之外的值。 对此问题的解决方案最终结果如下:

For those who don't want to click, that post describes the solution to the situation in which you want to know if there is a fact of CustomType which has a member field containing a value other than P. The Solution to this problem ended up being the following:

$c: CustomType()
exists Object(this != objectP) from $c.collection

上面的代码工作得很好。我的问题是,我想知道什么时候不存在类型CustomType的对象与此属性。现在,由于行2依赖于在行1中给出的绑定变量,我们不能简单地用非运算符取反行1。这样做会抛出运行时异常。以下是我直觉地想要编写代码,但是请记住它不工作:

The above code works great. My problem is that I want to know when there does not exist an object of type CustomType with this property. Now, since line 2 relies on a bound variable given in line 1, we cannot simply negate line 1 with a not operator. Doing so would throw a runtime exception. The following is how I intuitively want to write the code, but keep in mind it doesn't work:

not $c: CustomType()
exists Object(this != objectP) from $c.collection

I不能简单地否定行2,因为那么规则将需要存在CustomType的至少一个对象。我想知道第一个代码示例不是这样。

I cannot simply negate line 2, because then the rule would require the existence of at least one object of CustomType. I want to know when the first code example is not the case.

我的内部流氓告诉我原来的解决方案可能有缺陷。理想情况下,我们要在CustomType的圆括号()内表示第2行。这将表示更多的是有一个CustomType的属性,而不是有一个CustomType,并有一个对象的属性的线。

My inner drooler tells me the original Solution might be flawed. Ideally we would want to express line 2 within the parentheses() of the CustomType. This would be expressing something more along the lines of "there is a CustomType with the property" rather than "There is a CustomType, and there is an Object with the property". The former we could negate with a not operator, but I'm not sure what to do with the latter.

推荐答案

当你使用一个非操作符时,需要使用这些约束,需要用多行表示,并且否定它们,我想你正在进入推理和真理维护的世界:

When you need to work with constraints such as these, which need to be expressed in multiple lines, and negations of them, I think you're moving into the world of inference and truth maintenance:

http://blog.athico.com/ 2010/01 / drools-inference-and-truth-maintenance.html

ie您的规则可以是:

i.e. Your rules could be something like:

rule "Determine presence of non-P objects" when
    $c: CustomType()
    exists Object(this != objectP) from $c.collection
then
    insertLogical( new ContainsNonP($c) );
end

rule "There are some non-P objects" when
    $c: CustomType()
    exists ContainsNonP(customType == $c)
then
    ...
end

rule "There are no non-P objects" when
    $c: CustomType()
    not exists ContainsNonP(customType == $c)
then
    ...
end

请注意,如果第一个规则尚未启用,上述最终规则可能会启用。如果激活顺序对您的规则很重要,您可以定义一些突出。

Note that the final rule above may activate if the first rule has not yet activated. If the order of activations is important to your rules, you may wish to define some salience.

这篇关于Drools约束对象不存在,其成员字段包含除P之外的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆