Quick Start
Walkthrough #2 – create a fact and verbalize a rule
In this walkthrough we will add a Fact to the project created in the walkthrough #1. We’ll also verbalize the Rule to make it sound more natural.
1. Add a Fact
In the first walkthrough, we set the sale duration to 3 days. Now we will create a reusable Fact which states that weekend sale is a 3 day event.
Ø Click the Project tab. In the Project screen, create a new Facts file and a new Vocabulary file (this is similar to creating the References file and the Rules file in the walkthrough #1).
Ø Add the 2 new files to the Project and Reload it.
Ø Click the References tab. We will add a generic-type sale duration Atom. It will be used to make a Fact specific to weekend-type sale.
Ø In an empty “Alias” textbox type Sale Days. Make it “numeric” and check the “Atom” checkbox.
Ø Leave the xpath box blank because no XML tag is associated with this Atom.

Ø Save References by clicking the Save References button.
Ø Click the Facts tab and click the Refresh button to make the new Reference available to the Facts editor.
Ø In the “Fact Alias” textbox, type an identifier of the new Fact, for example: Weekend Sale Days
Ø Click the atom link, select the Sale Days Atom and click the Apply button
Ø In the Data Values section, type “3” into the Sale Days textbox:

Ø Click the Save Facts button
|
2. Add a Natural Term
Ø Switch over to the Vocabulary tab and click the Append button. Ø In a Natural Term textbox, type: sale is in effect:
Ø Click the atom/formula link. In the popup, click Sale Start Date and Ø In the Apply function to data dropdown select number of days since Ø Click the Apply button
Ø Click the “is” link and double click “is Less Than or Equal To” in the popup
Ø Click the atom/fact/formula/value link. Ø In the popup, click the Fact radio button:
|
|

Ø Select (click) the Weekend Sale Days Fact and click Apply
Ø An implementation of the new Fact should look like the following:

Ø Click the Apply & Go Back button to return to the Vocabulary Browser. It should be showing the new Term:

Ø Click the Save Changes button
3. Add a phrase to the Rule
Ø Click the Rules tab, select (click) the Offer Discount rule, and click the Edit Rule button
Ø Locate the condition created in the walkthrough #1:

We will replace it with a phrase.
Ø Click the AND button. When a new blank expression is added, click the phrase link:

Ø Click into the phrase textbox and double click the sale in effect term in the Vocabulary. A Natural Term is inserted into the phrase box:

Ø You can add some text outside the brackets, for example, enter “weekend” before the [sale is in effect]:
weekend [sale is in effect]
Ø We have no use for the original expression so let’s get rid of it. Click the topmost X button. The “phrase” should now be the only expression remaining in the Condition:

4. Create an action-type Natural Term
Wouldn’t it be nice to turn the Action expression into a phrase as well?
Ø To add an action-type Vocabulary Term, switch over to the Vocabulary tab.
Ø Click the Action radio button (note that Condition was the default choice at the time when we added our first Term)
Ø Click the Append button
Ø Type the following Natural Term (note that it includes a parameter):
offer (value)% discount
Ø Click the assign link:

Ø In the new expression click the atom link:
![]()
Ø Select the Discount atom and click Apply.
The new Term is done. The atom/formula/fact/value link remains as the placeholder for the “value” parameter that we will specify within a rule.
Ø Click the Apply & Go Back button. The new Term is added to the list:

Ø Click Save Changes and go back to the Rules tab.
Ø We need to refresh the Vocabulary lookup so that it displays the new Term. To refresh click the Hide Vocabulary button and then click the Show Vocabulary button. The updated Vocabulary displays both Terms:

Ø Under Rule Action – Then, click the assign link
Ø Click the phrase link
Ø Click into the new textbox and click the “offer (value)% discount” Term to copy it into the textbox. It will be rendered as:

Ø Replace the “NUMBER” with “10”:
[offer (10)% discount]
Ø We don’t need the original action expression any more so delete it by clicking the X button on the Then-line.
Ø The complete Rule should look like this:

Ø Click the Apply & Go Back button. The finished Rule is rendered in the Rules Browser:

Ø Click the Save Rules button.
5. Test the new Rule
Ø Switch over to the Test tab.
Ø Copy the following XML into the Input Test Data XML document textbox:
<sale>
<dateStart>1/1/2000</dateStart>
<discount></discount>
</sale>
Ø Click the Run Test button. If you are doing this walkthrough on Friday, Saturday or Sunday then the result will be similar to the first walkthrough (actual date will vary):

On any other day of the week the Rule will fail resulting into:
![]()
If you would like to see the Rule succeeding then modify the <dateStart> accordingly. Keep in mind that the rules engine retains its session through the State XML document displayed in the lower left corner. If you want to start over with a new date then do the following:
Ø Click the Reset button
Ø Change the date to yesterday’s date
Ø Click the Run Test button.
In this walkthrough, we used Atoms, Facts, and Natural Terms to build and verbalize a Rule. We also tested the Rule using pre-generated XML data document.
Next: go to Walkthrough #3 – enter a formula and add data filter
See also Complete project walkthrough
Managing RuleLab.Net projects.
Security of the online content