当前位置:网站首页>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
边栏推荐
- ORB-SLAM2不同线程间的数据共享与传递
- Heap (priority queue)
- Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
- PyTorch nn. Full analysis of RNN parameters
- 记录一下MySql update会锁定哪些范围的数据
- Go learning notes - go based interprocess communication
- JZ63 股票的最大利润
- Time format display
- YYGH-BUG-05
- 计算二叉树的最大路径和
猜你喜欢
随机推荐
Leetcode209 subarray with the smallest length
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
Repeat, tile and repeat in pytorch_ The difference between interleave
堆(优先级队列)
Post request body content cannot be retrieved repeatedly
Gaode map test case
ThreadLocal的简单理解
(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?
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
Leetcode739 daily temperature
PyTorch nn.RNN 参数全解析
Applet link generation
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
LeetCode—剑指 Offer 51. 数组中的逆序对
Leetcode14 longest public prefix
Map和Set
Natural language processing series (III) -- LSTM
字符串回文hash 模板题 O(1)判字符串是否回文
Leetcode922 sort array by parity II







