Re: [rules-users] drools grid or other high availability solution?

2012-11-12 Thread groovenarula
Follow up on high availability - 

I'm planning to use Drools for Capacity Management. In my use-case I need to
track # of hours of planned capacity that has been consumed based on hours
allocated. I'm planning on having a StatefulKnowledgeSession that will have
facts that store the # of hours of capacity that are available for a given
week. Then as work comes in (in the form of orders), it will be allocated
against this capacity. Even though at a high level this seems to be a simple
requirement, the process of allocating resources is very complicated and
using rules and FOL would greatly help manage the complexity of the
allocation process.

Based on the discussion above it looks like I won't be able to architect a
solution that's highly available. I'm not concerned about performance (the
drools engine is very efficient even on a single server). But it looks like
it's not possible to share / replicate session state contained in a
StatefulKnowledgeSession across separate JVMs (either on the same server or
across 2 servers). 

Am I correct or am I missing something ?



--
View this message in context: 
http://drools.46999.n3.nabble.com/rules-users-drools-grid-or-other-high-availability-solution-tp4020734p4020803.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] ConcurrentModificationException loading facts from db (Hibernate).

2012-07-03 Thread groovenarula
In my use case, I have ~ 200,000 rows in a table that I need lookup in order
to price an item. Rather than load the entire table into working memory,I'm
trying load the relevant rows (based on a matching criteria) and load those
as facts and then have my rules evaluate the loaded facts. Based on that
I've got the following rule :

rule Load pricelist
salience 1
when

$priceUnit : PriceUnit()
not ( exists Pricelist( id.prodid == $priceUnit.prodid ) )
$unitPrices : ArrayList() from collect ( Pricelist() from
PricelistUtilities.getPriceLists($priceUnit.prodid) ) 
then
for( Pricelist  priceList : (ListPricelist) $unitPrices ) {
insert (priceList);
}
end

In the rule above - 'PriceUnit' is the unit that I'm trying to price. And
'Pricelist' is the facts that I'm trying to fetch from a table based on the
prodid matching and inserting those into WM. The
PricelistUtilities.getPriceList returns a list of price list items that
match the 'Product id' (prodid). In the RHS, all I'm trying to iterate over
the list of pricelists and then insert those into WM.

When I execute the rule above, I can see that the rule is executing the
'select' to load pricelists :

Hibernate: 
/* 
from
PriceList 
where
status = 'A' 
and end_date = current_date 
and prodid = '010366' 
and cover_grade = 'LF' */ select
pricelist0_.prodid as prodid1_,
pricelist0_.cover_grade as cover2_1_,
pricelist0_.cover_series as cover3_1_,
pricelist0_.cover_color as cover4_1_,
pricelist0_.division as division1_,
pricelist0_.location as location1_,
pricelist0_.list as list1_,
pricelist0_.start_date as start8_1_,
pricelist0_.end_date as end9_1_,
pricelist0_.timestamp as timestamp1_,
pricelist0_.status as status1_,
pricelist0_.sold_flag as sold12_1_,
pricelist0_.base_price as base13_1_,
pricelist0_.list_price as list14_1_,
pricelist0_.add_on as add15_1_,
pricelist0_.landed_frt as landed16_1_ 
from
catalog.pricelist pricelist0_ 
where
pricelist0_.status='A' 
and end_date=current_date 
and prodid='123456' 
 
However, I get an java.util.ConcurrentModificationException when the rule
fires :

org.drools.runtime.rule.ConsequenceException: rule: Load pricelist

at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at 
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:737)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:701)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
at com.generic.rules.utils.DroolsTest.main(DroolsTest.java:46)
Caused by: java.util.ConcurrentModificationException
at 
java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at
com.sample.Rule_Load_pricelist_0.defaultConsequence(Rule_Load_pricelist_0.java:7)
at
com.sample.Rule_Load_pricelist_0DefaultConsequenceInvoker.evaluate(Rule_Load_pricelist_0DefaultConsequenceInvoker.java:27)
at 
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 6 more

If I comment the check for existing PriceList Items 'not ( exists Pricelist(
id.prodid == $priceUnit.prodid ) )', then it works fine. But as soon as I
add the check back, it breaks.

Is this a bug or am I doing something wrong ?

Any help / insight will be appreciated.

Thanks in advance.

--
View this message in context: 
http://drools.46999.n3.nabble.com/ConcurrentModificationException-loading-facts-from-db-Hibernate-tp4018431.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] ConcurrentModificationException loading facts from db (Hibernate).

2012-07-03 Thread groovenarula
That worked. Thanks for clearing this up.

--
View this message in context: 
http://drools.46999.n3.nabble.com/ConcurrentModificationException-loading-facts-from-db-Hibernate-tp4018431p4018437.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] NullPointerException using 'enabled' function.

2012-07-01 Thread groovenarula
I'm trying to use the enabled function to ensure that some rules only fire
under certain conditions. 

I have the following in my DRL :

rule Load pricelist
salience 1
when
$unitPrice : Pricelist() from 
PricelistUtilities.getPriceLists() 
then
insert ($unitPrice);
end

rule Retract a priced unit
salience 5000
when
$priceUnit : PriceUnit( basePrice != null )
then
System.out.println(Retracting ... + $priceUnit);
retract ( $priceUnit );
end

rule Price Unit by Prodid, Grade, Pattern, Color
enabled ( $detailPrice == true )
salience 2500
when
$priceUnit : PriceUnit ( $detailPrice : detailPrice )
$priceList : Pricelist( prodid == $priceUnit.prodid, 
coverGrade ==
$priceUnit.coverGrade, coverSeries == $priceUnit.coverSeries, coverColor ==
$priceUnit.coverColor )
then
modify ( $priceUnit )   {
setBasePrice ( $priceList.getBasePrice() );
}
end

rule Price Unit by Prodid, Grade, Pattern
enabled ( $detailPrice == true )
salience 2000
when
$priceUnit : PriceUnit ( $detailPrice : detailPrice )
$priceList : Pricelist( prodid == $priceUnit.prodid, 
coverGrade ==
$priceUnit.coverGrade , coverSeries == $priceUnit.coverSeries  )
then
modify ( $priceUnit )   {
setBasePrice ( $priceList.getBasePrice() );
}
end

