drools

开源规则流引擎实践

两盒软妹~` 提交于 2019-12-10 01:25:39
1. 基于 rete 算法的规则引擎 在 AI 领域,产生式系统是一个很重要的理论,产生式推理分为正向推理和逆向推理产生式,其规则的一般形式是:IF 条件 THEN 操作。rete 算法是实现产生式系统中正向推理的高效模式匹配算法,通过形成一个 rete 网络进行模式匹配,利用基于规则的系统的时间冗余性和结构相似性特征 [8],提高系统模式匹配效率。本文将介绍的 Drools 引擎就是利用 rete 算法对规则进行分析,形成 rete 网络,对模式进行匹配。 1.1 rete 算法研究 1.1.1 rete 算法概述 Rete 算法最初是由卡内基梅隆大学的 Charles L.Forgy 博士在 1974 年发表的论文中所阐述的算法 , 该算法提供了专家系统的一个高效实现。自 Rete 算法提出以后 , 它就被用到一些大型的规则系统中 , 像 ILog、Jess、JBoss Rules 等都是基于 RETE 算法的规则引擎 [7] 。 Rete 在拉丁语中译为”net”,即网络。Rete 匹配算法是一种进行大量模式集合和大量对象集合间比较的高效方法,通过网络筛选的方法找出所有匹配各个模式的对象和规则。 其核心思想是将分离的匹配项根据内容动态构造匹配树,以达到显著降低计算量的效果。Rete 算法可以被分为两个部分:规则编译和规则执行 [7] 。当 Rete 算法进行事实的断言时

Drools: Why stateless sessions?

限于喜欢 提交于 2019-12-09 20:03:37
问题 Drools uses sessions to store runtime data. For this purpose there are two kinds of sessions: stateless and stateful. In contrast to stateless sessions, stateful sessions allow iterative invocation and seem to have all advantages over stateless sessions. So why are there even stateless sessions? What is the purpose they serve? And what are their advantage over stateful sessions? Thank you. 回答1: As for many other general stateless scenarios, a Drools stateless session could be helpful for

Drools - Using “from” in decision table

冷暖自知 提交于 2019-12-09 03:44:25
I'm having some trouble getting a rule that I know works in .drl form, to work in a decision table. Here is my rule in drl form: rule = "slider1" dialect "mvel" when $person: Person() ArrayList( size >= 2 ) from collect( TestResult( name in ("TestA","TestB"), result == "high" ) from $person.getLabResults() ) then $person.setString("It worked"); end Here is what I am trying in the spreadsheet: CONDITION ------------------- $person:Person() ------------------- ArrayList( size >= 1 ) from collect( TestResult( name in $param, result == 'high' ) from $person.getLabResults() ) -------------------

Disable JIT in Drools 6.2 with Java 8

最后都变了- 提交于 2019-12-08 16:41:34
We are working with Drools version 6.2.0.Final for parsing some of our rules. But sometimes when we have a lot of runs, Drools invokes the JIT compiler which is causing failures. We have this covered in our Junit tests and we are getting the following error java.lang.NoSuchMethodError: org.mvel2.compiler.BlankLiteral.<init>(Ljava/lang/String;)V at ConditionEvaluatoref4dc802b6174038b0307f5e6196e229.evaluate(Unknown Source) at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:248) at org.drools.core.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:204) at

Drools compare two objects in decision table

∥☆過路亽.° 提交于 2019-12-08 15:44:32
I have the following code in DRL file rule "MyExample" when $eentity : ExampleEntity() $sentity : SecondEntity( secondField == $eentity.getMainField()) then System.out.println(true); end This is works but I need to convert it to spreadsheet table. I tried so much variants but no one works. How can I write this rule in decision table? Use a single condition column: CONDITION ExampleEntity($mf: mainField) SecondEntity secondField == $mf /*param*/ Combine Ex with Sec on equal field values x The /*param*/ and the x is a hack to get the condition being generated for the row. 来源: https:/

Nested Rules In Drools

别来无恙 提交于 2019-12-08 13:03:44
问题 I have a .drl file which contains more than 100 rules. There are approximately 40 rules like rule "1", some 35 like rule "2" and rest are like rule "3". rule "1" when m: MyBeanClass( something1 == "train" && something2 == somevalue2) then m.setSomeThing(someOtherValue); update(m); end rule "2" when m: MyBeanClass( something1 == "bus" && something2 == somevalue2) then m.setSomeThing(someOtherValue); update(m); end rule "3" when m: MyBeanClass( something1 == "car" && something2 == somevalue2)

Drools 6 - Accessing the LHS of an ObjectInsertedEvent

本小妞迷上赌 提交于 2019-12-08 11:37:27
问题 I'm in the process of upgrading from Drools 5.5.0.Final to Drools 6.5.0.CR2, and I'm running into a problem with a custom event listener that listens for ObjectInsertedEvents and references the LHS of the rule that triggered the insertion. Depending on the types of the LHS bindings of the fired rule, the listener updates a property of the newly inserted fact. In Drools 5, we did this with a custom event listener that extended DebugWorkingMemoryEventListener and implemented

Exception handling at individual rule level - Drools

*爱你&永不变心* 提交于 2019-12-08 11:21:28
问题 How to catch and handle exceptions at individual rule level in Drools? Aim is that exceptions at a single rule should not impact the execution of the rest of the rules. I know that we can use try catch in RHS, but can we have a control at much higher level irrespective of what LHS or RHS is. Something like: fireAllRules( new DefaultAgendaEventListener() { @Override public void whenExceptionAtRule(Exception exception) { //handle exception when } }) 回答1: First, you need to implement the org.kie

Fetching fact from stateful session of drools

时光总嘲笑我的痴心妄想 提交于 2019-12-08 11:08:30
问题 I'm trying to get the new inserted fact from the rules: import com.neu.als.thesis.db.beans.FLTBean import com.neu.als.thesis.db.beans.StudentBean rule "Excellent" no-loop when $m: FLTBean ( listeningScore > 85 && listeningScore < 101 ) then StudentBean studentBean = new StudentBean(); studentBean.setKnowledgeLevel( "Excellent" ); insert( studentBean ); end To get something from the stateful session I should do this: protected Collection<Object> findFacts( final StatefulKnowledgeSession

Drools: how to retrieve the fact in response from Kie Execution Server?

送分小仙女□ 提交于 2019-12-08 10:20:34
问题 I am using Kie Execution Server 6.2 final and I have a simple rule file deployed on the server and I am accessing it through rest api. When I try to execute the rules, everything goes well, but I do not get newly inserted fact in the response. Here is my drl file rule "Odd Rule" dialect "mvel" when testRecord : TestRecord((integerValue & 1) == 1 && integerValue != 0 , testId: testRecordId , intValue :integerValue ) then System.out.println( "Odd Rule- Test ID "+ testId ); TestResult