In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "use of drools rule language", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "the use of drools rule language" bar!
Brief introduction:
DRL (Drools Rule Language) is the abbreviation of drools rule language. When using the drools rule engine, we often put the written rules in the .drl file, and then the rule engine loads the rules, so what is the basic composition of a drl file? Continue to look down:
The composition of the drools rule file package / / package name import / / the imported classes function / / optional, the defined function query / / optional, the defined query declare / / optional, the declared global / / optional, the defined global variable rule "rule name 1" / / attribute when / / conditional then / / the action endrule "rule2 name" performed after the condition is met.
The following example DRL rule (note that this example is just a rule, not the contents of the entire rules file, so that it does not write package,import) defines the age limit in a loan decision service:
Rule "Underage" salience 15 agenda-group "applicationGroup" when $application: LoanApplication () Applicant (age < 21) then $application.setApproved (false); $application.setExplanation ("Underage"); end
The following figure shows the general order of several elements in a rule file: package in package: drools is the same as package syntax in java, a DRL file can only have one package and must be on the first line, other elements can contain one or more, but the rule name must be unique. For example:
Package com.cn.somepackage
The ";" after package is optional, and any rule property can be defined at the package level, which becomes the default property of the rule, and overrides the default property of the rule if you reset the property on the rule. Import:
Similar to the import statement in java, it is used to import classes or objects to be used in the format of packageName.objectName. Multiple import statements are separated by multiple lines, and the Drools engine automatically imports classes under the same package and classes under * java.lang.*. For example:
Import org.mortgages.LoanApplication
Function:
The structure of function is as follows:
The definition of function is placed in the drl rule file instead of the java class, and function can be called in later rules. In addition, a static method can be defined in the outer java class and then imported into the drl file; for example:
Define directly in the drl file
Function String hello (String applicantName) {return "Hello" + applicantName + "!";} rule "Using a function" when / / Empty then System.out.println (hello ("James")); end
Import external static methods
Import function my.package.applicant.hello;rule "Using a function" when / / Empty then System.out.println (hello ("James"); end
Query: the query statement is used in the drl file to query the relevant facts from the working memory of the drools engine. Define the query statement in the drl file and call it in the java code to get the result of the query. Return a QueryResults * via: * ksession.getQueryResults ("name"), where name is the name of the query, and this name is to be unique throughout the kbase. For example:
Define query in the drl file
Query "people under the age of 21" $person: Person (age < 21) end````-call ````QueryResults results = ksession.getQueryResults ("people under the age of 21") in java code; System.out.println ("we have" + results.size () + "people under the age of 21") Thank you for your reading. the above is the content of "how to use drools rules language". After the study of this article, I believe you have a deeper understanding of the use of drools rules language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.