流口水的规则继承 [英] drools rules inheritance

查看:86
本文介绍了流口水的规则继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对流口水并不陌生,并且熟悉使用extends关键字继承规则。问题是否有继承多个规则的方法?这类似于在Java类上使用多个接口。这是一个我希望它如何工作的示例,但是我在规则3上遇到错误:

I am new to drools and am familiar with using the extends keyword to inherit a rule. Question is there a way to inherit multiple rules? This would be similar to using multiple interfaces on a java class. Here's an example of how I would expect it to work but I get an error on rule 3:

rule "rule 1"
when //person name == "John"
then //print "John"
end

rule "rule 2"
when //person last name == "Smith"
then //print "Smith"
end

rule "rule 3" extends "rule 1", "rule 2"
when //person age > 20
then //print John Smith is older than 20
end

谢谢黎明

推荐答案

我知道该线程很旧,但是可以执行以下操作:

I know that this thread is old but it's possible to do the following:

rule "first name is John rule"
    when
        $p : Person(  name == 'John' )
    then
end

rule "last name is Smith rule" extends "first name rule"
    when
        eval( $p.getLastName() == "Smith" )
    then
end

rule "age older than 20 rule" extends "last name rule"
    when
        eval ( $p.getAge() > 20 )
    then
        System.out.println($p.getFirstName() + " " + $p.getLastName() +
                " is older than 20");
end

rule "age younger than 20 rule" extends "last name rule"
    when
        eval ( $p.getAge() < 20 )
    then
        System.out.println($p.getFirstName() + " " + $p.getLastName() +
                " is younger than 20");
end

如您所见,您可以从继承超级规则的超级规则创建链接规则声明的变量。

As you can see, you can create a chained rule from super rules inheriting their declared variables.

这篇关于流口水的规则继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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