版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、劉俊豪(I AI Business Logicy Drools議程JBoss Drools介紹 Hello Drools Drools Rule Language Domain Specific Language Flow Drools GuvnorDrools簡(jiǎn)介 Drools是Redhat公司JBoss業(yè)務(wù)邏輯智能模塊。 /drools/ Drools是處理規(guī)則的專家系統(tǒng)??虯_K戶端業(yè)務(wù)規(guī)則引入規(guī)則引單只業(yè)務(wù) 邏紺組件的編寫(xiě)方式業(yè)務(wù) 邏輯 組件引入規(guī)則引軍之前 引入規(guī)則引竽之后Rule Engine的優(yōu)勢(shì)聲明式編程 Rule Engine允許你說(shuō)“做什么”,而不
2、是“怎 樣去做” Rule系統(tǒng)能解決非常困難的難題邏輯和數(shù)據(jù)分離 快捷和靈活Knowledge集中化工具集成良好的解釋機(jī)制易于理解的RuleIf (uJoeequal( people.getName()if( uMalen.equal( people.getSex()Java語(yǔ)言表示,如果 有一個(gè)人的名字是 uJoen ,而且是個(gè)男 性,就會(huì)輸出他的名 字跟性別。System.out.priltln(uThis is a man, name is Joe.”); rule ”GoodByewhe nPeople( name = ”Joe”,sex = ”Male”) thenSystem.ou
3、t.println(“This is a man, name is Joe.”);產(chǎn)生背景系統(tǒng)龐大,業(yè)務(wù)復(fù)雜;業(yè)務(wù)規(guī)則經(jīng)常改變; 24小時(shí)服務(wù);業(yè)務(wù)統(tǒng)一管理;降低系統(tǒng)維護(hù)升級(jí)成本。知識(shí)背景生產(chǎn)式規(guī)則引擎 Rete算法產(chǎn)生式規(guī)則引擎許多產(chǎn)品規(guī)則系統(tǒng)的大腦實(shí)際上就是一個(gè)推理引擎, 用于匹配fa ctsO rules當(dāng)匹配被找到,rule actions被fire Actio ns經(jīng)常會(huì)改變facts的狀態(tài),或者在應(yīng)用上執(zhí)行一些外部” actionInference Engine(ReteOO/ Leaps)roductlon MemoryPatternMatcher(rules)Working M
4、emory(facts)AgendaRETE網(wǎng)絡(luò)節(jié)點(diǎn)ObjedTypeNodeAlpha NodeLeftlnputAdapterNodeEvalNodeReteNodeJoinNodeNotNodeTerminalNode簡(jiǎn)單的RETE網(wǎng)絡(luò)CheeseWhenCheese(type=,cheddar)ThenSystem.out. printl nCcheddar);System out.println( *che consequenceRule議程JBoss Drools介紹Hello Drools Drools Rule Language Domain Specific Language
5、 Flow Drools Guvnor配置開(kāi)發(fā)環(huán)境到Jboss Drools官網(wǎng)的下載頻道下載一下 資料: Drools Binaries(Required) Drools Eclipse Workbench(Required) Documentatio n Java docs Source Code配置開(kāi)發(fā)環(huán)境 解壓Drools Binaries,到路徑Drools_Homeo 解壓Drools Eclipse Workbench,把 features 和 plugins 放到 Eclipse_Homedropins 文件夾下。 打開(kāi)Eclipse,到Window Preference Dr
6、ools Install Drools Runtimes,給Eclipse指定Drools的安裝路徑 Drools_HomeoNameLocation0 DroolsS.1.0.MlD:Dev ToolsJ2EE ToolsFrameworkD.O Drools Runt iseEither select an existing Drools Runtime on your file system or create a new one.Name: DroolsS. 1.0. MlFath: D:Dev ToolsJ2EE ToolsFramevorkDroolsDrool5. 1.0droo
7、ls5.電Create a new Drools 5 Runtime .新建Hello Drools項(xiàng)目打開(kāi)Eclipse新建項(xiàng)目窗口,F(xiàn)ile New Other.口。選擇Drools Drools Project,打開(kāi)新建Drools項(xiàng)目輸入項(xiàng)目名稱,點(diǎn)Next進(jìn)入下一頁(yè)面。 勾上第2項(xiàng),生成一個(gè)Hello World的例子。點(diǎn)Finish完成。二回刃New Drools ProjectCreate & new Drools Project叼 Add a sample Hellotforld rule file to this project.叼Add a sample Java clas
8、s for loading and executing the Hellotforld rules.I I Add a sample HelloWorld decision table file to this project.I Add & sample Java class for loading and executing the HelloflforId deci si on table I Add sample HelloWorld process file to this projectI Add a sample Java class for loading and execut
9、ing the Hellotforld process.恥xt |FinishCancelE tz MelloDrools3 (* src/main/java 曰 tH com.sample. eem ”+ |JJ DroolsTeB 0 src/maiiv/rules Q Sample, drl+ JKE Sys tLibr ary jdk t Drools Libr LT srcpublic clot roolsTest OR kseson Mase MvStacefuIKao“你火10列): KAOvledeFuM xMLoa9r logger Know 1lunc m Love r F
10、 act or y. a wFj Jpackage co.sampleRessage Besiege new He93age(); essagtaMtlMfaoe (*NeUo World*) ;| e”age.setStatus (Ressage MTILO); kjs9ion.insert(message): ks” ion. f xrAllRule4 (); logtr-elo ():I catch (Thcovable l) yHessa9e : message ) thenSystesu out .print 5( nyKessage ); Markers O PropertiesS
11、ervers 怪D血 Source Explorer 匕 Snippets 國(guó) Console =:(2010-9-8 上午 1(執(zhí)彳丁結(jié)果(虧 open explorert八Run As1 Run on ServerAlt+Shift+X, RDebug AsPv* C F; 1 Q hu2 Java AppliestionAlt+Shit+X? J DroolsTest Java Application C:Javajdkl. 6. 0_05binjavaw. exeHello WorldGoodbye cruel worldDebug規(guī)則文件Debug As凋 1 Debug on Se
12、rverAlt+Shift+D, RProfile As審 2 Drools ApplicationValidateiJj 3 Java ApplicationAlt+Shift+D, JT oomrule rrHello Worldno-loop truewhenro : Message( status = Message.HELLO, myMessage : message )thenSystemoutprinmyMessage );m setMessage ( Goodbye cruel vorldr,);m setStatus( Hessag電 GOODBYE ):update( m
13、);end議程 JBoss Drools介紹 Hello DroolsDrools Rule Language Domain Specific Language Flow Drools Guvnor規(guī)則文件種類 DRL- Drools Rules Language高級(jí)別的表達(dá)式語(yǔ)言(適合高級(jí)用戶) XML 一 Drools 2.x Format XML結(jié)構(gòu)化規(guī)則 DSL 一 Domain Specific Language領(lǐng)域語(yǔ)義規(guī)則模板支持自然語(yǔ)言 Decision Tables (決策表)對(duì)業(yè)務(wù)分析人員非常有用 Excel, Impress or CSV自定義Ul界面挑選關(guān)鍵元素適合最終用
14、戶操作DRLimport com.sample.Stock;rule HldentifyHotBuysHno-loop true salie nee 10 whe nRuleStockPicker.drlthenstock : Stock ( indexName = “DJIA”, currentPrice = 10.1, fundamentals = 62.5, attractiveness = 87.2)log(”BUY:”+stock); stock.setFlag(true); stock.setAction(BUY); modify( stock);endFactStock.java
15、public class Stockenum Action (BUY, HOLD, SELL;public String getlndexName(); public BigDecimal getCurrentPrice(): public void sctCurrentPrice(BigDecimal p);public publicvoid setFlag(boolean flag): void setActlon(Stock.Action action);術(shù)語(yǔ):RuleConditionConsequeneeFact2 6789101112import importglobal name
16、r*oi:g. dcools. /identicier-rrxrr type-com. saaple.Xrr / identif ierrryadarr typerrcojii. sample. Yadarr13141516171819202丄222324252627282930313233 Sysceni.out.princln(rrhelio worldrr); 丈/function System, out.println ( rrhellorr );DSL - Domain Spec訐ic Languagesrule Platinum Priority”#we dont want to
17、make the high rollers wait! whenThere is a PlatinurrT customer with a ticket status of “New”thenEscalate the ticketendrule ”Escalate”whe nThere is a customer ticket with status of Escalate thenSend escalation emailendDecision Tables 解析Excel XLS 和 CSV (Open Office)#creared on: 2010-2-21ckage org.teya
18、nd#list any import classes here.import java.util.Lisr;expander customLanguage.dsldeclare any global vaxiatles here global org.somepackage.EmailService emailService;function void sayHello()#function content (can have multiple functions) SysteiE.out .pxxntlnrr ;rule nYour First Rulenwhentconditionseva
19、l( true )thentacrlonseinailSexvice. sent (ncidirj.nxedhat. coir.”)end剖析DRL文件 Package不必匹配目錄結(jié)構(gòu) Expander Dsl文件列表 Imports Fact類型/領(lǐng)域?qū)ο蟮牧斜鞦acts被插Aworking memory (通過(guò)insert API) Globals被命名的“變量”值能在working memory中設(shè)置(通過(guò)setGlobal API)大多用于返回結(jié)果,或者作為引用數(shù)據(jù)在LHS中使用要注意(應(yīng)該為常量結(jié)果,且是幕等的) Functions即一段語(yǔ)義代碼(java)能夠在LHS中的eval或
20、者predicate謂詞表達(dá)式中使用,或者在RHS中。RulesGlobals是一個(gè)命名變量可傳遞常量或者工具(服務(wù))可作為結(jié)果返回,尤其是返回集合結(jié)果的途徑當(dāng)Global變量是數(shù)字、字符或字符串類型時(shí),在規(guī)則中是不能被改變的。不應(yīng)該當(dāng)做facts的替換使用粉RHS中的修改不會(huì)影響到LHS中的conditions如果在LHS中使用,必須在facts插入前設(shè)置In a rule paekage:global :2*2二七二.List 色二二二stwhenonl : Farfion ( 64 )thensen丄orsLlst. add (Spersorl .getName ();In the AP
21、I:Liat enioxsList = new AxrayList();werkirgMenory se*GlobaliaenicrsLis二9 aenicrsLLs t);函數(shù)(Functions)可在規(guī)則LHS或者RHS中添加各種邏輯對(duì)字段的控制或者轉(zhuǎn)換,小計(jì)算公式特別有用funefcion float weighted Ave rage (long niml, Long n*xn2 / lcrtg divl z lone div2 ) return (nuinl 寧 num2) / (cilvl 今 div2);rul ealeiilata weighted 倉(cāng) whenobl : Ob
22、serxration (Svall : valr Sperl : per) QbfiGxfaion(this J = cblr $val2 :$pGz2 : per)feva.1 ( weightedAvrage ($vaLl, $vaL2, $pexlr $per2) 1) then aendQuotes on Rule names are optional if the rule name has no spaces.ru_e salie neeagendaproup no-loop auto-focus duration ruleflow-group .JRHS can be any v
23、alid Java or MV EL expression33剖析Rulewhen then= 1000)e nCustomer Discount,T when:Order ( value 30)thencrder.se-CrderDisccunt(6.0);end其他的條件元素(Conditional Elements) Exists Not Accumulate Collect蠶 From ForallConsequence / RHS即一段代碼 Java MVEL典型 actions:插入新的fact修改已經(jīng)存在的fact撤銷(xiāo)fact為fact的字段賦值為global賦值進(jìn)行GC警告:使
24、用java的時(shí)候。不要使用if/else, for/wh訂e loops或者其 他類似的jova邏輯Consequence / RHS特有關(guān)鍵字 update ( fact ) insert( new fact () retract ( fact ) 訪問(wèn)KnowledgeHelperdrools XXX getRule比如:System, out. print In (dfools. getRule (). getName (); 將打印出正在執(zhí)行rule的名稱 halt停止rule的firings,把控制權(quán)交給應(yīng)用 setFocus針對(duì)agenda groups執(zhí)行時(shí)控制SalienceA
25、genda GroupsActivation Groups No Loop RuleFlowRule屬性議程 JBoss Drools介紹 Hello Drools Drools Rule LanguageDomain Specific Language Flow Drools GuvnorDomain Spec訐ic Language領(lǐng)域特定語(yǔ)言自然語(yǔ)言與規(guī)則代碼翻譯器。適合非技術(shù)人員使用(業(yè)務(wù)分析員)。規(guī)則更加容易理解只要告訴規(guī)則做什么就妊,不許關(guān)注怎么做。議程 JBoss Drools介紹 Hello Drools Drools Rule Language Domain Specific
26、 LanguageFlow Drools Guv norRuleflow Drools已經(jīng)提供了定義執(zhí)行順序的功能,比如salience, activation groups等等當(dāng)處理大量ule集的時(shí)候,管理規(guī)則的執(zhí)行順序可能會(huì)變得復(fù) 雜 Ruleflow允許使用圖形化的流程圖來(lái)指定rule集的順序允許你指rule集順序或者并行執(zhí)#要使用ruleflow,你需要:使用ule屬性來(lái)給每個(gè)rule指定一個(gè)所屬的ruleflow group 定義一個(gè)ruleflow圖來(lái)描述這些ruleflow groups在執(zhí)行中的 順序構(gòu)建一個(gè)ruleflow 使用 New - Other - Drools -
27、Flow File,將創(chuàng)建一個(gè)新的.rf 文件O Hev三 E DroolsDeci si on TableDomain Specific Language Drools ProjectFlow FileGuided RuleCancelRule ResourcefinishDrools透視圖打開(kāi) u Drools透視圖” ,u properties M 面板在eclispe窗口 底部l 2 l二nl rIWtlvI* u|議程 JBoss Drools介紹 Hello Drools Drools Rule Language Domain Specific Language FlowDrool
28、s Guvnor業(yè)務(wù)規(guī)則編輯器基于web,基于電子表格,開(kāi)發(fā)工具QA工具什么是Guvnor測(cè)試腳本,分析工具,Rule執(zhí)行知識(shí)倉(cāng)儲(chǔ)版本控制和回滾搜索&索引不同用戶和權(quán)限部署管理快照和package部署運(yùn)行時(shí)引擎可以使用倉(cāng)儲(chǔ)中 的知識(shí)做出推論DAMS RuntmeWebDAVSearcfiEditorBAMS2傀uonejjsiuiuipV 囲)ueujAo|d9Q &sa6e)|oed 田03PUfdlS0Jo6e)E3 耳 soieisF W八 sejnyF t二二二二芍 M?NesMox o)seuo6a)eo esn aA|9AJieuj0(v ouieu e |o yed jo eme
29、u ay) jg)u3 :isi| ui siudii paAiqoje epnpui :6um3)euj aiueu e m)im stud)i puij bOno uOis AINO 3SA (90930)300W U3Sfl 3IGNIS :9UJOO|a/vWHENPersonBoardThere is no* Any type | equal toTHEN(options)name is equal tomynameScenarios for package: Sensis Run all scenariosOveral result: FAILUREScenarios1 failu
30、res out of 23 expectations. 90% of the rules were tested.0 failures out of 3 Open 0 failures out of 4 Open 0 failures out of 5 Open 0 failures out of 5 Open 0 failures out of 1 Open (0 failures out of 1 Open 0 failures out of 2 OpenAdv scoring sanity test: Sydney advertiser ratings: Basic assignment
31、 validation: Overlapping assignments: Allow email overiap assignments: Consultant self assign authority: QLD self assign: No available consultants:定乂白己的測(cè)試Change state Status: CSave changes Copy ArchiveResultsAdv scoring sanity testRun scenario囲adv field (valueScore) was 42.ummary.鳥(niǎo)“field (valueReaso
32、n was Loyal expected (Other.# GIVENCategories:令非EXPECTinsert Advertiser advadvertiserType: Agency :】2 rules fired in Oms. Show rules firedUse real date and timeAdvertiser adv has valuesModifiedon:Mar 28, 2008 4:47:25by: alanjxarsons Note:Version: 7Created Mar 2& 2008 12:08:2 on: PMyalasrsons Format:
33、 scenarioPackage: Senses 夕SubjectType:External knk:Source:Version htstory 金掃 valueScore: valueReason:More.(configuration) | All rules may fire: 1Aglobals)邏輯分析maxgagmM AnalyK for.可RlW 傳Analysing package: mortgagesRun analysisl=)壘 Warnings (20 Ins、3) RUe RcoexORute* 2 nc RhS.6xkS0cMU nas nc RHS3J Ri Dumppy ru# no RH5,3) RUe best bw OK but h 9 naiiy ? OKd) RU baM ca/arx Jeb. bid t s nisns Job3 Ri 9 0jk = 0 but t bd) RUe Me r 20, hH k e zeng 20
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣州鐵路職業(yè)技術(shù)學(xué)院《采礦工程》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025年浙江省安全員B證(項(xiàng)目經(jīng)理)考試題庫(kù)
- 2025黑龍江省安全員考試題庫(kù)附答案
- 2025年-河北省安全員《B證》考試題庫(kù)
- 《電影天堂》課件
- 植物的逆境生理-課件
- 上海市初中勞技試題解析2014
- 【大學(xué)課件】國(guó)際投資的企業(yè)形式
- 《植物病原病毒》課件
- 《探析權(quán)健腫瘤醫(yī)院》課件
- 漢語(yǔ)中的詞語(yǔ)詞性分類(課堂)課件
- 骨盆骨折PPT完整版
- 2023-2024學(xué)年廣西壯族自治區(qū)南寧市小學(xué)語(yǔ)文五年級(jí)期末高分試題附參考答案和詳細(xì)解析
- 事業(yè)單位登記管理講座課件
- DB44T 1315-2014物業(yè)服務(wù) 檔案管理規(guī)范
- 基本醫(yī)療保險(xiǎn)異地就醫(yī)登記備案申請(qǐng)表
- 非線性光纖光學(xué)六偏振效應(yīng)PPT
- 雪夜的老人閱讀答案6篇
- 2022數(shù)學(xué)課程標(biāo)準(zhǔn)解讀及實(shí)踐:八下平行四邊形大單元設(shè)計(jì)
- 昌樂(lè)二中271課堂教學(xué)模式
- 深基坑變形監(jiān)測(cè)方案
評(píng)論
0/150
提交評(píng)論