This isn't correct syntax: you cannot have a complex Java expression
on the left hand side of a contraints relational operator.
You might write this as
when
$conf : Configuration($category : category, eval(
$category.getCategoryId() != null ),
subCategories == null )
$subcats : ArrayList() from collect ( Category ( parent1 ==
($category. getCategoryId() ) ) )
then
2011/5/10 Abhay B. Chaware <Abhay.Chaware(a)kpitcummins.com>:
I’ve written this rule to be fired for Configuration object whose
category
is selected and subcategories are yet not selected.
rule "select sub categories"
salience 50
no-loop
when
$conf : Configuration($categoryId :
$conf.getCategory().getCategoryId() != null, subCategories == null )
$subcats : ArrayList() from collect (Category (
parent1 == $categoryId ) )
then
$conf.setSubCategories($subcats);
end
but it gives me following error.
[34,56]: [ERR 101] Line 34:56 no viable alternative at input ')' in rule
"select sub categories" in pattern Configuration
[34,57]: [ERR 102] Line 34:57 mismatched input '.' expecting ')' in rule
"select sub categories" in pattern Configuration
[34,74]: [ERR 102] Line 34:74 mismatched input '!=' expecting 'then' in
rule
"select sub categories" in pattern Configuration
Do I need to use “eval” around the “$conf.getCategory().getCategoryId()”
part ? Also in that case how do I get access to the property value ? It
doesn’t support something like this :
$conf : Configuration($categoryId : eval(
$conf.getCategory().getCategoryId() != null ), subCategories == null )
Regards,
Abhay
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wendy Mungovan
Sent: Tuesday, May 10, 2011 3:31 PM
To: Rules Users List
Subject: Re: [rules-users] FW: Basic rules question
Abhay,
You can use the normal Java gets (if your object has them).
when
$prod : Product ($prod.getMemory().getRam().getType() == "DDR")
...
instead of $prod.getMemory()... you I think should also be able to use
'this.getMemory()....'
(I have not tried these out to make sure)
Wendy
________________________________
From: Abhay B. Chaware <Abhay.Chaware(a)kpitcummins.com>
To: Rules Users List <rules-users(a)lists.jboss.org>
Sent: Mon, May 9, 2011 11:56:42 PM
Subject: Re: [rules-users] FW: Basic rules question
OK. Another one. How do I access and use a property of a member variable (
object ) of an object, in rules ?
e.g. in the same example, I need to check
1) if a product of type ‘laptop’ is inserted in memory AND
2) if the product’s MEMORY property ( object ) has an object of type DDR
ram attached.
In other words, here is the relationship of facts -
PRODUCT has member variable MEMORY ( which is an object )
MEMORY has member variable RAM ( which is again an object )
RAM has member variable TYPE ( which should be equal to “DDR” )
From within rules ‘when’ part, how do I check if there is a PRODUCT inserted
in memory whose MEMORY has a RAM of type DDR assigned ?
Regards,
Abhay Chaware
Sr. Designer | KPIT Cummins Infosystems Ltd | Board: +91 020 6652 5000 |
Extn: 2989 | abhay.chaware(a)kpitcummins.com |www.kpitcummins.com
P Please consider the environment before printing this e-mail
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Michael Anstis
Sent: Monday, May 09, 2011 4:27 PM
To: Rules Users List
Subject: Re: [rules-users] FW: Basic rules question
Yes :)
2011/5/9 Abhay B. Chaware <Abhay.Chaware(a)kpitcummins.com>
Mike,
What I meant was, There are say 10 objects of RAM in memory whose type is
DDR. Now my “Product” object has a member variable named “compatibleRAMs”,
and I would like to set an arraylist containing these 10 objects to the
“compatibleRAMs” variable of “Product” object in memory.
I am reading about the “collect” which can be used to create collections
from fact objects in memory. Something like.
When
$prod : Product (type==’laptop’)
$compatibleRAMs : ArrayList() from collect (RAM (type == ‘DDR’))
Then
$prod.setCompatibleRAMs($compatibleRAMs);
Am I on the right track ?
-abhay
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Michael Anstis
Sent: Monday, May 09, 2011 3:52 PM
To: Rules Users List
Subject: Re: [rules-users] FW: Basic rules question
Abhay,
Do you need a list?
You can assign RAM to COMPUTERS with this:-
when
$c : Computer( $type : type )
$r : RAM( compatibleWith == $type )
then
$c.addRAM( $r );
end
This would add all RAM (in Working Memory) compatible with COMPUTER to
computer.
You could use a list of RAM as a Fact in WM and change your rule to use
that:-
when
$l : MyList( )
$c : Computer( $type : type )
$r : RAM( compatibleWith == $type ) from $l
then
$c.addRAM( $r );
end
Or you can define a rule to construct the list too:-
when
$l : MyList( $t : typeRAM )
RAM( $c : $t )
then
$l.add( $r )
end
I assume you'd need to differentiate different lists for different types; so
I have shown use of "MyList" which could subclass ArrayList and have a
"Type
of RAM" attribute. Drools doesn't "do" generics.
With kind regards,
Mike
2011/5/9 Abhay B. Chaware <Abhay.Chaware(a)kpitcummins.com>
Wendy,
Thanks for helping me out so far.
I have another question. What if I have all my “RAM” objects inserted into
working memory. How should I write my rule’s “when” portion to get a
collection of all the RAM objects matching type “DDR” ? In other words, can
I get collection of facts assigned to a variable and use it in the “then”
part ?
Thanks
Abhay
==================================
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wendy Mungovan
Sent: Friday, May 06, 2011 5:47 PM
To: Rules Users List
Subject: Re: [rules-users] Basic rules question
Q2:
So the rule would be something like:
rule "RAM type"
when
$product: Product(type == "laptop");
then
//you are looking for the best way to set valid RAM types in the then
part of the rule?
$product.setRamType("DDR");
//or
$product.setValidRamOptions( getValidRamOptions("DDR"));
end
where getValidRamOptions would be a custom function included through 'import
function' so you can then load the choices from some where else. Or if
RamOptions were an object in memory you could have a rule like:
rule "RAM type"
when
$product: Product(type == "laptop");
$ramOptions: RAMOptions(type == "DDR");
then
$product.setValidRamOptions( $ramOptions.getList());
end
Wendy
==================================
Regards,
Abhay Chaware
Sr. Designer | KPIT Cummins Infosystems Ltd | Board: +91 020 6652 5000 |
Extn: 2989 | abhay.chaware(a)kpitcummins.com |www.kpitcummins.com
P Please consider the environment before printing this e-mail
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wendy Mungovan
Sent: Friday, May 06, 2011 5:47 PM
To: Rules Users List
Subject: Re: [rules-users] Basic rules question
Abhay,
Q1: I think that this will depend on how many different products you
have. If there is a small number it is more straight forward to have a rule
for each one (so the 2nd option). This allows all you logic to be in one
place. If there are a large number of products and writing a rule for each
one is intractable you probably would want to look into some generalizations
of the rules. Is that helpful?
Q2: I'm not quite sure what you are getting at in Q2. Are you trying to
write validation rules or rules that are modifying the facts?
Wendy
________________________________
From: Abhay B. Chaware <Abhay.Chaware(a)kpitcummins.com>
To: "rules-users(a)lists.jboss.org" <rules-users(a)lists.jboss.org>
Sent: Fri, May 6, 2011 4:59:46 AM
Subject: [rules-users] Basic rules question
Hi
I am a newbie to rule based applications and trying to get the concept of
rules. I have couple of questions about rules to start with, not
specifically about Drools though.
Q1 - Should rules be data/model specific or can/should they be generic or
both
==========================================================
e.g.
If selected product “TYPE” is “laptop”, then category “RAM” should have all
“DDR” type items compatible ( selecting items matching certain property )
OR
If selected product is “IBM T42”, then category “RAM” should have “512MB
DDR” , “1024MB DDR”, “2048MB DDR” compatible. ( assigning individual items
in rules )
OR
Combination of both
Q2 – How should be the data modeled in above case
==========================================================
e.g.
in product master, each item ( e.g. T40, T42 ) should have a “TYPE” ( e.g.
desktop or laptop ) , all items in category “RAM” should have a “TYPE” (
e.g. DDR ) and then control the assignment of RAM options to the PRODUCT
through Rule using “DDR” type ?
OR
in product master, each item ( e.g. T40, T42 ) should have a “TYPE” ( e.g.
desktop or laptop ) , all items in category “RAM” should have a
“compatibleProduct” column ( e.g. desktop or laptop ) and control the
assignment of RAM to PRODUCT through “dynamic” rules by selecting all the
RAMs by passing the “TYPE” of the product to the database handler.
Am I making my point clear ?
Thanks
Abhay
This message contains information that may be privileged or confidential and
is the property of the KPIT Cummins Infosystems Ltd. It is intended only for
the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in
error, please notify the sender immediately and delete all copies of this
message. KPIT Cummins Infosystems Ltd. does not accept any liability for
virus infected mails.
This message contains information that may be privileged or confidential and
is the property of the KPIT Cummins Infosystems Ltd. It is intended only for
the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in
error, please notify the sender immediately and delete all copies of this
message. KPIT Cummins Infosystems Ltd. does not accept any liability for
virus infected mails.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
This message contains information that may be privileged or confidential and
is the property of the KPIT Cummins Infosystems Ltd. It is intended only for
the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in
error, please notify the sender immediately and delete all copies of this
message. KPIT Cummins Infosystems Ltd. does not accept any liability for
virus infected mails.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
This message contains information that may be privileged or confidential and
is the property of the KPIT Cummins Infosystems Ltd. It is intended only for
the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in
error, please notify the sender immediately and delete all copies of this
message. KPIT Cummins Infosystems Ltd. does not accept any liability for
virus infected mails.
This message contains information that may be privileged or confidential and
is the property of the KPIT Cummins Infosystems Ltd. It is intended only for
the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in
error, please notify the sender immediately and delete all copies of this
message. KPIT Cummins Infosystems Ltd. does not accept any liability for
virus infected mails.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users