rule Price Unit by Prodid, Grade, Pattern 
salience 1500
when
$priceUnit : PriceUnit ( )
$priceList : Pricelist( prodid == $priceUnit.prodid, 
coverGrade ==
$priceUnit.coverGrade , coverSeries ==  )
then
System.out.println(Pricing unit :  + $priceUnit +  from   + 
$priceList);
$priceUnit.setBasePrice($priceList.getBasePrice());
update ( $priceUnit );
end

Before adding the 'enabled' conditions to the rules, it all worked fine. But
after adding the 'enabled' function, I'm getting the following NullPointer
exception :

Exception executing consequence for rule Price Unit by Prodid, Grade,
Pattern  in com.sample: java.lang.NullPointerException
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at 
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1283)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1209)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1442)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at com.generic.rules.utils.DroolsTest.main(DroolsTest.java:37)
Caused by: java.lang.NullPointerException
at 
org.drools.common.DefaultAgenda.createActivation(DefaultAgenda.java:569)
at
org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:297)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:246)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:363)
at
org.drools.reteoo.LeftTupleSource.doModifyLeftTuple(LeftTupleSource.java:297)
at
org.drools.reteoo.LeftTupleSource.modifyLeftTuple(LeftTupleSource.java:271)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:429)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateModifyObject(CompositeLeftTupleSinkAdapter.java:260)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateModifyObject(CompositeLeftTupleSinkAdapter.java:275)
at
org.drools.reteoo.LeftInputAdapterNode.modifyObject(LeftInputAdapterNode.java:170)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at 
org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at 
org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:470)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:370)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:317)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:312)
at

[rules-users] Is it safe to 'build' a knowledgebase (compile rules) in a web app?

2012-04-18 Thread groovenarula
Hello,

In our environment we need to develop a framework wherein we would have
about a dozen rule templates whose data will be provided by users using
spreadsheets. Basically users will upload excel workbooks containing 10-12
worksheets and we'll be using ExternalSpreadsheetCompiler to generate the
appropriate DRLs that will then be 'add'ed to a KnowledgeBuilder class to
create a KnowledgeBase. We need to provide this capability use a web
application deployed in Tomcat.

Question - Are KnowledgeBuilder/ExternalSpreadSheetCompiler thread safe ? Is
it safe to develop this KnowledegeBase build process in a web application ?
If these classes are not thread safe, can someone please advise me on how to
make this framework single threaded ? It's perfectly acceptable for the
framework to be single threaded (essentially if more than a single session
tries to upload a workbook, they will have to wait a few mins if there are
other workbooks being processed ahead of theirs). I know the last question
is not drools centric, but it would be great to hear from the gurus on how
best I can make the build/compile process single threaded. 

Please let me know if this is a safe approach to take or if there are ways
to make this approach safe !

Thanks in advance,

-G


--
View this message in context: 
http://drools.46999.n3.nabble.com/Is-it-safe-to-build-a-knowledgebase-compile-rules-in-a-web-app-tp3922081p3922081.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools parser error accessing ArrayList.

2012-04-12 Thread groovenarula
That worked. Thanks. Also in the course of running into this, i did manage to
find a better way to do it. I move the for loop into the LHS and that worked
too. I think I'll go with the latter - I think it's a better way anyway...

--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-parser-error-accessing-ArrayList-tp3902766p3905559.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Drools parser error accessing ArrayList.

2012-04-11 Thread groovenarula
Hi,

I have a situation where I need to iterate over an ArrayList in the RHS of a
rule. The ArrayList is created in the LHS of the rule as follows :

rule Hello World
dialect mvel
when
$cur: Message()
$others : ArrayList ( size  0 ) from collect(Message(status ==
$cur.status,  this != $cur ))
then
for ( int ctr = 0; ctr  $others.size(); ctr++)
{
System.out.println((Message) $others.get(ctr));
}   
end 

This works in Drools 5.1.1. 

However it gives the following parser error in Drools 5.2.X :

  Unable to Analyse Expression for ( int ctr = 0; ctr  $others.size();
ctr++);
{
System.out.println((Message) $others.get(ctr));
}   ;:
  [Error: was expecting type: java.lang.Object; but found type:
Unknown]
  [Near : {... for ( int ctr = 0; ctr  $othe }]
  ^
  [Line: 6, Column: 0] : [Rule name='Hello World']

  java.lang.IllegalArgumentException: Could not parse knowledge.
  at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:50)
  at com.sample.DroolsTest.main(DroolsTest.java:23)

What am I missing here ? Any insight on a possible solution is appreciated.
This has become a big stumbling block for us to move from 5.1.1 to 5.2.1.

Thanks in advance,
Gurvinder



--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-parser-error-accessing-ArrayList-tp3902766p3902766.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools parser error accessing ArrayList.

2012-04-11 Thread groovenarula
Thanks W, 

It worked after I moved opening brace to the same line as the 'for'. 

But 'wow - we've spent several hours trying to resolve this on our own. And
we did not want to post before we confirmed that we've taking care of all
the obvious..

But seriously - someone is advocating that MVEL use an 'algorithm' to add
semicolons to the code - I don't know if that's such a good idea - IMHO,
it's going create more frustrating situations like these than it's going to
solve. Just my opinion though.

Thanks again for the fix. Appreciate it.

--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-parser-error-accessing-ArrayList-tp3902766p3902926.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Drools parser error accessing ArrayList.

2012-04-11 Thread groovenarula
laune,

Unfortunately, the earlier test worked when I set the dialect to java. It
does not work when it's set to mvel. 

When the rule is written as follows :

rule Hello World
dialect mvel
when
$cur: Message()
$others : ArrayList ( size  0 ) from collect(Message( status ==
Message.HELLO  ))   
then
for ( int ctr = 0; ctr  $others.size(); ctr++ ) {
System.out.println(Got message :  + (Message) 
others.get(i));
}   
end

I am now getting the following error :

Unable to Analyse Expression for ( int ctr = 0; ctr  $others.size();
ctr++ ) {
System.out.println(Got message :  + (Message) 
others.get(i));
}   ;:
[Error: unable to resolve method using strict-mode:
org.drools.spi.KnowledgeHelper.$others()]
[Near : {... int ctr = 0; ctr  $others.size(); ctr++ ) { }]
^
[Line: 7, Column: 0] : [Rule name='Hello World']

