当前位置:网站首页>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
边栏推荐
猜你喜欢
Larvel modify table fields
MySQL and PostgreSQL methods to grab slow SQL
Jenkins voucher management
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
[C language] convert decimal numbers to binary numbers
MSI announced that its motherboard products will cancel all paper accessories
深入理解P-R曲线、ROC与AUC
jenkins 凭证管理
HR wonderful dividing line
【工控老马】西门子PLC Siemens PLC TCP协议详解
随机推荐
基于Arduino和ESP8266的连接手机热点实验(成功)
字符串回文hash 模板题 O(1)判字符串是否回文
还不会安装WSL 2?看这一篇文章就够了
Sub thread get request
自然语言处理系列(一)——RNN基础
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
SCM power supply
drools决策表的简单使用
Lombok common annotations
刷题---二叉树--2
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
Post request body content cannot be retrieved repeatedly
Docker-compose配置Mysql,Redis,MongoDB
Map和Set
史上最易懂的f-string教程,收藏这一篇就够了
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Pytorch builds LSTM to realize clothing classification (fashionmnist)
On data preprocessing in sklearn
Leetcode14 longest public prefix
Day12 control flow if switch while do While guessing numbers game