Setting a value in LHS
by stephen.masters
Hi folks,
Is there a decent way to set a value in the LHS of a rule so that it's available in the RHS?
Reason being I have a DSL driving the guided rules editor which will pluck out the value of a field, where the name of that field is driven by a drop down menu enumeration.
A change I now have would be a lot easier if I could assign a string to a variable in the LHS, which could be read by the RHS. Otherwise I might need to extend the RHS DSLs to include the same enumeration as the LHS. Which looks a bit redundant for a business user wondering why the need to write the same thing twice.
Any thoughts?
Steve
Sent from Samsung Mobile
11 years, 6 months
Separate selectable drl files in drools kbase.. Or agenda groups
by Ramon Buckland
Hi,
I am using a Stateless Knowledge session backed behind a web rest api.
The rest api is provided by spring Mvc, so I have a stateless ksession
injected in.
As it is stateless, I have found it difficult to use agenda groups to
meet my need. And have a question to how I set this up.
My task.
In short, I have 10 or so set up rules (init rules), then a 300 odd
(work) rules, then I need to fire a few (5) (finalisation) rules.
They need to be processed in that order. If I were using stateful I
see how an agenda group solves that need.. In the calling java that is
nice. setFocus().. But stateless blocks that api.
So I have attempted with auto-focus..
In the DRL (from XLS) however getting the agenda group settings right
has been a small 'mare. Suffice to say I haven't got it working.
My options:
1. get agenda groups working.
2. split the three groups into 3 DRL files. and execute in sequence
each one using a different ksession for each.
--- on 1.
How would I construct the flow.. .. Do I use three separate auto focus
rules , one for each a.group and set a salience ( I don think
salience helps here ) ? How do I guarantee to stack the focus using
auto-focus to follow my ordering?
-- on 2.
Can I create a separate ksession for each DRL file (injecting them in
from spring).
--
Thoughts ? Am I solving right ?
Many thanks. Ramon
11 years, 6 months
Unsubscribe
by Deepak Gmail
On 4 Jun 2013, at 17:00, rules-users-request(a)lists.jboss.org wrote:
> Send rules-users mailing list submissions to
> rules-users(a)lists.jboss.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.jboss.org/mailman/listinfo/rules-users
> or, via email, send a message with subject or body 'help' to
> rules-users-request(a)lists.jboss.org
>
> You can reach the person managing the list at
> rules-users-owner(a)lists.jboss.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of rules-users digest..."
>
>
> Today's Topics:
>
> 1. ClassCastException due to binding (bdolbeare)
> 2. Re: Setting a value in LHS (Michael Anstis)
> 3. Re: ClassCastException due to binding (Davide Sottara)
> 4. Re: Setting a value in LHS (Stephen Masters)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 4 Jun 2013 08:12:09 -0700 (PDT)
> From: bdolbeare <bdolbeare(a)yahoo.com>
> Subject: [rules-users] ClassCastException due to binding
> To: rules-users(a)lists.jboss.org
> Message-ID: <1370358729183-4024115.post(a)n3.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
> We have a need to support binds for conditional or elements so that we can
> describe why a rule fired in the then clause of a rule. The following DRL
> is a simple example of what we are trying to do. There are two versions of
> our rule in the DRL:
>
> *rule "WORKING: find with or"*: works but only because the first variable
> we try to bind in the or expression is of type "target" which is a super
> class of the other elements in the or expression.
>
> *rule "BROKEN: find with or"*: causes a class cast exception when the
> "bar" pattern is matched because the then clause tries to store the bar
> object in handle "x" which it thinks is of type "foo".
>
> Is there a way to define the object type for the bind variable?
>
> Is there any other way to make something like this work?
>
>
>
> package tests
>
> import org.apache.log4j.Logger;
>
> global Logger log
>
> declare target
> notreal : boolean
> end
>
> declare foo extends target
> foovalue : String
> end
>
> declare bar extends target
> barvalue : String
> end
>
> rule "insertdata"
> when
> then
> insert(new foo(false, "a"));
> insert(new bar(false, "b"));
> end
>
> rule "WORKING: find with or"
> when
> ( or x: target(notreal)
> x: foo(foovalue == "a")
> x: bar(barvalue == "b")
> )
> then
> log.info("i found object: " + x);
> end
>
> rule "BROKEN: find with or"
> when
> ( or
> x: foo(foovalue == "a")
> x: bar(barvalue == "b")
> )
> then
> log.info("i found object: " + x);
> end
>
>
>
> Exception executing consequence for rule "find with or" in tests:
> java.lang.ClassCastException: tests.bar cannot be cast to tests.foo
> 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
> org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:278)
> at tests.DroolsTest.testStateless(DroolsTest.java:120)
> at tests.DroolsTest.runTest(DroolsTest.java:74)
> at tests.DroolsTest.main(DroolsTest.java:59)
> Caused by: java.lang.ClassCastException: tests.bar cannot be cast to
> tests.foo
> at
> tests.Rule_find_with_or_411ee1c99de54340945b2b707ad0a576DefaultConsequenceInvoker.evaluate(Unknown
> Source)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273)
> ... 9 more
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/ClassCastException-due-to-binding-tp402...
> Sent from the Drools: User forum mailing list archive at Nabble.com.
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 4 Jun 2013 16:33:11 +0100
> From: Michael Anstis <michael.anstis(a)gmail.com>
> Subject: Re: [rules-users] Setting a value in LHS
> To: "stephen.masters" <stephen.masters(a)me.com>, Rules Users List
> <rules-users(a)lists.jboss.org>
> Message-ID:
> <CAAG9P0uZO_-sskN_1V1uQFXzWuAxCosx=v+i+SVfZ0VHysQKjQ(a)mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> This would need to be provided by the tooling; I don't think it's something
> that's even remotely possible at runtime (unless you stored the field name
> in a Fact and used reflection on the RHS).
>
> That said (and you're going to guess my next comment) this is not provided
> in the guided editors. Depending on how complex your DSLs are and whether
> users need to combine DSL Sentences; IDK if a "cheat" works:
>
> [when]Do something with {field} and {value}=$f : Fact({field}=={value} then
> $f.{field} = {value}
>
> I've not tried it; nor know whether it fits your requirements.. but a hack
> worth trying?
>
>
> On 3 June 2013 17:40, stephen.masters <stephen.masters(a)me.com> wrote:
>
>> Hi folks,
>>
>> Is there a decent way to set a value in the LHS of a rule so that it's
>> available in the RHS?
>>
>> Reason being I have a DSL driving the guided rules editor which will pluck
>> out the value of a field, where the name of that field is driven by a drop
>> down menu enumeration.
>>
>> A change I now have would be a lot easier if I could assign a string to a
>> variable in the LHS, which could be read by the RHS. Otherwise I might need
>> to extend the RHS DSLs to include the same enumeration as the LHS. Which
>> looks a bit redundant for a business user wondering why the need to write
>> the same thing twice.
>>
>> Any thoughts?
>>
>> Steve
>>
>>
>>
>>
>> Sent from Samsung Mobile
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
11 years, 6 months
ClassCastException due to binding
by bdolbeare
We have a need to support binds for conditional or elements so that we can
describe why a rule fired in the then clause of a rule. The following DRL
is a simple example of what we are trying to do. There are two versions of
our rule in the DRL:
*rule "WORKING: find with or"*: works but only because the first variable
we try to bind in the or expression is of type "target" which is a super
class of the other elements in the or expression.
*rule "BROKEN: find with or"*: causes a class cast exception when the
"bar" pattern is matched because the then clause tries to store the bar
object in handle "x" which it thinks is of type "foo".
Is there a way to define the object type for the bind variable?
Is there any other way to make something like this work?
package tests
import org.apache.log4j.Logger;
global Logger log
declare target
notreal : boolean
end
declare foo extends target
foovalue : String
end
declare bar extends target
barvalue : String
end
rule "insertdata"
when
then
insert(new foo(false, "a"));
insert(new bar(false, "b"));
end
rule "WORKING: find with or"
when
( or x: target(notreal)
x: foo(foovalue == "a")
x: bar(barvalue == "b")
)
then
log.info("i found object: " + x);
end
rule "BROKEN: find with or"
when
( or
x: foo(foovalue == "a")
x: bar(barvalue == "b")
)
then
log.info("i found object: " + x);
end
Exception executing consequence for rule "find with or" in tests:
java.lang.ClassCastException: tests.bar cannot be cast to tests.foo
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
org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:278)
at tests.DroolsTest.testStateless(DroolsTest.java:120)
at tests.DroolsTest.runTest(DroolsTest.java:74)
at tests.DroolsTest.main(DroolsTest.java:59)
Caused by: java.lang.ClassCastException: tests.bar cannot be cast to
tests.foo
at
tests.Rule_find_with_or_411ee1c99de54340945b2b707ad0a576DefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273)
... 9 more
--
View this message in context: http://drools.46999.n3.nabble.com/ClassCastException-due-to-binding-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
Re: [rules-users] StatefulKnowledgeSession and multi-threaded processing
by pprasad
Thanks for your prompt reply. I am working on a fraud system for a bank and they have around 3 millions records.
All my data is loaded to redis and I can access the key using jedis. How do I insert redis hashmap to fact in one go. I do not want to iterate for every key and insert fact individually.
Is there a way to get the instance of redis hashmap in java and insert that hashmap as a fact.
Thanks and Regards
Pradeep Prasad
Date: Sun, 2 Jun 2013 22:08:32 -0700
From: ml-node+s46999n4024076h45(a)n3.nabble.com
To: pradeep_prasad(a)hotmail.com
Subject: Re: [rules-users] StatefulKnowledgeSession and multi-threaded processing
You can do it as per my knowledge. Only thing is you will access in drl from java code. I dont think it will be an issue. but what the reason for sending hashmap as fact, You should have a different way of sending facts. As per my observation no rule needs so much of data to make a decision. It should have name value parameters to make the decision.
Hope this helps.
thankskamal.
On Sun, Jun 2, 2013 at 9:59 PM, pprasad [via Drools] <[hidden email]> wrote:
Hi,
Is it possible to insert redis hashmap as it is as fact into rule engine. I am using Jedis from java to access jedis and drool rule engine.
Also, Is there a way to access redis hashmap from drl file.
Thanks,
Pradeep
If you reply to this email, your message will be added to the discussion below:
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-and-multi-thre...
To unsubscribe from StatefulKnowledgeSession and multi-threaded processing, click here.
NAML
If you reply to this email, your message will be added to the discussion below:
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-and-multi-thre...
To unsubscribe from StatefulKnowledgeSession and multi-threaded processing, click here.
NAML
--
View this message in context: http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-and-multi-thre...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
Lazy Planning Value Validation
by jonathan.labin
I am using Optaplanner 6.0.0.beta2.
Like most domains, I am working where it is possible that a given planning
value is invalid to assign to some planning entities. However, it is
impractical to perform a thorough validity check against every combination
in order to a Value Range list containing only valid assignments.
I could simply create a Hard Constraint rule to test for these invalid
assignments but I fear the validity check may even too computationally
expensive for this (i.e. run for each potential step during step selection).
Also, this does not prevent the Optaplanner from considering this assignment
in the future in a slightly different context.
Instead, what I'd prefer is to only check the validity of an assignment
after it is used as part of a solution which improved the score. That way
it is never called for any of the huge space of possible assignments that
won't ever be part of a final solution anyway.
If the assignment turns out to be invalid in this check, I'd like to remove
it from the Value Range so it is never considered again.
Is there a way to have the Optaplanner behave this way?
Which components should I investigate implementing (a forager)?
How does the Optaplanner respond to run-time changes? Once, discovered, can
I simply remove the invalid planning value from the value range for the
planning entity?
Thanks,
Jon
--
View this message in context: http://drools.46999.n3.nabble.com/Lazy-Planning-Value-Validation-tp402409...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
filtering object having max value
by mohan
Hi folks,
I want to filter object instance in WM when max value of an object field
(rental ) is less than X (reloadValue) . X will vary over time.
I tried to use below query but I couldn't get expected results. Could anyone
please help me?
Thanks.
--------------------------------------------
rule "Insuf-Balance-Reload Alert"
dialect "java"
when
$re : ReloadEvent($rechargeNum : rechargedNumber,$reloadVal :
reloadValue ) from entry-point "RELOAD-EVENT"
InsufBalFailFact(mobileNo == $rechargeNum,$reloadVal > rental, $pkgId :
pkgId,$rental : rental)
not InsufBalFailFact(mobileNo == $rechargeNum, rental > $rental)
then
System.out.println($rechargeNum+","+$pkgId +","+$rental);
end
--
View this message in context: http://drools.46999.n3.nabble.com/filtering-object-having-max-value-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months