当前位置:网站首页>Drools executes string rules or executes a rule file
Drools executes string rules or executes a rule file
2022-07-02 12:14:00 【huan_ one thousand nine hundred and ninety-three】
1、 background
Here we mainly record 2 A small knowledge point , Prevent forgetting later .
1、 How to be in drools Execute a drl file .
2、 If our rule is a String String of type , So how to implement .
2、 Realization
2.1 Execute specified drl file
KieHelper kieHelper = new KieHelper();
// Get the specified drl file
Resource resource = ResourceFactory.newClassPathResource("rules/alway-rule.drl", "UTF-8");
kieHelper.addResource(resource,ResourceType.DRL);
KieBase kieBase = kieHelper.build();
KieSession kieSession = kieBase.newKieSession();
kieSession.fireAllRules();
kieSession.dispose();
2.2 perform String The rules
String drl = "package rules\n" +
"\n" +
"rule \"rule-01\"\n" +
" when\n" +
" $i: Integer()\n" +
" then \n" +
" System.out.println(\" The rules :[\"+drools.getRule().getName()+\"] perform , The value existing in the rule memory is :\"+$i);\n" +
"end";
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(drl, ResourceType.DRL);
// establish KieBase It's a costly one
KieBase kieBase = kieHelper.build(EqualityBehaviorOption.IDENTITY);
System.out.println(kieBase);
// establish KieSession The cost is small
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(123);
kieSession.fireAllRules();
kieBase.removeRule("rules", "rule-01");
kieSession.insert(456);
kieSession.fireAllRules();
kieSession.dispose();
It should be noted that KieBase The creation cost of is very large , Therefore, if you really want to use the necessary cache in this way .
3、 Complete code
边栏推荐
- Addition, deletion, modification and query of MySQL table (Advanced)
- SVO2系列之深度濾波DepthFilter
- 使用Sqoop把ADS层数据导出到MySQL
- 自然语言处理系列(三)——LSTM
- 堆(优先级队列)
- drools执行String规则或执行某个规则文件
- Codeforces 771 div2 B (no one FST, refers to himself)
- Go learning notes - multithreading
- Natural language processing series (II) -- building character level language model using RNN
- 求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
猜你喜欢
![[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)](/img/18/f0c9ef6250a717f8e66c95da4de08c.jpg)
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)

自然语言处理系列(一)——RNN基础

SVO2系列之深度滤波DepthFilter

Jenkins voucher management

自然语言处理系列(二)——使用RNN搭建字符级语言模型

Initial JDBC programming

Tas (file d'attente prioritaire)

寻找二叉树中任意两个数的公共祖先

MySQL indexes and transactions

自然语言处理系列(三)——LSTM
随机推荐
堆(優先級隊列)
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
HR wonderful dividing line
史上最易懂的f-string教程,收藏这一篇就够了
深入理解P-R曲线、ROC与AUC
String palindrome hash template question o (1) judge whether the string is palindrome
Differences between nodes and sharding in ES cluster
计算二叉树的最大路径和
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
MySQL与PostgreSQL抓取慢sql的方法
FastDateFormat为什么线程安全
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
Leetcode14 longest public prefix
LeetCode—剑指 Offer 59 - I、59 - II
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
[untitled] how to mount a hard disk in armbian
(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
drools动态增加、修改、删除规则
Yygh-10-wechat payment
(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?