java.lang.IllegalArgumentException: Could not parse knowledge.
at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:50)
at com.sample.DroolsTest.main(DroolsTest.java:23)

It looks like for some reason, the parser is unable to decipher the $other. 

Any insight into what could cause this ?

Thanks in advance,

Gurvinder


--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-parser-error-accessing-ArrayList-tp3902766p3903052.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Rule does not fire after 'Modify/Update' of a fact - Drools 5.1.1 !

2011-04-05 Thread groovenarula
Thanks for the response Wolfgang.

I am not calling ksession.fireAllRules(1). I just have
ksession.fireAllRules();

I tried inserting 2 pairs - One product with a price set and the other left
as null. The one with the null still does not fire the 'Set Options Price'
after it's price has been set by the 'Set Price' rule. The one with the
price set before calling 'insert' does fire the rule.

I'm uploading the relevant java,rules and fact definitions along with a
execution log for review.
 
Thanks again for looking into this.

Gurvinder

http://drools-java-rules-engine.46999.n3.nabble.com/file/n2779772/Sample.drl
Sample.drl 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2779772/DroolsTest.java
DroolsTest.java 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2779772/Product.java
Product.java 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2779772/Option.java
Option.java 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n2779772/test.log
test.log 


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Rule-does-not-fire-after-Modify-Update-of-a-fact-Drools-5-1-1-tp2778508p2779772.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Rule does not fire after 'Modify/Update' of a fact - Drools 5.1.1 !

2011-04-05 Thread groovenarula
Just ran another test, I removed the check for 'price == null' in the 'Set
Options Price' rule - so the rules now reads :

rule Set Options price
salience 50
when
$prod : Product ( )
$option : Option ( product == $prod ) 
then

System.out.println( Getting Options  + $prod ); 

end


Yet, the rule does not fire. It's almost as if the 'Option ( product ==
$prod ) is not being honored. I'm going to change my implementation of
'equals' on the product fact and see what happens next.

Just wanted to provide you'll with an update.

G

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Rule-does-not-fire-after-Modify-Update-of-a-fact-Drools-5-1-1-tp2778508p2779855.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Rule does not fire after 'Modify/Update' of a fact - Drools 5.1.1 !

2011-04-04 Thread groovenarula
Hello all,

For some reason I have a rule that does not fire after a Modify/Update.

I have 2 facts - Product and Option. The relationship between them is that a
'Product' can have 0 - N 'Option'(s).

Based on that, I added a 'product' field to the 'Option' object. I'm
creating and inserting my facts 
using the following code :

Product prod = new Product (001,002, A);
prod.setPrice(new BigDecimal(300.00));
Option opt = new Option (H1,,prod);

ksession.insert(prod);
ksession.insert(opt);


Now in my .DLR, I have the following rule :

rule Set Options price
salience 50

when

$prod : Product ( price != null )
$option : Option ( product == $prod ) 

then

System.out.println( Getting Options  + $prod ); 

end

This gives me the correct output in the console :

  Getting Options Product [category=001, grade=A, price=300.00, style=002]

The rule fired successfully.

I start running into problems when I try to update the 'price' field using a
rule, instead of through code. 

So for example, if I have the following rule also defined in the same drl
file : 

rule Set price
salience 500

when

$prod : Product ( category == 001, price == null )

then

$prod.setPrice ( new BigDecimal ( 300.00 ) );
update( $prod );
System.out.println( $prod ); 

end

And then change my code as follows (remove the setPrice call) :

Product prod = new Product (001,002, A);
Option opt = new Option (H1,,prod);

ksession.insert(prod);
ksession.insert(opt);

I only get the following output :

Product [category=001, grade=A, price=300.00, style=002]

What am I missing here ? I thought the rule 'Set Price' should update the
product fact with 
the new price and the rules would get re-evaluated. After the re-evaluation,
the LHS of 'Set Options Price' should now be true and it should have fired.
But it does not. 

Am I mis-understanding something about activation here ? If I am, can
someone please help explain what the gap is and how to re-write the rules so
that I can achieve the above objective ?

Any help will be appreciated. I've spend several hours trying different
permutations and combinations and got no where.
 
Thanks
Gurvinder


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Rule-does-not-fire-after-Modify-Update-of-a-fact-Drools-5-1-1-tp2778508p2778508.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] is is possible to insert facts into working memory from functions ?

2011-03-11 Thread groovenarula
Duh !!! Of course - I forgot the import statement. For some reason I thought
KnowledgeHelper would already be imported.

Thanks for your help once again W !

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/is-is-possible-to-insert-facts-into-working-memory-from-functions-tp2663433p2664731.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to Iteriate over a list of string values ?

2011-03-10 Thread groovenarula
ok ! It looks like Wolf, your idea of using 'for' in the RHS worked using
rule templates. 

It's still 'java' code though. I just wish there was a cleaner way to load
facts into WM without going through java. Declaring types in rules is a very
nice feature. If there's a cleaner way to 'load' these from different
sources like spreadsheets without using java, I would like to know that so
that I can allow drools to be used in a 'stand alone' mode and let the
business users to 'play' with different rules before IT needs to be pulled
in to integrate the model with enterprise systems. If anyone has any ideas
on how to do, please send it across.

Thanks
G


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Is-it-possible-to-Iteriate-over-a-list-of-string-values-tp2654135p2660559.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] is is possible to insert facts into working memory from functions ?

2011-03-10 Thread groovenarula
Hello all,

As the title states, I need to create new facts and insert them into working
memory from a function. Is it possible to do that ? I tried to create a
function with 'KnowledgeHelper' as a parameter and my rule file failed to
compile. Then I even tried to reference 'drools' instance variable from
within a function and that failed to compile too. 

So if this is possible, I'd appreciate it if someone can shed some light on
this !

Thanks in advance,
G

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/is-is-possible-to-insert-facts-into-working-memory-from-functions-tp2663433p2663433.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to Iteriate over a list of string values ?

2011-03-09 Thread groovenarula
All,

Thanks for the quick responses. 

Mantis, I did try using from [ one,two,three ] syntax, but it did not
work. It gave me a parser error. 

Basically I need to create a spreadsheet reader that inserts values into WM
before reasoning over them. The spreadsheet that the users are currently
using for their own internal use look something like this :

XXX  YYY   one,two,three

