【Mastering JBoss Drools 6】筆記 基本操作
Drools最基本最常用的有以下四種
布林運算與數值運算規則
rule "Add 5% discount for minors or seniors"
when $o: Order(customer.age < 18 || customer.age > 60)
then $o.increaseDiscount(0.05);
end
基於集合的規則
(contains and memberOf) 他們主要用來檢測集合是否包含不包含某元素
rule "print orders with pencils in them" when $i: Item(name == "pencil") $ol: OrderLine(item == $i) $o: Order($ol memberOf orderLines, orderLines contains $ol) then System.out.println("order with pencils: " + $o); end
from: 找到集合裡面對應條件的資料
rule "match all famale by from"
when
Company($persons: persons)
$p:Person(gender == Person.GENDER_FEMALE) from $persons
then
System.out.println("girl'name is " + $p.getName());
end
Person p = new Person(); p.setName("Wang"); p.setGender(Person.GENDER_FEMALE); Person p2 = new Person(); p2.setName("Depu"); p2.setGender(Person.GENDER_MALE); List<Person> persons = new ArrayList<>(); persons.add(p); persons.add(p2); Company c = new Company(); c.setPersons(persons); ks.insert(c);
collect(以下的程式碼的意思是把是Person物件的都集中起來放在一個List裡面)
rule "match all famale by collect"
when
$grils:List(size>0) from collect(Person(name=="Depu"))
then
System.out.println("gril's size " + $grils.size());
end
@Test public void testCollect() { Person p = new Person(); p.setName("Wang"); p.setGender(Person.GENDER_FEMALE); Person p2 = new Person(); p.setName("Depu"); p.setGender(Person.GENDER_MALE); ks.insert(p); ks.insert(p2); int count = ks.fireAllRules(); System.out.println("total run " +count+ " rules"); }
正則匹配規則
rule "validate customer emails"
when
$c: Customer(email not matches "[A-Za-z0-9-.][email protected][A-Za-z0-9-.]+$")
then
$c.setEmail(null); //invalidate email
end
Accumulate 關鍵字 這是一個很強大的功能,它提供了強大的過濾功能,比如使用者A有一批訂單,使用者實體類裡面有一個集合是儲存的訂單,通過這個關鍵字可以根據訂單的欄位過濾出符合條件的訂單
以下的程式碼表達的意思是,對Account類的balance求平均值,將最終的計算結果放在$averageBalancez中
query averageBalanceQuery
Number( $averageBalance : doubleValue ) from accumulate(
$account : Account($balance : balance), average($balance))
end
@Test
@Parameters("17.00,50.0,22.0,5.0")
public void testAverage(double val1, double val2, double val3, double val4){
ks.fireAllRules();
System.out.println(getAverageBalance());// 0.0
ks.insert(new Account(val1));
ks.insert(new Account(val2));
ks.insert(new Account(val3));
ks.insert(new Account(val4));
System.out.println(getAverageBalance());// 23.5
}
BigDecimal getAverageBalance() {
QueryResults queryResults = ks.getQueryResults("averageBalanceQuery");
return BigDecimal.valueOf((Double) queryResults
.iterator().next().get("$averageBalance"));
}
相關推薦
【Mastering JBoss Drools 6】筆記 基本操作
Drools最基本最常用的有以下四種 布林運算與數值運算規則 rule "Add 5% discount for minors or seniors" when $o: Order(customer.age < 18 || customer.age >
【C#學習之路】001.基本操作
arp main cti 字符 thread 程序 AI 報錯 float 001【HelloWorld】分析代碼塊 //這裏是註釋 下面是引入命名空間 using System; using System.Collections.Generic; using Syst
【Java學習-J.160406.0.6】筆記5-Linux基礎-linux程序管理
檢視和管理linux程序 程序中的狀態 R-程序已經排程,準備好執行;執行中 S-等待,使用者可以發訊號,可到R狀態 D-等待,不接受使用者指令-使用者無法控制 K-等待,接受使用者中斷訊號 Z-僵死,在退出時產生異常,僵死不接受使用者訊號,不釋放資源 PS 檢視列
【Spark深入學習-11】Spark基本概念和運行模式
nmf 磁盤 大數據平臺 並不是 鼠標 .cn 管理系統 大型數據集 spa ----本節內容------- 1.大數據基礎 1.1大數據平臺基本框架 1.2學習大數據的基礎 1.3學習Spark的Hadoop基礎 2.Hadoop生態基本介紹 2.1
【CS-4476-project 6】Deep Learning
paper mono difficult life slow 技術 current tun until AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction t
[JZOJ5899]【NOIP2018模擬10.6】資源運輸【矩陣樹定理】【圖論】
Description 給定一個n個點,m條邊的帶權無向圖。 定義這個圖的一個生成樹的權值為生成樹上邊權的乘積。 求所有生成樹權值的平均值,答案對998244353取模。 2<=n<=300,n-1<=m<=1000 Solution 平均值=和/總數
[JZOJ5898]【NOIP2018模擬10.6】距離統計
Description 給定一棵n個節點的帶邊權樹,m組詢問,每次詢問兩個數u,k,求出u本身外到u的第k小距離(相等距離會算多次) n,m<=50000 Solution 這絕對假NOIP。。 首先肯定是二分答案,將問題轉化為判定性問題,求有多少個距
jzoj5899 【NOIP2018模擬10.6】資源運輸 (矩陣樹定理)
描述 n<=300,給定有權邊,求生成樹大小和所有生成樹邊權乘積和。 要點 基爾霍夫矩陣: c [
【翻譯】影象基本操作
⚠️這個系列是自己瞎翻的,文法很醜,跳著跳著撿重要的部分翻,翻錯了不負責,就這樣。 ⚠️基於3.4.3,Basic Operations on Images,附原文。 目標 學會: 獲取畫素並且修改他們 獲取影象屬性 設定感興
jzoj 5899. 【NOIP2018模擬10.6】資源運輸 矩陣樹定理
Description Input Output Sample Input 3 2 1 3 5 2 1 6 Sample Output 30 樣例說明: 顯然m=n-1時,只有一種選擇方法,優秀程
jzoj 5898. 【NOIP2018模擬10.6】距離統計 動態樹分治
Description Input Output Sample Input 5 3 1 2 3 1 3 1 2 4 4 2 5 2 1 2 3 3 5 1 Sample Output 3 6 2 Data Constraint 分析: 我們可以先二分一個答
【python小甲魚6】集合
用{}括起來的,沒有對映關係的,就是集合。 集合的特點: 1.元素唯一。 num = {4,1,2,3,4,2,4,2} print(num) #執行結果為{1, 2, 3, 4} 2.無序。 eg:num[2]就會報錯。 建立集合: 1.直接把一堆數用{}
【Rscript】1.基本操作
setwd("/Users/alexandrashaw/Documents/R") getwd() x1 <- c(171,175,159,155,152,158,154,164,168,166,159,164) x2 <- c(57,64,41,3
【SQL】SQL基本操作
SQL基本操作 庫操作(DDL) 對資料庫的增刪改查 基本語法 1. 建立資料庫 Create database 資料庫名[庫選項]; 庫選項:用來約束資料庫,分為兩個選項 字符集設定:charset/character set 具體字符集.常用:GBK, UT
【Java基礎知識】JDBC基本操作
Jdbc簡介 JDBC(Java Data Base Connectivity )(java 資料庫連線) 可以為多種資料庫提供統一的資料庫訪問。 JDBC使用詳解 JDBC程式設計步驟 1. 載入驅動程式:Class.forName(driverClas
【深度學習】【caffe實用工具3】筆記25 Windows下caffe中將影象資料集合轉換為DB(LMDB/LEVELDB)檔案格式之convert_imageset
/********************************************************************************************************************************* 檔案說明:
【Cache】- Ehcache 基本操作
浪費了“黃金五年”的Java程式設計師,還有救嗎? >>>
【noip模擬賽6】收入計劃 最大值的最小值 二分答案
con card 兩個 space 最小值 一次 就會 pre iii 描述 高考結束後,同學們大都找到了一份臨時工作,渴望掙得一些零用錢。從今天起,Matrix67將連續工作N天(1<=N<=100 000)。每一天末他可以領取當天及前面若幹天裏沒有領
JS入門筆記+基本操作(剛接觸JS,很多筆記就是看到啥寫啥的,希望多多包涵)。
外部 friend mage fff pen scrip 表示 num 很好 1.註釋: html的註釋:<!--我是註釋--> CSS的註釋:/*我是註釋*/ JS的註釋://我是註釋 2.變量: 變量要先聲明再賦值,如下: var mychar; myc
Linux學習筆記-基本操作1
軟鏈接 數字 unix ctr binary bsp 類型 個數 ESS 1>. 命令解析器2>. Linux快捷鍵3>. Linux 系統目錄結構4>. 用戶目錄5>. 文件和目錄操作6>. 文件和目錄的屬性7>. 文件權限, 用