Template questions

86 views
Skip to first unread message

Vishnu Venkatesh

unread,
Sep 6, 2011, 2:58:30 PM9/6/11
to open...@googlegroups.com
We see that RuleFamilyTemplate is defined as "Rules void RulesFamilyTemplate()" in the templates xls and then we can use "RuleFamily  pqr"

1) Can we similarly create our own template terminology? For example - "Rules void XYZTemplate()".....and then I create a table called "XYZ setOfRules"

2) In the RuleFamilyTemplate, there is a optional column [Condition],  and then when defining the RuleFamily, we can provide zero or more Condition columns.  Is this also true of any column that we define in a custom rule? If we have [C1], then can we have zero or more C1 columns?

3) How is the column title picked up in a template? I see $COLUMN_TITLE in the template, but that's not formally documented.

4) What other $ variables can be used?

Thanks!

support

unread,
Sep 6, 2011, 3:17:32 PM9/6/11
to OpenRules
Hi Vishnu,

1) Of course, you can create your own templates and then create Rules
tables based on them . See the detailed description of templates at
http://openrules.com/pdf/OpenRulesUserManual.pdf, page 49. Before we
implemented the Decision Model with Rule Families,custom rule
templates provided the main mechanism for custom rules development.
See also http://openrules.com/docs/man_templates.html for OpenRules-5.

2) Yes, "If we have [C1], then can we have zero or more C1 columns".
You just have to use explicitly a second row that defined "C1" and
other used conditions and actions. See the User Manual and
http://openrules.com/docs/man_templates.html#Partial Template
Implementation

3) Your are right. At this point, we continue to improve our default
Decision Model templates and do not want (yet!) our customers to
create their own template. We will be backward compatible, but we want
to reserve an opportunity to extend standard templates with additional
features. However, we cannot prevent you from creating your own
templates to replace the standard ones right now. At the same time, we
would be glad to add additional features upon your request.

4) As you can see from the provided RuleFamilyExecuteTempaltes.xls,
there are currently two internal variables $COLUMN_TITLE and
$TABLE_TITLE that can be used inside the templates.

Hope it is helpful.

OpenRules Support

On Sep 6, 2:58 pm, Vishnu Venkatesh <vishnu.venkat...@gmail.com>
wrote:

Vishnu Venkatesh

unread,
Sep 8, 2011, 10:29:58 AM9/8/11
to open...@googlegroups.com
Just to follow up on 1) because your answer and the manual is slightly different from what I need.

Can we introduce our own terminology for the header of a table?

For example, this works from the description of the template:

"Rules Numerator template baseNumerator"

What I really need is something like:

"Numerator xyz" where Numerator becomes the header, similar to how you have made Rules, RulesSequence etc as headers.  What do I need to do to introduce my own headers?

Thanks!

support

unread,
Sep 8, 2011, 10:58:44 AM9/8/11
to open...@googlegroups.com
Your certainly can create a template "baseNumerator" and then create an instance of rule with a signature "Rules Numerator template baseNumerator". However, we do not allow a user to introduce new keywords like "Rules", "RuleFamily", etc. Our internal mechanism uses those keywords to recognize different tables inside Excel files (see http://openrules.com/pdf/OpenRulesUserManual.pdf p.8). It could be a real mess if we allow users to freely add new keywords. Besides, we do not recommend you to use "Rules" tables and templates at all. Use the DecisionModel and RuleFamily tables instead. If you find some functionality missing let us know and we will add it ASAP.

Vishnu Venkatesh

unread,
Sep 8, 2011, 2:14:42 PM9/8/11
to open...@googlegroups.com
1 - It would be nice to be able to use our keywords.  Maybe you could take this is a requirement for future direction? :-)

Reason is that analysts might be thrown off by the "extends..." keyword, trying to keep their lives as simple as possible.


2 - Reason I gravitated towards Rules and not the DecisionModel is that our Rules need to have dynamic fact names of any name.  A glossary kind of construct did not appear to work here.  So I have a Rules table whose rows are the fact names required for that particular XLS. 

The actual rules table involving these fact names are constructed with these fact names as columns.  This behaves like the RuleFamily and Glossary except that the fact names are completely dynamic.

Don't know if that explained our situation better.

jacob

unread,
Sep 8, 2011, 2:27:24 PM9/8/11
to open...@googlegroups.com
Vick,