where XXX, YYY will be in 2 individual cells that will hold the values for
one fact, and the one,two,three will be in a third cell will from which I
need to create separate instances for each value of fact #2.

I'm trying to see if there's a way to use the current spreadsheet without
changing it drastically. That will make the solution a lot more acceptable. 

W - Can you please elaborate on your last statement :

It's doable from a spreadsheet, using the forall substitution.

If I'm not mistake that's what I would use if it's a decision table - Would
I be able to use 'forall' even if I'm using a template to insert the facts ?

I'll try the different solution and see what fits the best. But if you can
please elaborate on this, it will help.

Thanks
G


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Is-it-possible-to-Iteriate-over-a-list-of-string-values-tp2654135p2654934.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to Iteriate over a list of string values ?

2011-03-09 Thread groovenarula
I was hoping to be able to give the Business Analysts an overall process to
use Drools by avoiding as much java code as possible. If there was some way
to do this, I could have just had them create different templates they would
need (based on the format of the spreadsheets they currently use) and
minimize interactions between the B.A.s and the developers. 

I'll just keep digging for a bit 

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Is-it-possible-to-Iteriate-over-a-list-of-string-values-tp2654135p2655825.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to validate literal values on the LHS of rules.

2011-03-07 Thread groovenarula
Ok - I managed to get this to work. Now the main question - I've used
ExternalSpreadsheetCompiler. This is still considered 'Experimental' per the
5.1.1 documentation ! And when I look at some history it looks like
RuleTemplates have been around since August of 2008. Is there a road map of
when RulesTemplates will be considered mainstream and a first class citizen
of drools ? Also are there plans to change this API ? What's the future of
RulesTemplates ? I can a lot of uses of this feature in our use case. But
before I get ahead of myself here, I'd like to know what the risk is of
basing my solution on this feature.

Thanks in advance,
G


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-validate-literal-values-on-the-LHS-of-rules-tp2638081p2648092.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] How to validate literal values on the LHS of rules.

2011-03-05 Thread groovenarula
Hello all,

In my use case, I am planning on using decision tables to implement rules
that contain product information (product attributes - like product grade,
product style etc). I've managed to put together the spreadsheet and have
been successful in generating different set of rules (using rule templates)
from this spreadsheet. The spreadsheet with contain basic product
information that product fact will be matched against. 

e.g. The spreadsheet will contain columns of product grade and product
styles that when translated into rules, the LHS would look something like 

 Product ( grade == 010, style == 515 )

Where the '010' and '515' would come from a spreadsheet (decision table)
that the user's provide.

Now here's the challenge. I need to also provide a means for the user to
validate the 010 and 515. The available product grade and styles are
available in a database table. So I should be able to use that to build
second set of rules (templates). So I'm thinking, if there's a way to
convert the user supplied spreadsheet and make it a table of 'facts' of the
validation rules, I should be able to verify the value 010 515 against
the database. 

Is that the best way to go about this ? If so, can someone please point me
to a way to load facts from a spreadsheet ? I have looked around and found
that there is a jxls project that allows loading of JavaBeans from values in
spreadsheet. But it requires xml files to be configured. I really like the
way rule templates work (by simply state substitution variables in the
template itself - thereby avoiding the whole need to configuration xml
files). I think if there's a way to load facts using templates from a
spreadsheet, I should be able to use that concept to validate the values in
my rules.

So is it possible to do the above ? Also is there a better way ?

Any insight would be appreciated.

Thanks in advance,
Gurvinder


 

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-validate-literal-values-on-the-LHS-of-rules-tp2638081p2638081.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to validate literal values on the LHS of rules.

2011-03-05 Thread groovenarula
Manstis,

You are correct. There are parameters that users will provide in the
spreadsheet that I need to validate. Actually there will be one spreadsheet.
It's going to serve 2 purposes. Provide a decision table AND also be a
container of data for a few Rule Templates. The concept is that if a product
does not match any criteria on the spreadsheet, then the next step is to
extract the data from the spreadsheet and create rules where the match would
be more 'generic'. So I'm planning to use the decision table to deduce the
more 'generic matching conditions'. In both cases, I need to be able to
validate the parameters in the spreadsheet against values in a data table. 

Taking my earlier example - The user might provide product attributes - e.g.
product number ABC510 in the spreadsheet. I have to ensure that the ABC510
is a valid product number before I can allow the spreadsheet to be used as
the source of my rules (the actual rules will determine the price that will
be charged for the product).

I'll be able to easily create a new set of rules to validate the product
information against the data table we have. That should not pose a major
problem. The question is how to easily convert the spreadsheet into an
arraylist of facts that I can insert into this rule set. I know I can
'program' this manually using POI etc. I'm looking to see if there's a less
fragile way to load the spreadsheet as facts ? If there is a quicker way,
I'd love to hear about it.

Hope that makes more sense and is a little clearer than mud :).


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-validate-literal-values-on-the-LHS-of-rules-tp2638081p2639892.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Getting different results from decision tables based on number of facts - all other fact information staying the same.

2011-02-10 Thread groovenarula

Background : 

I have an object model is as follows :

Units  1 --- 0..N Options

where a unit (basically an item in stock),  can have 0 … N Options. 

Items themselves have 2 primary fields - an item type (called group - a 3
digit number that represents the category the item belongs to) and a minor
item number (called style - another 3 digit number that represents the
styling of the item). 

Options represent additional enhancements that can be added to the base
units. Very similar to options that can be purchased when buying a new car -
wider wheels/tires, navigation system, leather seats etc. 

Now the use case is to provide the business with easy to use decision tables
that will enable them to Price items based on the base unit and the options
added to the base unit. The way pricing works is that each options has a
standard price. However there are times when options associated with a
specific group and style are priced differently. 

e.g. Option 'F103' would alway be priced at 100 bucks, however when 
added
to a unit with group '010' and style '315' it should be priced at 120.

I've created the following approach to meet the pricing rules above: 

rule Set F103 Option price based on Group/Style
salience 50
when
$unit : Unit (  group == 010, style == 315 )
$option : Option (unit == $unit )
  Option (optionPrice == null, code == F103 )
then

$option.setOptionPrice(120.00);
retract ( $option );
end

rule Set F103 Option base price
salience 5
when 
$option : Option ( optionPrice == null, code == F103 )
then
$option.setOptionPrice(100.00);
retract ( $option );
end

