可能是流氓时间推理中的一个错误?

时间:2016-02-08 16:48:19

标签: drools rule-engine

我想测试一个对drools进行时间推理的场景。我有一个带有时间戳字段的Message类。当这个类的每个事件都被drools接收时,插入到工作内存中并调用fireAllRules()。在每次射击中,我想打印配对消息ml和mo的时间戳,即在[0s,160s] mo之后的ml。当我写下我的规则时,每件事情都没问题。

rule "Rule 1"
when
    ml: Message()
    mo: Message(ml after[0s,160s] this)
then
    System.out.println("ml:"+new Date(ml.timestamp));
    System.out.println("mo:"+new Date(mo.timestamp));
end

输出:

Message received{"timestamp":"Feb  8 19:39:45", ... }
ml:Sun Feb 08 19:39:45 IRST 1970
mo:Sun Feb 08 19:39:45 IRST 1970
Message received{"timestamp":"Feb  8 19:40:04", ... }
ml:Sun Feb 08 19:40:04 IRST 1970
mo:Sun Feb 08 19:39:45 IRST 1970
ml:Sun Feb 08 19:40:04 IRST 1970
mo:Sun Feb 08 19:40:04 IRST 1970
Message received{"timestamp":"Feb  8 19:40:15", ... }
ml:Sun Feb 08 19:40:15 IRST 1970
mo:Sun Feb 08 19:40:04 IRST 1970
ml:Sun Feb 08 19:40:15 IRST 1970
mo:Sun Feb 08 19:39:45 IRST 1970
ml:Sun Feb 08 19:40:15 IRST 1970
mo:Sun Feb 08 19:40:15 IRST 1970

但是当我以这种形式重写规则时,输出效果不佳。

rule "Rule 1"
when
    ml: Message()
    mo: Message(this before[0s,160s] ml)
then
    System.out.println("ml:"+new Date(ml.timestamp));
    System.out.println("mo:"+new Date(mo.timestamp));
end

输出:

Message received{"timestamp":"Feb  8 19:41:40", ... }
ml:Sun Feb 08 19:41:40 IRST 1970
mo:Sun Feb 08 19:41:40 IRST 1970
Message received{"timestamp":"Feb  8 19:41:57", ... }
ml:Sun Feb 08 19:41:57 IRST 1970
mo:Sun Feb 08 19:41:57 IRST 1970
Message received{"timestamp":"Feb  8 19:42:02", ... }
ml:Sun Feb 08 19:42:02 IRST 1970
mo:Sun Feb 08 19:42:02 IRST 1970

为什么在第二种形式输出不好?当我为时间运算符使用两个参数时观察到这个问题,“this”是第一个操作数。 “这之前[0s,160s] ml”是否等于“0s,160s之后的ml”这个“? 第二种形式是错误?

0 个答案:

没有答案