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 Edson Tirelli
   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 gnaru...@la-z-boy.com


 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




-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Sliding window of length (1) equals latest event?!

2011-01-29 Thread OlliSee

Hey again everyone, 

I seem to be having another problem. 

When I have a rule like that 

when 
A() over window:length(1) 
B() over window:length(1) 
then 
... 

I imagine now having two windows of length 1. One always keeping the latest
A event and one always keeping the latest B event. And I expect them to
update themselves once a new event comes in. 

But if I have events coming in like this... 

A1, A2, B1 

The rule fires for (A2, B1) 

then another event B2 is coming in and it fires for (A2,B2) 
So far so good. 

Then another event A3 is coming in and the rule fires for (A3,B2) and
(A3,B1). 
Why? Shouldn't the B window only have B2 inside since it arrived and thus
fire only for (A3,B2)? 

I have already been searching for this problem, found this 
http://drools-java-rules-engine.46999.n3.nabble.com/DROOLS-problem-with-sliding-windows-td2039892.html
but I'm not sure if this is the same problem as mine. 

Helping me understand this is highly appreciated, since I thought I had
completely understood the window behaviour. 

Thanks in advance. 
Kind regards 
Oliver
-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Sliding-window-of-length-1-equals-latest-event-tp2370162p2370162.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] Writing a pattern in which each event constraint depends on the previous event

2011-01-29 Thread OlliSee

Hello everyone. 

Lets say we have StockTicks... 
Is it possible to detect a monotonically decreasing StockTick stream over a
window? 

If I knew the number of events I want to check on, I'd do it this way 

$a : StockTick() over window:time(20s) 
$b : StockTick(this after $a, price  $a.price) over window:time(20s) 
... 

But I don't know for how long the StockTick prices continue to decrease.. 
I imagine doing something like that 

$list : List(size  0) from collect(StockTick() over window:time(20s)) 
forall($a : StockTick() from $list 
$b : StockTick(this after $a, price  $a.price from $list 
) 

That results in a nice exception. 
Any idea how to do this work? And more efficiently than my approach? 

Thanks 
Oliver 



Exception in thread Thread-1 java.lang.ClassCastException:
org.drools.common.DefaultFactHandle cannot be cast to
org.drools.common.EventFactHandle
at
org.drools.base.evaluators.AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedLeft(AfterEvaluatorDefinition.java:336)
at
org.drools.rule.VariableRestriction.isAllowedCachedLeft(VariableRestriction.java:110)
at
org.drools.rule.VariableConstraint.isAllowedCachedLeft(VariableConstraint.java:115)
at
org.drools.common.DoubleBetaConstraints.isAllowedCachedLeft(DoubleBetaConstraints.java:166)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:274)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
at
org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:662)
at 
org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:270)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
at 
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
at 
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1187)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1089)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:893)
at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:238)

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Writing-a-pattern-in-which-each-event-constraint-depends-on-the-previous-event-tp2370165p2370165.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] Writing a pattern in which each event constraint depends on the previous event

2011-01-29 Thread Greg Barton
See the current discussion of accumulate functions.  That should satisfy your 
need.

GreG

On Jan 29, 2011, at 10:18, OlliSee o.ro...@seeburger.de wrote:

 
 Hello everyone. 
 
 Lets say we have StockTicks... 
 Is it possible to detect a monotonically decreasing StockTick stream over a
 window? 
 
 If I knew the number of events I want to check on, I'd do it this way 
 
 $a : StockTick() over window:time(20s) 
 $b : StockTick(this after $a, price  $a.price) over window:time(20s) 
 ... 
 
 But I don't know for how long the StockTick prices continue to decrease.. 
 I imagine doing something like that 
 
 $list : List(size  0) from collect(StockTick() over window:time(20s)) 
 forall($a : StockTick() from $list 
$b : StockTick(this after $a, price  $a.price from $list 
 ) 
 
 That results in a nice exception. 
 Any idea how to do this work? And more efficiently than my approach? 
 
 Thanks 
 Oliver 
 
 
 
 Exception in thread Thread-1 java.lang.ClassCastException:
 org.drools.common.DefaultFactHandle cannot be cast to
 org.drools.common.EventFactHandle
at
 org.drools.base.evaluators.AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedLeft(AfterEvaluatorDefinition.java:336)
at
 org.drools.rule.VariableRestriction.isAllowedCachedLeft(VariableRestriction.java:110)
at
 org.drools.rule.VariableConstraint.isAllowedCachedLeft(VariableConstraint.java:115)
at
 org.drools.common.DoubleBetaConstraints.isAllowedCachedLeft(DoubleBetaConstraints.java:166)
at
 org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:274)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
at
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
at
 org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
at
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
at
 org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:662)
at org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:270)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
at
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
at
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1187)
at
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1089)
at
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:893)
at
 org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:238)
 
 -- 
 View this message in context: 
 http://drools-java-rules-engine.46999.n3.nabble.com/Writing-a-pattern-in-which-each-event-constraint-depends-on-the-previous-event-tp2370165p2370165.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 mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Writing a pattern in which each event constraint depends on the previous event

2011-01-29 Thread Wolfgang Laun
Is there a *defined *order in which objects resulting from an over clause
are presented to the preceding from? Otherwise, an accumulate function
requiring a specific order is based on implementation details.
-W

On 29 January 2011 18:24, Greg Barton greg_bar...@yahoo.com wrote:

 See the current discussion of accumulate functions.  That should satisfy
 your need.

 GreG

 On Jan 29, 2011, at 10:18, OlliSee o.ro...@seeburger.de wrote:

 
  Hello everyone.
 
  Lets say we have StockTicks...
  Is it possible to detect a monotonically decreasing StockTick stream over
 a
  window?
 
  If I knew the number of events I want to check on, I'd do it this way
 
  $a : StockTick() over window:time(20s)
  $b : StockTick(this after $a, price  $a.price) over window:time(20s)
  ...
 
  But I don't know for how long the StockTick prices continue to decrease..
  I imagine doing something like that
 
  $list : List(size  0) from collect(StockTick() over window:time(20s))
  forall($a : StockTick() from $list
 $b : StockTick(this after $a, price  $a.price from $list
  )
 
  That results in a nice exception.
  Any idea how to do this work? And more efficiently than my approach?
 
  Thanks
  Oliver
 
 
 
  Exception in thread Thread-1 java.lang.ClassCastException:
  org.drools.common.DefaultFactHandle cannot be cast to
  org.drools.common.EventFactHandle
 at
 
 org.drools.base.evaluators.AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedLeft(AfterEvaluatorDefinition.java:336)
 at
 
 org.drools.rule.VariableRestriction.isAllowedCachedLeft(VariableRestriction.java:110)
 at
 
 org.drools.rule.VariableConstraint.isAllowedCachedLeft(VariableConstraint.java:115)
 at
 
 org.drools.common.DoubleBetaConstraints.isAllowedCachedLeft(DoubleBetaConstraints.java:166)
 at
 
 org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:274)
 at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
 at
 
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
 at
 
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
 at
 
 org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)
 at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
 at
 
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:220)
 at
 
 org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:81)
 at
 
 org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:662)
 at
 org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:270)
 at
 
 org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
 at
 
 org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
 at
 org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
 at
 org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
 at
 
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1187)
 at
 
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1089)
 at
 
 org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:893)
 at
 
 org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:238)
 
  --
  View this message in context:
 http://drools-java-rules-engine.46999.n3.nabble.com/Writing-a-pattern-in-which-each-event-constraint-depends-on-the-previous-event-tp2370165p2370165.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 mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
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] Writing a pattern in which each event constraint depends on the previous event

2011-01-29 Thread radai.rosenblatt

how about numbering your ticks ?
as a rough outline, this might look something like:

1st : Tick ($number : num)
2nd : Tick (num == $number+1, {this.value below 1st.value})
3rd : Tick (num == $number+2, {this.value above 2nd.value})

this should find all bottoms

-- 
View this message in context: 
http://drools-java-rules-engine.46999.n3.nabble.com/Writing-a-pattern-in-which-each-event-constraint-depends-on-the-previous-event-tp2370165p2382430.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