本站首页    管理页面    写新日志    退出


«February 2026»
1234567
891011121314
15161718192021
22232425262728


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7722991
建立时间:2006年5月29日




[Java Open Source]Drools规则引擎的基础语义
软件技术

lhwork 发表于 2006/9/5 9:57:08

   基础语义模块提供了一种在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,而对conditions和consequences是可见的。  如果没有在{{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元素必须具有唯一的名字,也可以包含可选的salience和no-loop属性。如果duration元素被指定,则no-loop就会被忽略。Parameter元素       每个rule元素必须包含至少一个parameter元素,在此rule元素的范围里,parameter元素必须为其identifer属性使用一个唯一的名字。单独的,parameter元素不能做任何事。它需要一个级连的元素来声明一个对象类型,象class,class-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(一) 翻译  500)this.width=500'>walk_in_the_rain500)this.width=500'>2006-05-05 15:23:57500)this.width=500'>查看评论500)this.width=500'> 500)this.width=500'>    基础语义模块       基础语义模块提供了一种在XML种构建RuleSet(规则集)的语言,单独地,基础语义模块不能写一个完整而有效地规则文件,它必须和别的语义模块结合,这些模块包括Java语义模块、Groovy语义模块、Pythos语义模块或者是一个自定义地,指定域地语义模块。语法指南rule-set 元素       每个DRL文件必须有一个rule-set元素,而且名字在规则基础和定义绑定命名空间是唯一的。attributeoptional?descriptionnamenoThis 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,而对conditions和consequences是可见的。       如果没有在{{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元素必须具有唯一的名字,也可以包含可选的salience和no-loop属性。如果duration元素被指定,则no-loop就会被忽略。attributeoptional?descriptionnamenoThis string must uniquely identify the rule in the rule-set.salienceyesDefault to 0. Must be numeric, integral, signed. Must be numeric, non-float values, can be negative. Example: salience="-42", salience="2".no-loopyesDefault to "false". Must be boolean. Example: no-loop="true", no-loop="false".xor-groupyesAllow 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元素不能做任何事。它需要一个级连的元素来声明一个对象类型,象class,class-field,和semaphore object。attributeoptional?descriptionidentifiernoThis string must uniquely identify the parameter in the rule<parameter identifier="goodbye">  <class>java.lang.String</class></parameter> class元素       class元素是用在parameter元素内部的一种对象类型的实现。它没有属性,它的内容既可以是一个全路径类,或者是一个从预先导入的包中的类的名字。attributeoptional?description<class>java.util.HashMap</class><class>HashMap</class>class-field元素       class-field元素是用在parameter元素内部的一种对象类型的实现。它不仅仅限制要给出class参数,而且规定需要为给定的字段(field)指定一个值(value),这个字段别限定是字符串类型,字段的值也是一个静态字符串。attributeoptional?descriptionfieldnoThe name of the field of the type String, written to JavaBean specifications with setters and gettersvaluenoStatic 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-set的import导入,或者他们在java.lang包里。Functions:       用户定义函数允许将代码片断置于规则集中,这些函数在规则里能被引用,注意的是,这些方法不许是public static形式的。例如:


阅读全文(2004) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 1.395 second(s), page refreshed 144837306 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号