本站不再更新,欢迎光临 java开发技术网
随笔-230  评论-230  文章-8  trackbacks-0
   基础语义模块提供了一种在XML种构建RuleSet(规则集)的语言,单独地,基础语义模块不能写一个完整而有效地规则文件,它必须和别的语义模块结合,这些模块包括Java语义模块、Groovy语义模块、Pythos语义模块或者是一个自定义地,指定域地语义模块。

语法指南。

rule-set 元素

    
   每个DRL文件必须有一个rule-set元素,而且名字在规则基础和定义绑定命名空间是唯一的。

    如<rule-set name="abc">那么在整个drools中name属性的值必须是唯一的。
 

Import元素

    对于任何想引用一个Class的元素,通过Import来指定,这个元素的使用和编写Class类引入类的操作一样。

application-data 元素

  
application-data元素允许对象不需要将它们断言进入Working Memory,而对conditionsconsequences是可见的。

  如果没有在{{rule-set}}里定义,则Application data就不能被设置。Application data设置:

workingMemory.setApplicationData("amount", newInteger(3));

rule-set里定义一个 application data:

<application-data identifier="amount">java.lang.Integer</application-data>

Rule元素

       每个rule-set必须包含至少一个rule元素。在这个rule-set里,每个rule元素必须具有唯一的名字,也可以包含可选的salienceno-loop属性。如果duration元素被指定,则no-loop就会被忽略。

Parameter元素

       每个rule元素必须包含至少一个parameter元素,在此rule元素的范围里,parameter元素必须为其identifer属性使用一个唯一的名字。单独的,parameter元素不能做任何事。它需要一个级连的元素来声明一个对象类型,象classclass-field,semaphore object。如:


<parameter identifier="goodbye">

  <class>java.lang.String</class>

</parameter>



class元素

       class元素是用在parameter元素内部的一种对象类型的实现。它没有属性,它的内容既可以是一个全路径类,或者是一个从预先导入的包中的类的名字。

class-field元素

       class-field元素是用在parameter元素内部的一种对象类型的实现。它不仅仅限制要给出class参数,而且规定需要为给定的字段(field)指定一个值(value),这个字段别限定是字符串类型,字段的值也是一个静态字符串。

如:

<class-field field="name" value="A">State</class-field>

这和下面代码段是类似的:

<parameter identifier="state">

    <class>State</class>

</parameter>

 

<java:condition>state.getName().equals("A")<java:condition>

Java规则引擎学习-drools(一)
 翻译  walk_in_the_rain2006-05-05 15:23:57查看评论  
  

基础语义模块

       基础语义模块提供了一种在XML种构建RuleSet(规则集)的语言,单独地,基础语义模块不能写一个完整而有效地规则文件,它必须和别的语义模块结合,这些模块包括Java语义模块、Groovy语义模块、Pythos语义模块或者是一个自定义地,指定域地语义模块。

语法指南

rule-set 元素

       每个DRL文件必须有一个rule-set元素,而且名字在规则基础和定义绑定命名空间是唯一的。

attribute

optional?

description

name

no

This string must uniquely identify the rule-set in the rule base

<rule-set name="HelloWorld"

          xmlns="http://drools.org/rules"

          xmlns:java="http://drools.org/semantics/java"

          xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"

          xs:schemaLocation="http://drools.org/rules rules.xsd

                             http://drools.org/semantics/java java.xsd">

  ....

  ....

<rule-set>

 

Import元素

       对于任何想引用一个Class的元素,通过Imports来指定。

       元素的实体可以是一个全路径引用:

<import>java.util.HashMap</import>

或者是一个动态的import

<import>java.util.*</import>

 

application-data 元素

       application-data元素允许对象不需要将它们断言进入Working Memory,而对conditionsconsequences是可见的。

       如果没有在{{rule-set}}里定义,则Application data就不能被设置。Application data设置:

workingMemory.setApplicationData("amount", newInteger(3));

rule-set里定义一个 application data:

<application-data identifier="amount">java.lang.Integer</application-data>

 

Rule元素

       每个rule-set必须包含至少一个rule元素。在这个rule-set里,每个rule元素必须具有唯一的名字,也可以包含可选的salienceno-loop属性。如果duration元素被指定,则no-loop就会被忽略。

attribute

optional?

description

name

no

This string must uniquely identify the rule in the rule-set.

salience

yes

Default to 0. Must be numeric, integral, signed. Must be numeric, non-float values, can be negative. Example: salience="-42", salience="2".

no-loop

yes

Default to "false". Must be boolean. Example: no-loop="true", no-loop="false".

xor-group

yes

Allow only a single rule within a group to fire, all other rules in that group are then removed from the agenda. A rule can be in only a single xor group.

<rule name="Hello World" salience="10" no-loop="true" xor-group="group1">

  ...

  ...

</rule>

 

Parameter元素

       每个rule元素必须包含至少一个parameter元素,在此rule元素的范围里,parameter元素必须为其identifer属性使用一个唯一的名字。单独的,parameter元素不能做任何事。它需要一个级连的元素来声明一个对象类型,象classclass-field,semaphore object

attribute

optional?

description

identifier

no

This string must uniquely identify the parameter in the rule

<parameter identifier="goodbye">

  <class>java.lang.String</class>

</parameter>

 

class元素

       class元素是用在parameter元素内部的一种对象类型的实现。它没有属性,它的内容既可以是一个全路径类,或者是一个从预先导入的包中的类的名字。

attribute

optional?

description

<class>java.util.HashMap</class>

<class>HashMap</class>

class-field元素

       class-field元素是用在parameter元素内部的一种对象类型的实现。它不仅仅限制要给出class参数,而且规定需要为给定的字段(field)指定一个值(value),这个字段别限定是字符串类型,字段的值也是一个静态字符串。

attribute

optional?

description

field

no

The name of the field of the type String, written to JavaBean specifications with setters and getters

value

no

Static value constraint for the given field

<class-field field="name" value="A">State</class-field>

这和下面代码段是类似的:

<parameter identifier="state">

    <class>State</class>

</parameter>

 

<java:condition>state.getName().equals("A")<java:condition>

 

Semaphore元素

    Semaphore元素用在parameter元素内部的一种特别对象类型的实现。它提供了在规则里使用的全局的命名变量,在那里,identifier就是这个全局名字。这对于控制执行是非常有用的。



duration元素

       duration元素能够使Temporal Rules,如果在一个给定的时间内,temporal Rules仍旧是true

condition元素

       condition元素通常被用于确定一个指定的条件是否存在。一个rule需要一个或者多个condition,当condition条件为true,则结果将被执行或者被设置。

consequence元素

       consequence元素让我们在Working Memory里,通过drools变量使用java语言语义去改变信息。当写Java consequence模块时,有几点需要注意。

       首先能够使用使用预先定义在规则里parameter元素的任何变量,也可以对application-data进行读取。如果象创建别的变量,必须导入在consequence内部导入他们的类,除非它们已经通过rule-setimport导入,或者他们在java.lang包里。


Functions

       用户定义函数允许将代码片断置于规则集中,这些函数在规则里能被引用,注意的是,这些方法不许是public static形式的。例如:

posted on 2006-09-01 11:24 有猫相伴的日子 阅读(2453) 评论(2)  编辑  收藏 所属分类: drools

评论:
# re: Drools规则引擎的基础语义 2006-09-01 11:55 | 江南白衣
Drools3.0 不搞这种XML式定义啦:)  回复  更多评论
  
# re: Drools规则引擎的基础语义 2006-09-01 14:51 | Schweigen
Drools3.0 还是有XML 定义模块的,不过确实没有什么人用了:)  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
本站不再更新,欢迎光临 java开发技术网