Original address: http://jefferson.iteye.com/blog/68604
In the section above on the use of JSR94 API, we use the implementation of the specific engine is a commercial product, if you want to understand the use of drools, here is an introductory reference article: http://blog.csdn.net/tigerflower/ Archive/2006/09/06/1185922.aspx. Since there are few articles on blaze, here is a brief introduction to its implementation based on experience.
Blaze is a product provided by Blazesoft company, because it is a commercial product, so specialized IDE is very powerful, now popular version is Blaze Advisor5.5 and Blaze advisor6.x. Blaze's development model has the benefit of programmatic development, as well as the benefits of declarative development. In the development of the IDE, you see the general traditional programming of the IDE, like the original code is the XML format of the file. Having seen drool's regular language, it has some fixed XML tags, has different meanings, you have to master, and in blaze programming, you are like writing Java code.
Before introducing the establishment and development of blaze, it is simple to introduce the grammar of the rule language. The rule language, the name SRL (full name of standard Rule Language), is claimed to be an English language, which is a language that allows business people to understand. Let's look at an example: Theaccount's balance is between $00.00 and $500.00. The representation in Java is theaccount.balance>=00 and theaccount.balance<=500, and, of course, in the SRL, it supports similar usages in Java as in the previous sentence. See another example, a declaration of a class:
A Vehicle is a object; In fact, its grammatical rules are simple, but also easy to learn, the cost of learning is very small. In the use we can find that it is an object-oriented language, provides atomic type, basic class library and built-in methods, and so on, compatible with Java, Java code embedded convenient.
Now let's look at the specific usage:
The declaration of a class, of course including attributes:
A Vehicle is an object with {
A speed:a real,
A size:a string,
A unit_price:a real}.
The use in Java is:
Class Vehicle
{
public double speed;
public String size;
public double unit_price;
}
Have fun, give me an example of declaring an object instance:
For example, just VEHICL class:
A vehicle1 is some Vehicle initially a vehicle1 initially{
Set 10.0,size to 20,unit_price to $100000.00}
or more concise:
MyCar is a Vehicle initially{
Speed=10.0,size= "2m", unit_price=$100000.00}
Very flexible, and you don't have to worry about the loose syntax that brings many errors, and the IDE can recognize the syntax errors.
Object array:
Accounts is a fixed array of 4 account
Initially {it[0] = Checkingaccount.}
An array of objects, named accounts, is declared here, the type of the array is account, and the size is 4, where the object reference to which the first item points is checkingaccount.
Again, let's look at another example:
Itinerary is an array of the city
Initially {it.append (city2),
It.append (City3),
It.append (City4).
}.
Using the built-in method of the array append,it represents the current object, which is equivalent to the This keyword in java.
Other examples of declaring arrays, array subscripts can be string types, or integer types, and so on, like the Java Class Library map and its subclasses, is powerful.
Airports is a association from
String to string initially
{it["New York"] = "JFK",
it["San Francisco"] = "SFO",
it["Los Angeles"] = "LAX".
}.
What does this passage mean? Explain the first half of the section.
Airports is the object name, which is the object array name, an association from is the keyword, the string after the from is the type of the array key, and the string after to is the array that the array is a string type.
To increase your perceptual knowledge, give another example:
Products are an association from
Integer to Product initially {
it[094] = someproduct. }
Declaration of object Properties:
A speed:a real,
A size:a string,
A unit_price:a Real
....
If the property is an array, then an address:some array of string.
Object initialization, the above introduction, everyone is probably clear, and look at the code snippet:
Initially {temp = 98.6, FirstName = "Bill"}
Initially {it.settemp (98.6),
FirstName = "Bill"}
Initially {Deposit (NewAccount, amount)}.
The second code snippet calls the method inside the class. The third code snippet calls the deposit method.
Enumeration, declared as: A[n] Enumerationname is one of {itemname,
itemname[, ItemName] ...}.
For example: A color is one of {red, Green, blue}.
It is necessary to talk about the role of enumeration.
A enumeration is defined above, named color, then a property is defined in application, which is color, as follows:
An application are an object with {
A customer: A string,
a color,
an Amount:an integer}
initially {amount = 0, color = red}.
Then, the attribute color of this Application object will have three standard values: red, green, blue, you can initialize the specified as red. Pretty much like a custom type with a value constraint.
Pattern declaration:
and See example:
Thecustomer is any Customer.
Theaccount is any account in Accountarray.
Seniormale is any person such this
(It.age > It.gender is male).
We know that a class can have more than one instance, and we can make an object whose value is limited to one or several object instances of an object or an array of objects, then you can define a patten. This is the typical conditional match, which is simplified into a type. In the
example above, thecustomer specifies that any one of the customer's objects, Theaccount, is specified as any of the account objects in the Accountarray array. The Seniormale is specified as a person object that is older than 65 and is female.
This pattern matches, like the regular expression we use, is infinitely powerful:
say an example:
Suppose there is a class account, in a ruleset, with N account objects: A1,a2,..., AN, Then you can declare a patten as follows:
Accountpattern is the any account.
the conditions in the rules match, you can use:
if accountpattern.balance > 0
Then accountpattern.positivebalance = True
Then it works equivalent to:
if a1.balance > 0
Then a1.positivebalance = True
If a2.balance > 0
Then a2.positivebalance = True
...
If an.balance > 0
Then an.positivebalance = True
Finally look at the declaration of the original type:
I am an integer.
StartDate is a date initially ' 1/31/99 '.
Today is a date.
Today = Calendar (). currentdate ().
Price was a money initially $1684.37.
Then look at the specific variable declared as enumeration, should be: sample is a color initially blue.
Color is the above, a color is one of {red, Green, blue}.
These are commonly used, like the event, RuleSet's definition from the document, in the GUI without SRL to define.
Now say, rule is also the rules match, the main use is the conditional matching sentence. And look at:
If Theform ' s name starts with "req" then ...
If Theform ' s name ends with "req" then ...
If Theapplicant ' s lastName is blank then ...
else ...
The above is if-then-else sentence, nothing special. Where the property of the Theform ' s Name,theform object name is of type string, the operation on string type can be seen from the sentence.
The Boolean operation in the IF statement has: not | or | and
Comparison operators are: is | = | <> | < | > | <= | >=
Operations on numbers are: + | - | * | / | div | MoD For example:
19/5 = 3.8
div 5 = 3
MoD 5 = 4
Other Process Control statements:
Case statement:
Select Countryoforigin of Product
Case China:apply Chinatariffrules
Case Japan:apply Japantariffrules
Case Thailand:apply Thailandtariffrules
Otherwise:print ("No tariffs apply.").
Iterate for statement:
For each customer such this (It.balance > 10000)
Do {print (it.name "qualifies for promotion.").
Apply Promotionruleset. }
For each Invoice in customer.invoices
such that it.balance
do {sum + = It.amount.}
WHILE_DO statement:
while (Portfoliovalue = unavailable)
do {portfoliovalue = Promptreal ("What
Is the value of your portfolio? ")}
Until do statement:
Until (productsremaining = 0)
Do {apply Checkpriceruleset (product).
Productsremaining-= 1. }
Exception capture and handling:
Try Statement_block
Catch A[n] Exceptionclassname with Statement_block
[Finally Statement_block]
For example:
try {customer.addaccount (Payment)}
Catch an accountexception with
{print ("account not created because" it).}
In fact, are similar to Java, not much difference.
(Blaze's introduction to the Rule engine continues ...) )
On the integration of Rule engine and Blaze rule Library three--blaze rule engine and Srl