Question : Is there a better way to implement the rules stated above ?

The DRL works as expected when I insert one or multiple items in working
memory. The appropriate rules fire and when Group / Style = 010 / 315, the
price for the option is set to 120, but when Group and Style is anything
else, the option does get priced at 100.00.

However, when I try to implement the same rule using decision tables, I get
different results. To implement the above, I created 2 rule tables :

1. The first rule table establishes the pricing of options that are not
specific to a group / style as follows:

CONDITION  PRIORITY
ACTION
$option : Option 
code == $param, optionPrice == null   5
$option.setOptionPrice($param); retract($option)

2. A second rule table that adds the unit constraints as follows (with
PRIORITY 50):

CONDITION  CONDITION  CONDITION
$unit : Unit  $option : Option
group == $param  style == $param unit == $unit, code == $param,
optionPrice == null

ACTION
$option.setOptionPrice($param); retract ( $option);

There in lies my dilemma. 

When I send one unit with Group Style 010 315 and option F103, it prices the
option properly @ 120.00. 

When I send in a unit with a different style (same group = 010), it also
prices the option properly at 100.  

When I when I send 2 units together - one with group and style 010 315 and
another having the same group but a different style (515 for example), it
prices the option for both units @ 120 :

   010 315 option price = 120.00 (correct result)
   010 515 option price = 120.00 (wrong result)

But if the second unit on the 2 units has a different group (011 for
example), I get the right option prices :
 010 315 option price = 120.00 (correct result)
 011 315 option price = 100.00 (correct result)

For what ever reason, it does not fire the generic pricing option even
though the second unit's G/S does not match 010 315.

Can anyone please shed some light on what I'm doing wrong here ?

Any help will be appreciated.

Thanks in advance.
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Getting-different-results-from-decision-tables-based-on-number-of-facts-all-other-fact-information-s-tp2467364p2467364.html
Sent from the Drools - User mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Getting different results from decision tables based on number of facts - all other fact information staying the same.

2011-02-10 Thread groovenarula

Never mind. I figured it out. I had not merged the fact cell over the 2
columns that had the unit constraint. I'm good. Thanks for looking though.
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Getting-different-results-from-decision-tables-based-on-number-of-facts-all-other-fact-information-s-tp2467364p2467791.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Getting different results from decision tables based on number of facts - all other fact information staying the same.

2011-02-10 Thread groovenarula

Thanks for the pointer Wolfgang. I'll change the DRL accordingly.
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Getting-different-results-from-decision-tables-based-on-number-of-facts-all-other-fact-information-s-tp2467364p2468740.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-02-09 Thread groovenarula

Wolfgang - adding the dialect to the 'Functions' cell worked like a charm.
Edson's solution did not work without the dialect mvel. So in this case MVEL
is a must have.  But then your suggestion to add the dialect next to the
cell keyed Functions worked.

Thanks again for your help.
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2462063.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-02-05 Thread groovenarula

Edson/Wolfgang,

Thanks to your suggestions, I've got this working the way I need it using
rules defined in a .drl file. I think I have just one hurdle left before I
start working out how to get it working through decision tables - and that
is how to specific 'mvel' dialect for decision tables. 

Edson as you pointed out, in order for me to send the value of $param to the
accumulator, I should use mvel to create a list of the parameters (the
$param and the fact being matched). I tried looking for ways to specify mvel
and couldn't find how to set the dialect for rules defined in decision
tables.

Thanks,
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2432302.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-29 Thread groovenarula

Edson,

I did manage to use the 'CollectSetAccumulateFunction' as a template for the
MatchAll and have also successfully 'called' the accumulate function from a
rule written in a .drl file. But I'm stuck at one point - how to send the
value of $param to the accumulate method ? From what I understand, the
accumulate method is invoked for each fact - so if I write 

 MatchAll( $o ) it will invoke the accumulate method and passing $o fact
to the method via the 'Object value' parameter. 

So far so go, however, I'm stuck on how to pass the value of '$param' to the
accumulate method (or any other method like init, getResult for that
matter).

One option I can think of is to change the definition of the Option fact to
include a 'param' field and then write a rule that sets the value of that
field to $param (so every Options param field would get set to the value of
$param). I can then extract that in the accumulate method it self. But is
there a better way that I might be missing ?

Thanks in advance,
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-29 Thread groovenarula


Edson,

That worked beautifully !

Drools is looking more and more promising for what we need to do.

Thanks for all your help,

Gurvinder


-Original Message-
From: Edson Tirelli-4 [via Drools - Java Rules Engine] 
[mailto:ml-node+2380361-572428564-9...@n3.nabble.com]
Sent: Sat 1/29/2011 10:59 PM
To: Gurvinder Narula1
Subject: Re: How to write a rule that fires when it matches against specific 
facts in working memory.
 

   Up to Drools 5, the accumulate function API supports only a single 
argument to the function, but that argument can be an array or a list. So what 
I do on my own implementations is to pass the $param as one element of the 
array and $o as the other. It is not ideal, but it is how you can do that in 
Drools 5. In Drools 6 I will change the API to support multiple parameters, but 
I've been postponing that because when I do it, it will break existing 
implementations of the interface.

   Anyway, if you are using the MVEL dialect, creating a list is as simple as 
wrapping it in [ ], as you could see in my previous e-mail.

$options : List() from accumulate(Â 
      $op : Option(),
      matchAll( [ ${param}, $op ] ) )

    Edson

2011/1/29 groovenarula [hidden email]



Edson,

I did manage to use the 'CollectSetAccumulateFunction' as a template 
for the
MatchAll and have also successfully 'called' the accumulate function 
from a
rule written in a .drl file. But I'm stuck at one point - how to send 
the
value of $param to the accumulate method ? From what I understand, the
accumulate method is invoked for each fact - so if I write

    MatchAll( $o ) it will invoke the accumulate method and passing 
$o fact
to the method via the 'Object value' parameter.

So far so go, however, I'm stuck on how to pass the value of '$param' 
to the
accumulate method (or any other method like init, getResult for that
matter).

One option I can think of is to change the definition of the Option 
fact to
include a 'param' field and then write a rule that sets the value of 
that
field to $param (so every Options param field would get set to the 
value of
$param). I can then extract that in the accumulate method it self. But 
is
there a better way that I might be missing ?

