RE: [rules-users] DSL/DRL Problem
by Hehl, Thomas
Sorry, where should we look in the manual for this?
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Tuesday, May 27, 2008 11:14 AM
To: Rules Users List
Subject: Re: [rules-users] DSL/DRL Problem
Do you mean like:
There is a client
- which is adult
- whose wife is adult
Mapped to:
Client( age > 17, spouse.age > 17 )
Take a look at the manual and check for the "-" special character.
[]s
Edson
2008/5/27 <ringsah(a)comcast.net <mailto:ringsah@comcast.net> >:
Hi All,
I am new to Drools - my company is evaluating it for use in a project. We
are doing a proof of concept, and we are developing a DSL. One of our DSL
expressions is
"client is an adult"
which is defined as
Client(age > 17)
The problem we have is that there are many different types of people in our
system that we would like to test for adulthood. For example, we have the
client's spouse (Client.spouse), and the clients children (Client.children),
who we also want to test for adulthood. Do we need to make a different DSL
expression for each case, or is there a way to "genericize" the DSL
expression so it could be used for any person?
TIA,
-Hans
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org <mailto:rules-users@lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users
<https://lists.jboss.org/mailman/listinfo/rules-users>
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com <http://www.jboss.com>
16 years, 7 months
DSL/DRL Problem
by ringsah@comcast.net
Hi All,
I am new to Drools - my company is evaluating it for use in a project. We are doing a proof of concept, and we are developing a DSL. One of our DSL expressions is
"client is an adult"
which is defined as
Client(age > 17)
The problem we have is that there are many different types of people in our system that we would like to test for adulthood. For example, we have the client's spouse (Client.spouse), and the clients children (Client.children), who we also want to test for adulthood. Do we need to make a different DSL expression for each case, or is there a way to "genericize" the DSL expression so it could be used for any person?
TIA,
-Hans
16 years, 7 months
Question on Rules, Packages, and adding/Removing from RuleBase
by James Brannan
Sorry if this is covered, I looked up in documentation and searched
here before posting.
env: Drools 4.0.7 running in Eclipse 3.3.2 on Mac OSX 10.5
Here's the confusion......
create 2 rules in agenda A in package A
create 2 rules in agenda B in package A
setFocus(A)
setFocus(B)
load some objects to evaluate in stateless session, call fireallrules
and works as expected.
now, say I wish to remove the rules in Agenda A from the RuleBase, I
tried three different ways, including removing the rules directly from
the rulebase!
But then, when I load in some new objects in a new session, set the
focus to Agenda A (which I thought I removed all the rules for
it)...instead of getting nothing or an exception, the rules in agenda
A still fire, even though I removed them (or I thought I did).
1) how do I remove rules if these three ways dont work (at least they
dont appear to
- or much more likely -
1) what the heck am I doing wrong....
2) my needs are two add and subtract agendas on the fly, as I will
have multiple customers with multiple sets of rules with different
agendas (is there a better way then this - i.e. should I have separate
rulebases?)
Thanks,
James A. Brannan
package com.sample;
import java.io.*;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.compiler.PackageBuilder;
import org.drools.StatefulSession;
import org.drools.rule.Package;
import org.drools.rule.Rule;
/**
* This is a sample file to launch a rule package from a rule source
file.
*/
public class DroolsTestTwo {
public static void main(String[] args) {
try
{
File dir = new File("/Users/brannanj/Documents/workspace/
BankingTutorial/src/main/rules");
File[] files = dir.listFiles();
PackageBuilder builder = new PackageBuilder();
for(int i = 0; i < files.length; i++)
{
if(files[i].getName().indexOf(".xml") > 0)
continue;
//Reader reader = ;
builder.addPackageFromXml(new FileReader(files[i]));
}
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
ruleBase.addPackage(builder.getPackage());
final StatefulSession session =
ruleBase.newStatefulSession(false);
User user = new User();
user.addRole("admin");
user.addRole("tester");
FooBarInfoTwo y = new FooBarInfoTwo();
y.setProperty("type");
y.setValue("cheddar");
FooBarInfoTwo z = new FooBarInfoTwo();
z.setProperty("age");
z.setValue(new Integer(32));
FooBarInfoTwo a = new FooBarInfoTwo();
z.setProperty("weight");
z.setValue(new Double(22.222));
FooBarInfo x = new FooBarInfo();
x.setValue("color", "red");
x.setValue("count", new Integer(23));
FooBarInfoTwo b = new FooBarInfoTwo();
b.setProperty("smelly");
b.setValue("true");
FooBarInfoTwo c = new FooBarInfoTwo();
b.setProperty("birthday");
b.setValue(new SimpleDate("12/01/2006"));
session.insert(x);
session.insert(y);
session.insert(z);
session.insert(a);
session.insert(b);
session.insert(user);
session.setFocus("GroupOne");
session.setFocus("GlobalsGroup");
session.setFocus("GroupTwo");
session.fireAllRules();
//remove GroupOne rules from package
pkg = builder.getPackage();
Rule[] rules = pkg.getRules();
for(int i =0;i<rules.length;i++)
{
System.out.println("Agendagroup in package: " +
rules[i].getAgendaGroup());
if(rules[i].getAgendaGroup().equals("GroupOne"))
{
pkg.removeRule(rules[i]);
}
}
System.out.println("GET THE RULES AGAIN TO SEE IF BY
REFERENCE......");
pkg = builder.getPackage();
rules = pkg.getRules();
for(int i =0;i<rules.length;i++)
{
System.out.println("Agendagroup in package: " +
rules[i].getAgendaGroup());
}
System.out.println("NOW EVALUATE THE RULEBASE
PACKAGE......");
pkg = ruleBase.getPackages()[0];
rules = pkg.getRules();
for(int i =0;i<rules.length;i++)
{
System.out.println("Agendagroup in package from
rulebase: " + rules[i].getAgendaGroup());
}
session.dispose();
final StatefulSession session2 =
ruleBase.newStatefulSession(false);
User user2 = new User();
user2.addRole("admin");
user2.addRole("tester");
FooBarInfo x2 = new FooBarInfo();
x2.setValue("color", "red");
x2.setValue("count", new Integer(23));
x2.setValue("description", "a foobarinfo");
System.out.println("SECOND TEST**************************");
session2.insert(x2);
session2.insert(user2);
session2.setFocus("GroupOne");
session2.fireAllRules();
session2.dispose();
System.out.println("RULES STILL THERE EVEN THOUGH SEEMS TO BE
BY REFERENCE!");
rules = pkg.getRules();
for(int i =0;i<rules.length;i++)
{
System.out.println("Agendagroup in package from rulebase: "
+ rules[i].getAgendaGroup());
if(rules[i].getAgendaGroup().equals("GroupOne"))
{
ruleBase.removeRule(rules[i].getAgendaGroup(),
rules[i].getName());
System.out.println("removed rule: " + rules[i].getName() +
" directly from ruleBase");
}
}
System.out.println("THIRD TEST WITH RULES REMOVED FROM
RULEBASE ************************");
final StatefulSession session3 =
ruleBase.newStatefulSession(false);
User user3 = new User();
user3.addRole("admin");
user3.addRole("tester");
FooBarInfo x3 = new FooBarInfo();
x3.setValue("color", "red");
x3.setValue("count", new Integer(23));
x3.setValue("description", "a foobarinfo");
session3.insert(x3);
session3.insert(user3);
session3.setFocus("GroupOne");
session3.fireAllRules();
System.out.println("Mystifying I still get the rules
fired....");
} catch (Throwable t) {
t.printStackTrace();
}
}
}
16 years, 7 months
Re: [rules-users] Declaring Variables in Condition
by Christine
On Mon, May 26, 2008 13:33, Markus Helbig wrote:
> currently i always get that $item1 couldn't not be matched.
I see no "item1" in your DSL, is that correct?
Christine
> Hi together,
>
> i'd like to do the following using a DSL
>
> in consequece part of a rule
>
> then
> Create a new Item $item1
> Set name of $item1 to "New Value"
> end
>
> DSL
>
> [consequence][]Create a new Item {item}={item}=new Object();
> [consequence][]Set name of {item} to {value}={item}.setValue({value});
>
> currently i always get that $item1 couldn't not be matched.
>
> Any suggestions?
>
> Thanks in advance, cheers
>
> Markus
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 7 months
Matching on instanceof without eval?
by Barry Kaplan
I would like to match on the class of a field. I know I can use "eval(option
instanceof OptionInstrument)", but my understanding is that the use of eval
precludes indexing. What I want is something like the below, which does not
work. Is some other mechanism other than putting type codes that are
redundant with the class for this use case?
thanks!
----
rule "Long Call/Put, Short Uncovered Call/Put"
when
position : Position(option : instrument, option.class ==
OptionInstrument.class)
then
...
end
----
--
View this message in context: http://www.nabble.com/Matching-on-instanceof-without-eval--tp17425953p174...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 7 months
Declaring Variables in Condition
by Markus Helbig
Hi together,
i'd like to do the following using a DSL
in consequece part of a rule
then
Create a new Item $item1
Set name of $item1 to "New Value"
end
DSL
[consequence][]Create a new Item {item}={item}=new Object();
[consequence][]Set name of {item} to {value}={item}.setValue({value});
currently i always get that $item1 couldn't not be matched.
Any suggestions?
Thanks in advance, cheers
Markus
16 years, 7 months
Re: [rules-users] creating rules via API?
by Marina
Thanks, Edson, Mark, for such a quick reply.
Mark, I'm not sure why you are saying that creating rules programmatically would be too complex for users? Maybe by 'users' we mean different things. In my case, a user will use a UI and create rules by selecting some pre-defined properties (like contract_amount), then selecting an operator (like <,==, > ...) then typing in a value to compare against, and then specifying what is the resulting action (a few approvers, for example). Easy. And then my code will transform this information into a rule like:
if (contract_amount > 5mil) then addApprover (user1). And so on.
So, the only part that is left is to transform this rule into DRL syntax, or, as I was hoping would be possible, into Rules objects directly. Something like:
Rule rule1 = new Rule()
rule1.addCondition(condition1)
rule1.addCondition(condition2)
rule1.setDependency (condition1, AND, condition2)
rule1.setAction(addApprover(user1))
As I understood from your response, it is not possible to do for now, unless I use an unofficial API, which scares me off a lot as this is not a good thing to base your application on an API that can change on you on a minute's notice :-)
Still, I will take a look at the descriptor package and might consider going this way if the performance of going through DRL turns out to be much worse.
Any plans on making this API public/published/stable? I would assume this is not an uncommon feature request from those who wants to embed a rule engine into their application.
Thanks a lot for all your suggestions!
Marina
----- Original Message ----
From: Edson Tirelli <tirelli(a)post.com>
To: Rules Users List <rules-users(a)lists.jboss.org>
Sent: Sunday, May 25, 2008 1:05:47 PM
Subject: Re: [rules-users] creating rules via API?
Marina,
My first advise for you is to forget JSR94. It is not worth to use it.
Regarding the creation of rules via API, you can use the descriptor classes in the package: org.drools.lang.descr.
There is not much documentation (anyone up to help on that?) but it is easy to understand how it works... just look at the result of parsing a DRL file and you will easily figure out:
DrlParser parser = new DrlParser();
PackageDescr pkgDescr = parser.parse( source );
[]s
Edson
2008/5/25 Marina <ppine7(a)yahoo.com>:
Hello,
I am working on a project that requires a rules engine to handle numerous rules for approval chain determination. My main choice at the moment is JBoss Rules engine. One issue came up though that I could not find a good answer in the documentation:
Is it possible to create rules programmatically via a public API? We already have a (pretty complex) admin screen as part of our application where users can build conditions and specify desired approval chains using the UI, integrated with all our back end stuff (domain objects, permissions, common look&feel, etc.). It would be a huge overhead to serialize these rules into DRL/XML files/streams and then have the rules engine parse them again....
JSR94 solves the problem of handling rules once they are read from rule files, but there is nothing about creating and persisting rules, unless I missed it.
thanks,
Marina
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
16 years, 7 months
Error while firing rules <compiler.DrlParser.getParser>
by pramod george
Hi all,
I was getting this error while firing my rule.
I did check on the sites but could not rectify.
Pls do give me some pointers to work on.
----------------
EJB Exception: ; nested exception is: java.lang.NoClassDefFoundError
Exception: ; nested exception is: java.lang.NoClassDefFoundError
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247)
at com.digitalharbor.rules.ejb.FusionRulesServer_b673w0_EOImpl_814_ WLStub.populateFactsFromQuery(Unknown Source)
at test.com.digitalharbor.rules.RulesTest.testPersonWebsiteMonitoring Rule(RulesTest.java:167) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) Caused by: java.lang.NoClassDefFoundError at org.drools.compiler.DrlParser.getParser(DrlParser.java:207) at org.drools.compiler.DrlParser.parse(DrlParser.java:60) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:165) at com.digitalharbor.rules.drools.FusionDroolsReader.readRules(FusionDroolsReader.java:75) at com.digitalharbor.rules.drools.FusionDroolsReader.getRuleBase(FusionDroolsReader.java:48) at com.digitalharbor.rules.drools.FusionDroolsServer.executeQuery(FusionDroolsServer.java:58)
Thanks,
-Promod
16 years, 7 months
creating rules via API?
by Marina
Hello,
I am working on a project that requires a rules engine to handle numerous rules for approval chain determination. My main choice at the moment is JBoss Rules engine. One issue came up though that I could not find a good answer in the documentation:
Is it possible to create rules programmatically via a public API? We already have a (pretty complex) admin screen as part of our application where users can build conditions and specify desired approval chains using the UI, integrated with all our back end stuff (domain objects, permissions, common look&feel, etc.). It would be a huge overhead to serialize these rules into DRL/XML files/streams and then have the rules engine parse them again....
JSR94 solves the problem of handling rules once they are read from rule files, but there is nothing about creating and persisting rules, unless I missed it.
thanks,
Marina
16 years, 7 months
Question about Metadata for Rules
by tservas
Hello everybody,
I have a simple question about annotations for rules. Is it possible to add
metadata
to a rule in the following or in a similar way?
------------------------------------------------------------------------------------------------
@CostumAnnotation(ruleType=RuleType.GOOD, otherInformation="This rule ist
very important since ...")
rule "A rule with metadata"
when
eval(true)
then
System.out.println(drools.getRule().getAnnotation(CostumAnnotation.class).toString());
end
------------------------------------------------------------------------------------------------
The annotatons should also be accesible within my java program otherwise it
wouldn't be very useful at all. So for example I should be able to do the
following
Package[] packages = ruleBase.getPackages();
for (Package pack : packages) {
Rule[] rules = pack.getRules();
for (Rule rule : rules) {
rule.getAnnotation(CostumAnnotation.class).toString();
}
}
Why would I like to have such meta information along with my rules in one
file? ... here it comes ...
The result of firing all my rules is a list of all rules (whether they have
been fired or not)
with certain meta information.
On the lhs of each rule I append an entry to that list with all the meta
information. Depending
on the inserted facts only a subset of all my rules fires and only a few
rules will add entries to
the list. My problem is that I want the rules that havn't been fired to
appear in the list with all
the meta information.
A possible but not feasible solution would be to double all my rules. For
each rule I could
add second rule that fires if the original rule doesn't fire and this newly
added rule inserts the
entry in the list with all the meta information. Doubling the number of
rules makes editing rules
error prone and tedious.
Another strategy could be to put all the meta information in a separate
file. Via the rule name
all meta information could be uniquely assigned to one rule. This strategy
is also not very appealing
since I have a lot of rules and editing rules again becomes error prone and
tedious, since I have to
keep the metadata file in sync.
The by far best solution I can think of is to allow annotaions in the drl
file as shown above.
Any hints or suggestions about the stated problem are highly appreciated.
Thanks in advance
--
View this message in context: http://www.nabble.com/Question-about-Metadata-for-Rules-tp17301548p173015...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 7 months