日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Drools学习笔记3—Conditions / LHS—字段约束连接字段约束操作符

發布時間:2025/3/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Drools学习笔记3—Conditions / LHS—字段约束连接字段约束操作符 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

字段約束連接

  • 用于字段約束
  • 對象內部多個約束連接,采用“&&”(and)、“||”(or)和“,”(and)
  • 執行順序:“&&”(and)、“||”(or)和“,”

字段約束操作符

  • >、>=、<、<=、= =、!=
  • contains:包含 A contains B, A中包含B
  • not contains:與contains相反
  • memberOf:單個對象屬于某個集合,this表示當前對象
  • not memberOf:與memberof相反
  • matches:正則表達式,匹配
  • not matches:正則表達式,不匹配

contains 、 not contains

package com.sampleimport com.bean.Customer; import com.bean.Account;rule "contains"when$account : Account();$customer : Customer(name=="七夜雪" && accounts contains $account);thenSystem.out.println( "contains test success" ); endrule "not contains"when$account : Account();$customer : Customer(name=="七夜雪" && accounts not contains $account);thenSystem.out.println( "not contains test success" ); end /*** 字段約束符,contains* @throws Exception*/@Testpublic void testContainsRule() throws Exception {KnowledgeBase kbase = readKnowledgeBase("Contains.drl");StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");Customer customer = new Customer();customer.setName("七夜雪");Account account1 = new Account();account1.setNum(100);Account account2 = new Account();account2.setNum(100);customer.getAccounts().add(account1); //not contains//customer.getAccounts().add(account2); // contains ksession.insert(customer);ksession.insert(account2);ksession.fireAllRules();logger.close();}

?

memberOf 、not?memberOf?

package com.sampleimport com.bean.Customer; import com.bean.Account;rule "Memberof"when$customer : Customer();//當前的account是$customer.getAccounts()的一個成員$account : Account(this memberOf $customer.getAccounts()); thenSystem.out.println( "memberOf test success and account is " + $account.getName() ); endrule "not Memberof"when$customer : Customer();//當前的account不是$customer.getAccounts()的一個成員$account : Account(this not memberOf $customer.getAccounts()); thenSystem.out.println( "not memberOf test success and account is " + $account.getName() ); end /*** 字段約束符,memberOf* @throws Exception*/@Testpublic void testMemberOfRule() throws Exception {KnowledgeBase kbase = readKnowledgeBase("Members.drl");StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");Customer customer = new Customer();Account account1 = new Account();account1.setName("碧落");Account account2 = new Account();account2.setName("黃泉");customer.getAccounts().add(account1); ksession.insert(customer);ksession.insert(account1);ksession.insert(account2);ksession.fireAllRules();logger.close();}

matches 、 not?matches

package com.sampleimport com.bean.Customer; import com.bean.Account;rule "Matchs"when$customer : Customer(name matches "qiye*");thenSystem.out.println( "Matchs test success and customer is " + $customer.getName() ); endrule "not Matchs"when$customer : Customer(name not matches "qiye*");thenSystem.out.println( "not Matchs test success and customer is " + $customer.getName() ); end /*** 字段約束符,memberOf* @throws Exception*/@Testpublic void testMatcherRule() throws Exception {KnowledgeBase kbase = readKnowledgeBase("Matchs.drl");StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();Customer customer = new Customer();customer.setName("qiyexue");Customer customer1 = new Customer();customer1.setName("biluo");ksession.insert(customer);ksession.insert(customer1);ksession.fireAllRules();}

?

fact對象代碼:http://www.cnblogs.com/qiyexue/p/7822670.html

?

轉載于:https://www.cnblogs.com/qiyexue/p/7822850.html

總結

以上是生活随笔為你收集整理的Drools学习笔记3—Conditions / LHS—字段约束连接字段约束操作符的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。