2012-07-04 41 views
4

我想使用決策表基於流水線中越來越小的值實現簡單的規則。如何在drools中使用決策表實現更少和更多的規則?

這是很容易實現DRL的規則,例如:

rules "less than" 
when Example(value < 10) 
then 
    System.out.println("Less than 10") 
end 

rules "equals" 
when Example(value = 10) 
then 
    System.out.println("Equals 10") 
end 

rules "greater than" 
when Example(value > 10) 
then 
    System.out.println("Greater than 10") 
end 

但我怎麼能在Drools中它轉化爲決策表?到目前爲止,我所看到的所有例子都是在條件單元中完成比較。甚至有可能在價值單元中進行比較?

我見過的所有例子都是格式:

CONDITION       | ACTION 
Example       | 
value        | 
-----------------------------------|------------------------------------- 
10         | System.out.println("equals to 10") 

但只適用於1條規則,並執行以下完全有不同的含義:

CONDITION | CONDITION | CONDITION | ACTION 
Example 
value  | value > $1 | value < $1 | 
-----------+------------+------------+---------------- 
10   | 10   | 10   | ??? 

甚至可以做下列?

CONDITION       | ACTION 
Example       | 
value        | 
-----------------------------------+---------------------------------------- 
10         | System.out.println("equals to 10") 
> 10        | System.out.println("greater than 10") 
< 10        | System.out.println("less than 10") 

什麼是實施這些規則的正確方法?

回答

6

我發現只要將$ param放在約束字段單元格中,並將整個約束放在值單元格中,我就可以實現我所需要的。因此,決策表看起來是這樣的:

CONDITION      | ACTION 
Example      | 
$param       | System.out.println("$param"); 
-------------------------------+----------------------------------- 
value == 10     | equals to 10 
value > 10      | greater than 10 
value < 10      | less than 10  
+0

我們可以絃樂做同樣的比較。我嘗試過,但不斷出現錯誤。 –

1

你可以看看這個

http://s11.postimage.org/oya6zxr83/Screenshot.png

下面我們就用戶位置和用戶數,並檢查計數小於每個城市的初始計數如果條件滿足,循環將運行至循環條件。

希望它會有幫助。

+2

你可以將你的例子的內容移到你的答案中嗎?將答案與外部資源聯繫起來對知識獲取並不是很有幫助,但未來形象可能不存在。 –

5

可以將該部分條件作爲值。在標題中,您可以給「值$ param」進行評估。 (順便說一句,以便能夠像== 10輸入值必須更改單元格的格式在Excel中文字)

CONDITION       | ACTION 
Example       | 
value $param      | 
-----------------------------------+---------------------------------------- 
== 10        | System.out.println("equals to 10") 
in (10, 11)      | System.out.println("is 10 or 11") 
> 10        | System.out.println("greater than 10") 
< 10        | System.out.println("less than 10") 
相關問題