drools 规则语法_Drools:规则编写或语法基础
drools 规则语法
Drools:规则编写或语法基础 (Drools: Rule writing or Syntax basics)
If you see the default rule which is written in the FirstDroolsProgram project(Sample.drl), there are a lot of keywords
used. Let us explain them one by one now :
如果您看到在FirstDroolsProgram项目(Sample.drl)中编写的默认规则,则使用了很多keywords
。 现在让我们一一解释:
-
Package: Every Rule starts with a package name. The package acts as a namespace for Rules. Package name has to be defined while creating the Rule resource. Rule names within a package must be unique. Packages in Rules are similar to packages in 包:每个规则均以包名称开头。 该包充当规则的名称空间。 创建规则资源时必须定义包名称。 包中的规则名称必须唯一。 Rules中的软件包与
Java
. When you create a new Rule byJava
软件包相似。 当通过 New -> Rule Resource -> then in the below window you need to mention the Rule name as well as package name.New-> Rule Resource->创建新Rule时,在下面的窗口中,您需要提及Rule名称以及包名称。 -
Import statement: Import statements are also similar to 导入语句:导入语句也类似于
Java
. All the FACTS classes and any helper classes needs to be imported for the rules to work on. For ex:Java
。 需要导入所有FACTS类和任何帮助器类,然后才能使用这些规则。 例如:com.sample.DroolsTest.Message;
in the above example.com.sample.DroolsTest.Message;
在上面的示例中。 -
Rule Definition: The Rule definition consists of some drools specific 规则定义:规则定义由一些特定于口水的
keywords
. Post you have added the plugins you can see the drools specific keywords in red color. In the above example,keywords
。 添加插件后,您会看到红色的drools特定关键字。 在上面的示例中, rule-when-then-end are the different keywords.rule-when-then-end是不同的关键字。 -
Global variables: With global you define 全局变量:使用全局可以定义global variables. They are used to make application objects available to the rules. Typically, they are used to provide data or services that the rules use, especially application services used in rule consequences, and to return data from the rules, like 全局变量 。 它们用于使应用程序对象可用于规则。 通常,它们用于提供规则使用的数据或服务,尤其是用于规则结果的应用程序服务,并从规则返回数据,例如在规则结果中添加的
logs
orlogs
或values
added in rule consequences, or for the rules to interact with the application.values
,或用于规则与应用程序进行交互。
rule keyword must be followed by a logical rule name.
rule关键字必须后跟逻辑规则名称。
when keyword must be followed by some condition.
when关键字必须跟随一些条件。
then keyword must have the consequence part if the when condition is met.
There are lot of other keywords which will be covered in further sections.如果满足when条件, 那么关键字必须具有结果部分。
还有许多其他关键字将在后续章节中介绍。Now let us walk you through the terms used in the Java file used to load the drools and execute the rules.
现在,让我们逐步介绍一下Java文件中用于加载流口水和执行规则的术语。
drools 规则语法