??
基礎語義模塊提供了一種在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(一) |
| ?翻譯?? |  | walk_in_the_rain |  | 2006-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,而對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就會被忽略。 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元素不能做任何事。它需要一個級連的元素來聲明一個對象類型,象class,class-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-set的import導入,或者他們在java.lang包里。
Functions:
?????? 用戶定義函數允許將代碼片斷置于規則集中,這些函數在規則里能被引用,注意的是,這些方法不許是public static形式的。例如:
posted on 2006-09-01 11:24
有貓相伴的日子 閱讀(2476)
評論(2) 編輯 收藏 所屬分類:
drools