Thanks in advance,
Gurvinder

--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html
 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html?by-user=t
 

Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list

[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users





-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com


___ 
rules-users mailing list 
[hidden email] 
https://lists.jboss.org/mailman/listinfo/rules-users





If you reply to this email, your message will be added to the discussion below:
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2380361.html
 
To unsubscribe from How to write a rule that fires when it matches against 
specific facts in working memory., click here 
http://drools-java-rules-engine.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=2294599code=Z25hcnVsYTFAbGEtei1ib3kuY29tfDIyOTQ1OTl8MjAzMTM1NDY2Mw==
 . 


-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2381946.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-26 Thread groovenarula

Thanks for outlining the approach, Edson.

Unfortunately, I'm a newbie using drools, so I just need some clarification
on what you mean by 'matchAll is your own accumulate function with the
semantics you described.' ? Do you mean that I have to create a 'custom'
accumulate function ? 

Edson, if that's the case, then I'll try to search for example of creating a
custom function. When I last searched, I did find an example on the
Internet, however, I don't think I found details of how to make the function
available to the rules engine (is it as simple as including the jar in the
classpath or do I need to take addtional steps to use Matchall in drl ?) 

Can you please elaborate for the benefit of a noobie ?

Thanks
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2354793.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-26 Thread groovenarula

Thanks Wolfgang. I found it. I Work on it and let you'll know how it goes.

Sent from my iPhone

On Jan 27, 2011, at 1:08 AM, Wolfgang Laun-2 [via Drools - Java Rules Engine] 
ml-node+2356705-1292265879-9...@n3.nabble.com wrote:

 Accumulate functions are very well documented in the Expert manual. Look for 
 a section titled Accumulate Functions.
 
 You could also use accumulate with all the steps in inline code, which is 
 documented in the preceding section.
 
 -W
 
 
 
 On 26 January 2011 16:50, groovenarula [hidden email] wrote:
 
 Thanks for outlining the approach, Edson.
 
 Unfortunately, I'm a newbie using drools, so I just need some clarification
 on what you mean by 'matchAll is your own accumulate function with the
 semantics you described.' ? Do you mean that I have to create a 'custom'
 accumulate function ?
 
 Edson, if that's the case, then I'll try to search for example of creating a
 custom function. When I last searched, I did find an example on the
 Internet, however, I don't think I found details of how to make the function
 available to the rules engine (is it as simple as including the jar in the
 classpath or do I need to take addtional steps to use Matchall in drl ?)
 
 Can you please elaborate for the benefit of a noobie ?
 
 Thanks
 Gurvinder
 
 --
 View this message in context: 
 http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2354793.html
 Sent from the Drools - User mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 [hidden email]
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 ___ 
 rules-users mailing list 
 [hidden email] 
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2356705.html
 To unsubscribe from How to write a rule that fires when it matches against 
 specific facts in working memory., click here.

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2359225.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-26 Thread groovenarula

Edson,

This surely looks like a great template to base my implementation - it looks 
like an great starting point.

Gurvinder



-Original Message-
From: Edson Tirelli-4 [via Drools - Java Rules Engine] 
[mailto:ml-node+2359987-1512063982-9...@n3.nabble.com]
Sent: Wed 1/26/2011 11:44 PM
To: Gurvinder Narula1
Subject: Re: How to write a rule that fires when it matches against specific 
facts in working memory.
 

   I suggest you use this as a base for your implementation, as I think it 
will help you:

https://github.com/droolsjbpm/droolsjbpm/blob/master/drools-core/src/main/java/org/drools/base/accumulators/CollectSetAccumulateFunction.java

https://github.com/droolsjbpm/droolsjbpm/blob/master/drools-core/src/main/java/org/drools/base/accumulators/CollectSetAccumulateFunction.java
 Â Â  Edson


2011/1/26 groovenarula [hidden email]


Thanks Wolfgang. I found it. I Work on it and let you'll know how it 
goes.

Sent from my iPhone

On Jan 27, 2011, at 1:08 AM, Wolfgang Laun-2 [via Drools - Java Rules 
Engine] [hidden email] http://user/SendEmail.jtp?type=nodenode=2359225i=0 
 wrote:



Accumulate functions are very well documented in the Expert 
manual. Look for a section titled Accumulate Functions.

You could also use accumulate with all the steps in inline 
code, which is documented in the preceding section.

-W




On 26 January 2011 16:50, groovenarula [hidden email] 
http://user/SendEmail.jtp?type=nodenode=2356705i=0by-user=t  wrote:



Thanks for outlining the approach, Edson.

Unfortunately, I'm a newbie using drools, so I just 
need some clarification
on what you mean by 'matchAll is your own accumulate 
function with the
semantics you described.' ? Do you mean that I have to 
create a 'custom'
accumulate function ?

Edson, if that's the case, then I'll try to search for 
example of creating a
custom function. When I last searched, I did find an 
example on the
Internet, however, I don't think I found details of how 
to make the function
available to the rules engine (is it as simple as 
including the jar in the
classpath or do I need to take addtional steps to use 
Matchall in drl ?)

Can you please elaborate for the benefit of a noobie ?

Thanks
Gurvinder


--
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2354793.html?by-user=tby-user=tby-user=t
 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2354793.html
 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2354793.html?by-user=tby-user=t
 
Sent from the Drools - User mailing list archive at 
Nabble.com.
___
rules-users mailing list

[hidden email] 
http://user/SendEmail.jtp?type=nodenode=2356705i=1by-user=t 

https://lists.jboss.org/mailman/listinfo/rules-users 
https://lists.jboss.org/mailman/listinfo/rules-users




___ 
rules-users mailing list 
[hidden email] 
http://user/SendEmail.jtp?type=nodenode=2356705i=2by-user=t  

https://lists.jboss.org/mailman/listinfo/rules-users 
https://lists.jboss.org/mailman/listinfo/rules-users





If you reply to this email, your message will be added to the 
discussion below:

http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2356705.html?by-user=tby-user=t
 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2356705.html
 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write

Re: [rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-21 Thread groovenarula

Thanks for the options, Bruno and Wolfgang. 

But is there a more 'generic' way to do the matches ? The problem I have is
that the # of instances that might match could vary. And I have to provide a
means for the business users to be able to provide that 'option's code'
using a decision table. Basically I need to be able to provide a construct
that's would look something like :

Options
P1,P2
P1,P4,P5

So in the above decision table had 2 rules where in the first row represents
a rule that matches against Options with Codes P1 and P2. And the second
rule would match against options with codes P1, P4 and P5. 

Is it possible to represent this using Drools decision tables ?

Thanks
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2300564.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] How to write a rule that fires when it matches against specific facts in working memory.

2011-01-20 Thread groovenarula

Hello,

I have a fact called 'Option' :

public class Option {
private String code;

private Item item;
public String getCode() {
return code;
}
public void setCode(String optionCode) {
this.code = optionCode;
}

At any point in time, the working memory can have several Option instances
with different code values. My rules need to fire specifically when the
working memory contains a specific set of options. e.g. Rule 1 should fire
if and only if the working memory contains 2 option instances one with code
P1 and the other with P2 (order should not matter).

I tried to use 'forall' as follows :

rule Matched Options 
when
forall (
Option ( code == P1 || code == P2 ) 
   )
then
//insert( new IsPriced( i ) );  
System.out.println ( Priced using G/S );
end

However, the rule above never fires. Maybe I should be taking a different
approach. I'm still learning through how to create rules. So any
help/suggestions on how to tackle the above will be appreciated.

Thanks
Gurvinder

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2294599.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Can we use 'from' CE in Decision Tables ?

2009-12-03 Thread groovenarula

Thomas,

Thanks the response. I'm not sure how the newlines disappeared from my post
either. I do know I'd put them all there neatly formatted.

I'll try out solution you provided and let you know how it goes. I guess
I'll have to resort to quite a few evals in my decision tables, given that
'from' does not work in there. Don't like it, but if it works, at least I'll
be able to acheive my project's objects.

Thanks again for the solution. I'll let you know how it works out.

Gurvinder


Swindells, Thomas wrote:
 
 Hi Gurvinder.
 
 Not sure where new lines have gone from your email - it makes it very hard
 to read!
 
 I've also been working on a project which uses decision tables and I
 couldn't find any way to use from statements either.  I'm hoping to get
 some time within the project to work on the drools decision table code to
 add some improvements, providing support for the from clause is one of
 these however I'm not sure whether I will get time or not.
 
 However I think you may be able to restructure your code so that you don't
 need the from cause however I've not fully tested it. The code relies on
 their existing a constructor which takes the promotion code and the equals
 is defined that P1.equals(P2) when P1.code.equals(P2.code).
 
 If you wanted to match that a promotion of a particular name exists then I
 think you can use the rule
 Rule existsPromotion  when
 Line(promos contains (new Promotion(HOTBUY))) then ...
 
 However the expression language doesn't support not contains which means
 you have to full back to use java:
 rule  contains d
   when
 line : Line(eval(!line.getPromos().contains(new
 Promotion(HOTBUY
   then
 ...
 end
 
 If you prefer you could also define a method on Line
 containsPromotionWithCode(code) which would let you choose how to do the
 match.
 
 As a spreadsheet the above would then look something like the following:
 RuleTable Hotbuys
 
 
 
 
 
 NAME
 
 CONDITION
 
 ACTION
 
 
 
 l :Line
 
 
 
 
 
 eval(!l.getPromos().contains(new Promotion($param)))
 
 System.out.println($param);
 
 Rule Name
 
 Number Directors
 
 Warning
 
 example1
 
 Hotbuys
 
 Hotbuys missing
 
 
 Hope that helps,
 
 Thomas
 
 
 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of groovenarula
 Sent: 03 December 2009 06:51
 To: rules-users@lists.jboss.org
 Subject: [rules-users] Can we use 'from' CE in Decision Tables ?
 
 Hello all, Is it possible to define the follow rule in a decision table :
 rule Activate Promotion when l : Line( ) not ( Promotion ( code ==
 HOTBUY ) from l.promos ) then #do some action end The rule above works
 perfectly for what I need when defined in a rule file. However, when I try
 to define it in a decision table so that the 'code' can be feed from a
 spreadsheet, I use the following values in the rules cells : RuleTable
 HOTBUYS CONDITION ACTION l : Line not ( Promotion ( code == $param )
 from l.promos ) System.out.println($param added); PROMOTION PROMOTION
 HOTBUY BESTBUY I'm getting the following parser errors [10,17]: [ERR 101]
 Line 10:17 no viable alternative at input 'Promotion' in rule _11 in
 pattern Line [10,29]: [ERR 101] Line 10:29 no viable alternative at input
 'code' in rule _11 [10,63]: [ERR 102] Line 10:63 mismatched input ')'
 expecting 'then' in rule _11 java.lang.IllegalArgumentException: Could
 not parse knowledge. at
 com.sample.DecisionTableTest.readKnowledgeBase(DecisionTableTest.java:85)
 at com.sample.DecisionTableTest.main(DecisionTableTest.java:28) Also in
 Eclipse IDE, I get the following error : Unknown error while parsing.
 This is a bug. Please contact the Development team. NewPromotions.xls Is
 it possible to use 'from' conditional element in decision tables ? If so,
 what am I doing wrong. If not, then what's the best approach to implement
 the rule above in a decision table. I'm running Drools 5.1.0M1 in Eclipse.
 Help truly appreciated. Gurvinder
 
 View this message in context: Can we use 'from' CE in Decision Tables
 ?http://n3.nabble.com/Can-we-use-from-CE-in-Decision-Tables-tp67005p67005.html
 Sent from the Drools - User mailing list
 archivehttp://n3.nabble.com/Drools-User-f47000.html at Nabble.com.
 
 
 
 **
 This message is confidential and intended only for the addressee. If you
 have received this message in error, please immediately notify the
 postmas...@nds.com and delete it from your system as well as any copies.
 The content of e-mails as well as traffic data may be monitored by NDS for
 employment and security purposes. To protect the environment please do not
 print this e-mail unless necessary.
 
 NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18
 4EX, United Kingdom. A company registered in England and Wales. Registered
 no. 3080780. VAT no. GB 603 8808 40

Re: [rules-users] Can we use 'from' CE in Decision Tables ?

2009-12-03 Thread groovenarula

Hi Thomas,

Just wanted to let you know that the eval soution finally worked. I create a
'containsCode' method on my Line bean and then used that to see if the Line
contained a given code. Then finally used 'eval' to check if the 'code'
exists from within a decision table. 

Got what I needed.

Thanks for the solution. 
Gurvinder


Swindells, Thomas wrote:
 
 Hi Gurvinder.
 
 Not sure where new lines have gone from your email - it makes it very hard
 to read!
 
 I've also been working on a project which uses decision tables and I
 couldn't find any way to use from statements either.  I'm hoping to get
 some time within the project to work on the drools decision table code to
 add some improvements, providing support for the from clause is one of
 these however I'm not sure whether I will get time or not.
 
 However I think you may be able to restructure your code so that you don't
 need the from cause however I've not fully tested it. The code relies on
 their existing a constructor which takes the promotion code and the equals
 is defined that P1.equals(P2) when P1.code.equals(P2.code).
 
 If you wanted to match that a promotion of a particular name exists then I
 think you can use the rule
 Rule existsPromotion  when
 Line(promos contains (new Promotion(HOTBUY))) then ...
 
 However the expression language doesn't support not contains which means
 you have to full back to use java:
 rule  contains d
   when
 line : Line(eval(!line.getPromos().contains(new
 Promotion(HOTBUY
   then
 ...
 end
 
 If you prefer you could also define a method on Line
 containsPromotionWithCode(code) which would let you choose how to do the
 match.
 
 As a spreadsheet the above would then look something like the following:
 RuleTable Hotbuys
 
 
 
 
 
 NAME
 
 CONDITION
 
 ACTION
 
 
 
 l :Line
 
 
 
 
 
 eval(!l.getPromos().contains(new Promotion($param)))
 
 System.out.println($param);
 
 Rule Name
 
 Number Directors
 
 Warning
 
 example1
 
 Hotbuys
 
 Hotbuys missing
 
 
 Hope that helps,
 
 Thomas
 
 
 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of groovenarula
 Sent: 03 December 2009 06:51
 To: rules-users@lists.jboss.org
 Subject: [rules-users] Can we use 'from' CE in Decision Tables ?
 
 Hello all, Is it possible to define the follow rule in a decision table :
 rule Activate Promotion when l : Line( ) not ( Promotion ( code ==
 HOTBUY ) from l.promos ) then #do some action end The rule above works
 perfectly for what I need when defined in a rule file. However, when I try
 to define it in a decision table so that the 'code' can be feed from a
 spreadsheet, I use the following values in the rules cells : RuleTable
 HOTBUYS CONDITION ACTION l : Line not ( Promotion ( code == $param )
 from l.promos ) System.out.println($param added); PROMOTION PROMOTION
 HOTBUY BESTBUY I'm getting the following parser errors [10,17]: [ERR 101]
 Line 10:17 no viable alternative at input 'Promotion' in rule _11 in
 pattern Line [10,29]: [ERR 101] Line 10:29 no viable alternative at input
 'code' in rule _11 [10,63]: [ERR 102] Line 10:63 mismatched input ')'
 expecting 'then' in rule _11 java.lang.IllegalArgumentException: Could
 not parse knowledge. at
 com.sample.DecisionTableTest.readKnowledgeBase(DecisionTableTest.java:85)
 at com.sample.DecisionTableTest.main(DecisionTableTest.java:28) Also in
 Eclipse IDE, I get the following error : Unknown error while parsing.
 This is a bug. Please contact the Development team. NewPromotions.xls Is
 it possible to use 'from' conditional element in decision tables ? If so,
 what am I doing wrong. If not, then what's the best approach to implement
 the rule above in a decision table. I'm running Drools 5.1.0M1 in Eclipse.
 Help truly appreciated. Gurvinder
 
 View this message in context: Can we use 'from' CE in Decision Tables
 ?http://n3.nabble.com/Can-we-use-from-CE-in-Decision-Tables-tp67005p67005.html
 Sent from the Drools - User mailing list
 archivehttp://n3.nabble.com/Drools-User-f47000.html at Nabble.com.
 
 
 
 **
 This message is confidential and intended only for the addressee. If you
 have received this message in error, please immediately notify the
 postmas...@nds.com and delete it from your system as well as any copies.
 The content of e-mails as well as traffic data may be monitored by NDS for
 employment and security purposes. To protect the environment please do not
 print this e-mail unless necessary.
 
 NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18
 4EX, United Kingdom. A company registered in England and Wales. Registered
 no. 3080780. VAT no. GB 603 8808 40-00
 **
 
 
 This message is confidential

[rules-users] Can we use 'from' CE in Decision Tables ?

2009-12-02 Thread groovenarula

Hello all,
Is it possible to define the follow rule in a decision table :

rule Activate Promotion
when
l : Line( )
not ( Promotion ( code == HOTBUY ) from l.promos )
then
   #do some action
end

The rule above works perfectly for what I need when defined in a rule file.
However, when I try to define it in a decision table so that the 'code' can
be feed from a spreadsheet, I use the following values in the rules cells :
  
   RuleTable   
HOTBUYS
   CONDITION   
ACTION
l : Line
not ( Promotion ( code == $param ) from l.promos ) 
System.out.println($param added);
PROMOTION  
PROMOTION
HOTBUY 
BESTBUY

I'm getting the following parser errors 

[10,17]: [ERR 101] Line 10:17 no viable alternative at input 'Promotion' in
rule _11 in pattern Line
[10,29]: [ERR 101] Line 10:29 no viable alternative at input 'code' in rule
_11
[10,63]: [ERR 102] Line 10:63 mismatched input ')' expecting 'then' in rule
_11
java.lang.IllegalArgumentException: Could not parse knowledge.
at
com.sample.DecisionTableTest.readKnowledgeBase(DecisionTableTest.java:85)
at com.sample.DecisionTableTest.main(DecisionTableTest.java:28)

Also in  Eclipse IDE, I get the following error :
Unknown error while parsing. This is a bug. Please contact the Development
team.  NewPromotions.xls

Is it possible to use 'from' conditional element in decision tables ? If so,
what am I doing wrong. If not, then what's the best approach to implement
the rule above in a decision table.

I'm running Drools 5.1.0M1 in Eclipse.

Help truly appreciated.
Gurvinder



-- 
View this message in context: 
http://n3.nabble.com/Can-we-use-from-CE-in-Decision-Tables-tp67005p67005.html
Sent from the Drools - User mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users