字段约束连接

  • 用于字段约束
  • 对象内部多个约束连接,采用“&&”(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—字段约束连接字段约束操作符相关推荐

  1. XML学习笔记01【xml_基础、xml_约束】

    Java后端 学习路线 笔记汇总表[黑马程序员] XML学习笔记01[xml_基础.xml_约束][day01] XML学习笔记02[xml_解析][day01] 目录 01 xml_基础 今日内容 ...

  2. Java快速入门学习笔记3 | Java语言中的表达式与操作符

    有人相爱,有人夜里开车看海,有人却连LeetCode第一题都解不出来!虽然之前系统地学习过java课程,但是到现在一年多没有碰过Java的代码,遇到LeetCode不知是喜是悲,思来想去,然后清空自己 ...

  3. oracle update单引号,Oracle学习笔记:update的字段中包括单引号

    平时update的时候直接更改字段内的值,例如: update table_temp set name = 'Hider' where id = 100; 但更新后的值中包括单引号,则不能按以上方式进 ...

  4. 学习笔记(十六)——MySQL(约束与关系)

    文章目录 一.表字段的增删改 1.添加字段 2.删除字段 3.修改 二.约束 1.默认约束 default 2.非空约束 not null 3.唯一约束 unique key 4.主键约束 prima ...

  5. re学习笔记(37)BUUCTF-re-[GUET-CTF2019]re Z3约束求解器

    推荐肉丝r0ysue课程(包含安卓逆向与js逆向): 新手一枚,如有错误(不足)请指正,谢谢!! 个人博客:点击进入 题目链接:[GUET-CTF2019]re 题目下载:点击下载 IDA64位载入 ...

  6. Drools 学习笔记(一)----stateless session(无状态会话) 的使用

    关于Drools: Drools是jboss的一款开源的业务规则引擎,具有速度快.效率高.易学习的特点. 本文内容参考自Drools 官方文档 7.9.0.Final版 https://docs.jb ...

  7. Drools学习笔记4-第一个例子

    安装环境有了,下面开始做第一个例子. 新建一个Drools工程,新建时就会生成一个hello world的例子.这个例子我看了一下,没多看.从网上找了一个更复杂的例子.例子的具体内容自己去看.下面主要 ...

  8. python学习笔记:第19天 类的约束、异常、MD5和logging

    目录 一.类的约束 二.异常处理: 三.MD5加密 四.日志(logging模块) 一.类的约束 真正写写项目的代码时都是多人协作的,所以有些地方需要约束程序的结构.也就是说,在分配任务之前就应该把功 ...

  9. 标定学习笔记(九)-- 利用空间正交约束的相机自标定和三维重建

    本文主要内容围绕西交大的舒远.谈正和丁礼如所提出的一种利用空间正交约束的相机自标定方法进行归纳概述,谨做学习用.文章提出了一种用 2 幅存在正交约束的场景图像进行三维重建的方法,该方法不需要事先标定相 ...

最新文章

  1. Key-Value数据库:Redis与Memcached之间如何选择?
  2. dell 服务器 加ssd硬盘,DELL服务器加SSD硬盘.doc
  3. mciSendString用法
  4. 25. K 个一组翻转链表
  5. [css] 简述你对BFC规范的理解
  6. AfxGetMainWnd( )函数
  7. 计算机专业对口升学模拟试题,2010对口升学模拟试题计算机专理论综合
  8. 关于c语言编写 单项链表 的创建、插入、修改、删除、显示、退出 的程序案例
  9. 【Flink】Flink 写入 Clickhouse 大对象直接进入老年代 导致OOM
  10. IT人不要一直做技术(转载)
  11. mysql基础之帮助信息
  12. 性能测试--jmeter结合charles,以及charles的基本使用【11】
  13. 通过TXT文件批量生成PDF417码
  14. sql2008r2服务器维护,Windows Server 2008 r2服务器上安装SQL Server 2008 r2的方法
  15. 深入浅出WPF(一)
  16. Mugeda(木疙瘩)H5案例课—H5酷炫特效制作-岑远科-专题视频课程
  17. mac苹果电脑使用耳机听不到声音
  18. SEO为什么一定要面面俱到?
  19. Foxmail中Exchange设置账户总是提示密码错误
  20. Win7旗舰版下安装SQL Server 2008总结

热门文章

  1. flutter 动画展开菜单_多级菜单栏展开隐藏动画
  2. css 两边到中间 渐变_css3渐变过渡机制
  3. php 怎么打印条形码,php – 如何在垂直标签中垂直打印zpl条形码
  4. python将一组数据转化为列表_python如何将一个全部为int的列表,转化为全部为str的列表...
  5. 书脊开胶了用什么胶粘_画册印制1万本,结果一本不能用,这些问题你注意了吗...
  6. windows下安装TensorFlow(清华镜像)
  7. 【杂谈】人脸图像书看完了感觉不过瘾?这些拓展人脸资料值得你关注一下
  8. 【NLP-ChatBot】搜索引擎的最终形态之问答系统(FAQ)详述
  9. 中国太阳能热水器市场营销模式探析与品牌格局调研报告2022版
  10. 全球及中国模块化塑料带行业供需调查及产销形势预测报告2021-2027年版