Please explain your "dynamic fact names" on a concrete example. You actually can redefine your glossary (or glossaries) dynamically, not just at the very beginning. Take one of our sample (say DecisionHello) and explain what you want to do with it "dynamically": add new fact types? change their types? associate a glossary with different business objects between decision runs? choose between different glossaries? If we understand what you need, we would be able to help.
Thanks,

OpenRules Support

Vishnu Venkatesh

unread,
Sep 8, 2011, 3:12:05 PM9/8/11
to open...@googlegroups.com
Ok, no problem, although I won't use the DecisionHello.


MyHashMapBasedObject extends HashMap {

  public void setVariable(varName)  {
          put(varName, varName); <--- this is simple where key = val, but it could get complex.

 }

public void setVarValue(varName, varValue) {
    if (hashmap contains varName) {
         set value in hashMap of varName to varValue;
    }

}

  public boolean compare(input, Oper, value) {
          valueFromDbCall = get(input);
          return oper.compare(input, value);

 }

 public void setRepository(String repository);

public String getRepository();



}

In Java.....new myObj.....myObj.getRepository() is null at this point.

Table 1:

Rules void setVariables(MyHashMapBasedObject myObj)
[C]       A1        
         myObj.setVariable(param)
         String param
         VARIABLE NAME
         var1
         var2
         var3

Then in Java...engine.run("setVariables", myobj);

Then in Java...via database call or some other way...myObj.setVarValue("var1", "blah");




Table 2 (template):

Rules void baseDecision
[Condition]                                                                                                 [Action]
myObj.compare($COLUMN_TITLE, op, value)                                        myObj.setRepository(value2)
Oper op             String value                                                                                String value2
Title for Condition                                                                                 Title for Action


Table 3 (implementation)

Rules DecisionImpl extends baseDecision
Condition                                                                      Action
       var1                                                                      [col name for action not needed]
Is                        blah                                                      Production
Is                        foo                                                        Development03


Then in Java...engine.run("DecisionImpl", myObj).

Then in Java ....myObj.getRepository()---> should be "Production"

Hope this helps.

support

unread,
Sep 9, 2011, 11:47:28 AM9/9/11
to open...@googlegroups.com
Vick,

We have created for you a sample project that demonstrates how to deal with Maps inside your business objects. Here is a Java main:
public class Main {

public static void main(String[] args) {
String fileName = "file:rules/DecisionWithMap.xls";
Decision decision = new Decision("SetMapVariables",fileName);
MyObject obj = new MyObject();
MyMap map = new MyMap();
map.put("var1", "value1");
map.put("var2", "value2");
map.put("var3", "");
obj.setMap(map);
System.out.println("BEFORE: " + map);
decision.put("object",obj);
decision.execute();
System.out.println("AFTER: " + map);
}
}

it uses:

public class MyMap extends HashMap<String,String> {

}

and 

public class MyObject {
MyMap map;

public MyMap getMap() {
return map;
}
public void setMap(MyMap map) {
this.map = map;
}
}

The decision is described as:

The glossary:

And finally sample rule families:

Here are the execution results:

BEFORE: {var3=, var1=value1, var2=value2}
*** Decision SetMapVariables ***
Decision has been initialized
Decision SetMapVariables: Set First Set of Variables
Decision SetMapVariables: Set Second Set of Variables
AFTER: {var5=newvalue5, var3=, var1=newvalue1, var2=value2}

To support this project we had to extend templates in Excel files DecisionTemlate.xls, RuleFamilyExecuteTemplates.xls, and RuleFamilyExecuteTemplates.xls. They are attached and you need to replace your current files in openrules.config. The entire working project is also attached as DecisionWithMap.zip.

Let us know if it works for you.

OpenRules Support


DecisionTemplates.xls
RuleFamily1ExecuteTemplates.xls
RuleFamilyExecuteTemplates.xls
DecisionWithMap.zip

Vishnu Venkatesh

unread,
Sep 9, 2011, 11:06:25 PM9/9/11
to open...@googlegroups.com
Hi guys - thanks, it will be a couple of days while I get diverted to other things temporarily.

Meanwhile - I am curious - is there a reason why you would steer actively away from Rules and into Decision?

support

unread,
Sep 10, 2011, 3:04:28 PM9/10/11
to open...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages