Drools规则插入新事实,并解雇其他规则动态



我是Drools和Kie-Server的新手。我对如何通过射击规则RHS(然后操作(在工作记忆中插入新事实的问题有问题,然后通过这些动态传递的事实激活其他规则。

我期望的是,当底部基础从外部插入工作记忆并激活Ruleone,在Ruleone内部"然后"它将插入新事实的luleresult,并期望激活Ruletwo,但是它不会激活Ruletwo,只是Ruleone,被激活了,我做错了吗?

在这里,我有两个规则和一组事实:

事实定义:

public class AppResult implements java.io.Serializable
{
   static final long serialVersionUID = 1L;
   private java.lang.String key;
   private java.lang.String value;
   //getters and setters ...
}

public class BaseFeature implements java.io.Serializable
{
   static final long serialVersionUID = 1L;
   private int age;
   //getters and setters ...
}
public class RuleResult implements java.io.Serializable
{
   static final long serialVersionUID = 1L;
   private java.lang.String ruleName;
   private java.lang.Long score;
   private boolean state;
   //getters and setters ...
}

规则定义:

rule "RuleOne"
    dialect "mvel"
    salience 100
    no-loop true
    lock-on-active true
    when
        $b : BaseFeature( age < 22 || age > 40 )
    then
        RuleResult $r = new RuleResult();
        $r.setRuleName( "RuleOne" );
        $r.setState( false );
        insertLogical( $r );
end
rule "RuleTwo"
    dialect "mvel"
    no-loop false
    lock-on-active true
    salience 10
    when
        $r : RuleResult( ruleName == "RuleOne" , state == false )
        $a : AppResult( )
    then
        $a.setKey( "PASS" );
        $a.setValue( "false" );
end

如何实现射击规则插入新事实并解雇其他规则动态?预先感谢!

我正在使用Kie-Server(6.5 final(进行测试,以及以下的帖子和响应:

发布:

{
    "lookup": "RuleChainTestStateless",
    "commands": [
    {
        "insert": {
            "return-object": false,
            "object": {
                "com.qf.rulechaintest.BaseFeature": {
                    "age": "10"
                }
            }
        }
    },
    {
        "insert": {
            "return-object": true,
            "out-identifier": "AppResult",
            "object": {
                "com.qf.rulechaintest.AppResult": {
                }
            }
        }
    },
    {
        "fire-all-rules": ""
    },
    {
            "get-objects":{
                "out-identifier":"allFactsInWrokingMemory"
            }
    }
    ]
}

回复:

{
  "type": "SUCCESS",
  "msg": "Container RuleChainTest1.1 successfully called.",
  "result": {
    "execution-results": {
      "results": [
        {
          "key": "",
          "value": 1
        },
        {
          "key": "AppResult",
          "value": {
            "com.qf.rulechaintest.AppResult": {
              "key": null,
              "value": null
            }
          }
        },
        {
          "key": "allFactsInWrokingMemory",
          "value": [
            {
              "com.qf.rulechaintest.BaseFeature": {
                "age": 10
              }
            },
            {
              "com.qf.rulechaintest.AppResult": {
                "key": null,
                "value": null
              }
            },
            {
              "com.qf.rulechaintest.RuleResult": {
                "ruleName": "RuleOne",
                "score": null,
                "state": false
              }
            }
          ]
        }
      ],
      "facts": [
        {
          "key": "AppResult",
          "value": {
            "org.drools.core.common.DefaultFactHandle": {
              "external-form": "0:2:1542374590:1542374590:2:DEFAULT:NON_TRAIT:com.qf.rulechaintest.AppResult"
            }
          }
        }
      ]
    }
  }
}

请注意,响应:

"com.qf.rulechaintest.AppResult": {
              "key": null,
              "value": null
            }

它的期望是:

"com.qf.rulechaintest.AppResult": {
                  "key": "PASS",
                  "value": "false"
                }

如果您不知道这些规则属性的目的,则应阅读文档。然后,我认为,您会意识到您可以删除它们。

salience 100 or 10
no-loop true or false
lock-on-active true

我同意Laune的同意,您应该阅读规则属性的含义(请参见文档[1]中的ERE(。我认为这是因为您对规则有锁定。请查看我链接的文档。

[1] https://docs.jboss.org/drools/release/6.5.0.final/drools-docs/html/ch08.html#d0e9196

尝试使用更新功能"

然后

    RuleResult $r = new RuleResult();
    $r.setRuleName( "RuleOne" );
    $r.setState( false );
    update ( $r );

"

相关内容

  • 没有找到相关文章

最新更新