当前位置:网站首页>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
边栏推荐
- 上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
- 深入理解PyTorch中的nn.Embedding
- 子线程获取Request
- drools决策表的简单使用
- drools执行String规则或执行某个规则文件
- 自然语言处理系列(三)——LSTM
- B high and beautiful code snippet sharing image generation
- Yygh-10-wechat payment
- drools执行完某个规则后终止别的规则执行
- Leetcode209 subarray with the smallest length
猜你喜欢
Docker-compose配置Mysql,Redis,MongoDB
MySQL与PostgreSQL抓取慢sql的方法
甜心教主:王心凌
深入理解P-R曲线、ROC与AUC
SparkContext: Error initializing SparkContext解决方法
Sparkcontext: error initializing sparkcontext solution
MySQL indexes and transactions
深入理解PyTorch中的nn.Embedding
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
自然语言处理系列(一)——RNN基础
随机推荐
LeetCode—剑指 Offer 51. 数组中的逆序对
Deep understanding of NN in pytorch Embedding
Full link voltage measurement
Post request body content cannot be retrieved repeatedly
LeetCode—剑指 Offer 59 - I、59 - II
mysql索引和事务
Day12 control flow if switch while do While guessing numbers game
Input a three digit number and output its single digit, ten digit and hundred digit.
CDA data analysis -- common knowledge points induction of Excel data processing
WSL 2 will not be installed yet? It's enough to read this article
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
Mysql database foundation
基于Arduino和ESP8266的连接手机热点实验(成功)
Jenkins用户权限管理
自然语言处理系列(三)——LSTM
二分刷题记录(洛谷题单)区间的甄别
Differences between nodes and sharding in ES cluster
Take you ten days to easily finish the finale of go micro services (distributed transactions)
This article takes you to understand the operation of vim
Jenkins user rights management