Re: [rules-users] Rules Effective Date

2009-05-27 Thread Nicolas Héron
Hello,
look at documentation point on
datehttps://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/drools-expert/html_single/index.html#d0e3705on
rules attributes
*date-effective and date-expires
regards
Nicolas Heron
*
2009/5/27 Srinivas Doddi srinivas_do...@gap.com

  Hi

 I am a newbie for Drools and googled for a good time.  I would like to
 know if Drools 4.0.7 and Drools 5 have anything like an “Effective Date”
 concept? We have a requirement for having a rule written by the Business
 Analysts and takes effective for a future date, without restarting the
 application. Is Rules Engine intelligent enough to pick the rules
 depending on effective dates?

 Thanks a lot for your help.

 ***SRINI*


 ___
 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] moving average rule

2009-05-27 Thread Edson Tirelli
 There are 2 important concepts related to time windows. First and most
important, sliding windows only work in STREAM_MODE, not in CLOUD_MODE
(default). Did you set the engine to STREAM_MODE?
 Second, the session clock becomes really important in STREAM_MODE: what
clock are you using? Real time or pseudo clock?

 []s
 Edson

2009/5/26 Chris Richmond crichm...@referentia.com

  Well, it never fires even though the last several values are ALL above my
 moving averate limit…I never see the output being written out.  I modified
 my limit value to something very very low to ensure the average was beyond
 that, but still nothing.



 I understand what you are saying about Expert+Fusion and that was my
 understanding as well and I have been reading through the docs on that
 links, however I have not read all of the documentation exhaustively yet.
 There doesn’t seem to be a lot of samples(syntax wise) for authoring rules
 taking advantage of those Fusion features.  There are isolated one or two
 line samples, but I guess I am having a difficult time determining how to
 author rules based on collections of data…think of sensor data over time….so
 I want to author rules that work on the latest readings plus some
 configurable amount of readings in the past.  From the Fusion features
 description, it seems ideal….but finding out the nuts and bolts of
 implementing it is eluding me thus far.



 I am continuing the reading as well..perhaps I have not come across it
 yet..



 Thanks again for your help.



 Chris






  --

 *From:* rules-users-boun...@lists.jboss.org [mailto:
 rules-users-boun...@lists.jboss.org] *On Behalf Of *Edson Tirelli
 *Sent:* Tuesday, May 26, 2009 4:24 PM
 *To:* Rules Users List
 *Subject:* Re: [rules-users] moving average rule




Chris,

Fusion is an extension of Drools Expert. Think about it as all Expert
 features + some additional features. That is why Drools Fusion docs is just
 a list of features explained.

I assume you looked here already:

 http://www.jboss.org/drools/documentation.html

For both, expert and fusion docs.

So, back to your rule, syntax seems correct to me. Why do you say it is
 not working? What error or symptoms do you see?

[]s
Edson

 2009/5/26 Chris Richmond crichm...@referentia.com

 Hello,



 I am trying to write a rule for a moving average over values over the last
 minute using fusion.  In general I can’t seem to locate a detailed resource
 for authoring syntax for these types of rules or rules in general, but
 specifically, I tried to modify something from the fusion documentation for
 my purposes using the StockTicker fusion sample.  Here is the rule entry I
 aded to the broker.drl:



 *rule* Alert when moving average goes below 50

 *when*

 Number( doubleValue  127 ) *from* *accumulate*(

 StockTick( symbol == ORCL, $price: price ) over window:time( 1m
 ),

 average( $price ) )

 *then*

 System.out.println(moving average has gone beyone moving average);

 *End*

 * *

 I basically want to be alerted any time the moving average for ORCL moves
 above 127 (or whatever criteria I set…I picked that based on the sample data
 the sample fusion project uses), but it doesn’t seem to be working.



 I guess if I could locate the definitave samples or guide for authoring
 these types of rules I could use that, but it’s very difficult to piece
 together how to author rules utilizing fusion features based on isolated
 snippets from the fusion guide.



 Can anyone point me to some reasources for learning rule authoring,
 especially for taking advantage of the fusion features.



 Thanks,


 Chris


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




 --
  Edson Tirelli
  JBoss Drools Core Development
  JBoss, a division of Red Hat @ www.jboss.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, a division of Red Hat @ www.jboss.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Rules Effective Date

2009-05-27 Thread Ingold, Jonathan
Hi Srinivas,
  I would look at the newly released 5.01 GA, specifically at the
documentation for Fusion, which focuses on event processing. 
 

| Jonathan Ingold |

 



From: Srinivas Doddi [mailto:srinivas_do...@gap.com] 
Sent: Tuesday, May 26, 2009 11:41 PM
To: rules-users@lists.jboss.org
Subject: [rules-users] Rules Effective Date



Hi

I am a newbie for Drools and googled for a good time.  I would like to
know if Drools 4.0.7 and Drools 5 have anything like an Effective Date
concept? We have a requirement for having a rule written by the Business
Analysts and takes effective for a future date, without restarting the
application. Is Rules Engine intelligent enough to pick the rules
depending on effective dates?

Thanks a lot for your help.

SRINI


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


[rules-users] Rules Effective Date

2009-05-27 Thread Srinivas Doddi
Hi Nicoloas

Thank you for pointing it out.  I went through it previously, but
somehow missed that point.  


Hi Jonathan

I went through Fusion, but couldn't relate how the Events can be related
to the Rules effective dates.


And adding to my initial query, 

So, can we modify the attribute date expires for an existing rule when
the application is running, and the rules engine knows about it and
expires the rule, without restarting the application? I am talking about
4.0.7 in particular?

Also, I see that Rule names should be unique,  so does it mean that we
can't have 2 rules with same name and different effective date ranges?

Sorry for asking these without trying, we are still in the process of
brain storming, and need to know what Rules has to offer.  I am still in
the process of setting up Rules on my pc.


Thank you.

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


[rules-users] keeping running stats

2009-05-27 Thread Chris Richmond
Hello,

 

I have modified the stockTicker fusion example to keep some running stats,
you can see from the rule snippet below that it injects a stats object based
on the symbol then matches them as updates come in later.  You can see for
now I am just updating the running counts and outputting the readings count
on each stock tick and this works fine.

 

What I would like to do however is only have the running averages,stats
object reflect stock ticks that are still in memory..essentiall only stock
tick items that have not expired.  As it is now the count just keeps growing
and growing, I want the count to only reflect the stock ticks within the
expiration time in the past for stock ticks, but I cannot figure out how to
make this happen?Could anyone give me a pointer on how to do this?  How
to make the stats object only reflect those stock ticks that have not
expired?  I do not know the strategy for this.

 

Thanks,

Chris

 

# tells the engine that a StockTick instance will assume the

# role (semantics) of events and that the default retention 

# policy will be 2 minutes 

declare StockTick

@role( event )

@expires( 1m )

end 

 

# One can even declare helper facts to make rules easier and

# simpler to write and maintain

declare Statistics

symbol : String @key()

average : double

readings : int

total : double

end

 

rule Setup statistics

when

   $c : Company( $s : symbol )

   not( Statistics( symbol == $s ) )

then

   Statistics s = new Statistics();

   s.symbol = $s;

   s.readings = s.readings + 1;

   insert( s );

 

end

 

 

 

# a simple rule to show that it is possible to join

# events from an entry-point (stream) with facts 

# present in the working memory

rule Update stock stats

agenda-group evaluation

lock-on-active

when

  

$cp : Company( $sb : symbol )

$st : StockTick( symbol == $sb, $pr : price ) from entry-point
StockTick stream

 

  $stats : Statistics( symbol == $sb  )

 

then

 

  modify( $stats ) { readings = readings + 1};

  System.err.println($stats.symbol + readings:  + $stats.readings);

// This shows an update on working memory facts with data from joined
events

//modify( $cp ) { currentPrice = $pr }



// Although events are considered immutable, a common pattern is to use
a class

// to represent an event and enrich that event instance with data
derived from other facts/events.

// Bellow we enrich the event instance with the percentual change in
the price, 

// based on the previous price

//modify( $st ) { delta = $cp.delta }

//modify( $st ) { readings = 5 }

//System.out.println($st.delta)

end

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


RE: [rules-users] moving average rule

2009-05-27 Thread Chris Richmond
Well I am only modifying the StockTicker example which I believe is using
Stream mode and  and system time.

 

  _  

From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Wednesday, May 27, 2009 2:22 AM
To: Rules Users List
Subject: Re: [rules-users] moving average rule

 


 There are 2 important concepts related to time windows. First and most
important, sliding windows only work in STREAM_MODE, not in CLOUD_MODE
(default). Did you set the engine to STREAM_MODE?
 Second, the session clock becomes really important in STREAM_MODE: what
clock are you using? Real time or pseudo clock?

 []s
 Edson

2009/5/26 Chris Richmond crichm...@referentia.com

Well, it never fires even though the last several values are ALL above my
moving averate limit.I never see the output being written out.  I modified
my limit value to something very very low to ensure the average was beyond
that, but still nothing.   

 

I understand what you are saying about Expert+Fusion and that was my
understanding as well and I have been reading through the docs on that
links, however I have not read all of the documentation exhaustively yet.
There doesn't seem to be a lot of samples(syntax wise) for authoring rules
taking advantage of those Fusion features.  There are isolated one or two
line samples, but I guess I am having a difficult time determining how to
author rules based on collections of data.think of sensor data over time..so
I want to author rules that work on the latest readings plus some
configurable amount of readings in the past.  From the Fusion features
description, it seems ideal..but finding out the nuts and bolts of
implementing it is eluding me thus far.  

 

I am continuing the reading as well..perhaps I have not come across it yet..

 

Thanks again for your help.

 

Chris  

 

 

 

  _  

From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Tuesday, May 26, 2009 4:24 PM
To: Rules Users List
Subject: Re: [rules-users] moving average rule

 


   Chris,

   Fusion is an extension of Drools Expert. Think about it as all Expert
features + some additional features. That is why Drools Fusion docs is just
a list of features explained.

   I assume you looked here already:

http://www.jboss.org/drools/documentation.html

   For both, expert and fusion docs.

   So, back to your rule, syntax seems correct to me. Why do you say it is
not working? What error or symptoms do you see?

   []s
   Edson

2009/5/26 Chris Richmond crichm...@referentia.com

Hello,

 

I am trying to write a rule for a moving average over values over the last
minute using fusion.  In general I can't seem to locate a detailed resource
for authoring syntax for these types of rules or rules in general, but
specifically, I tried to modify something from the fusion documentation for
my purposes using the StockTicker fusion sample.  Here is the rule entry I
aded to the broker.drl:

 

rule Alert when moving average goes below 50

when

Number( doubleValue  127 ) from accumulate(

StockTick( symbol == ORCL, $price: price ) over window:time( 1m ),

average( $price ) )

then

System.out.println(moving average has gone beyone moving average);

End

 

I basically want to be alerted any time the moving average for ORCL moves
above 127 (or whatever criteria I set.I picked that based on the sample data
the sample fusion project uses), but it doesn't seem to be working.  

 

I guess if I could locate the definitave samples or guide for authoring
these types of rules I could use that, but it's very difficult to piece
together how to author rules utilizing fusion features based on isolated
snippets from the fusion guide.

 

Can anyone point me to some reasources for learning rule authoring,
especially for taking advantage of the fusion features.

 

Thanks,


Chris


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




-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.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, a division of Red Hat @ www.jboss.com

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


Re[rules-users] sult Lists from Decision Tables

2009-05-27 Thread wasabifan

I have worked directly with DRLs previously, but my new company would like to
store their rules in decision tables.

Basically, in the past, we would insert a custom object to maintain a list
of results from the rules, which was pretty easy to do in a DRL.  However,
in decision tables, I have not found a good way to create a named parameter
for that controlled list without making up a bogus condition (that really
doesn't matter).

Is there an easy way to pass an object to really only be used in the actions
columns?

Thanks,
Bryan
-- 
View this message in context: 
http://www.nabble.com/Result-Lists-from-Decision-Tables-tp23749077p23749077.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] keeping running stats

2009-05-27 Thread Michal Bali
Hi Chris,

You can use 'accumulate' with sliding time window. Have a look here
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/ch02.html#d0e1169

rule Sound the alarm in case temperature rises above threshold
when
TemperatureThreshold( $max : max )
Number( doubleValue  $max ) from accumulate(
SensorReading( $temp : temperature ) over window:time( 10m ),
average( $temp ) )
then
// sound the alarm
end

The engine will automatically discard any SensorReading older than 10
minutes and keep the calculated average consistent.

Is that what you're looking for?

Michal


2009/5/27 Chris Richmond crichm...@referentia.com

  Hello,



 I have modified the stockTicker fusion example to keep some running stats,
 you can see from the rule snippet below that it injects a stats object based
 on the symbol then matches them as updates come in later.  You can see for
 now I am just updating the running counts and outputting the readings count
 on each stock tick and this works fine.



 What I would like to do however is only have the running averages,stats
 object reflect stock ticks that are still in memory….essentiall only stock
 tick items that have not expired.  As it is now the count just keeps growing
 and growing, I want the count to only reflect the stock ticks within the
 expiration time in the past for stock ticks, but I cannot figure out how to
 make this happen?Could anyone give me a pointer on how to do this?  How
 to make the stats object only reflect those stock ticks that have not
 expired?  I do not know the strategy for this.



 Thanks,

 Chris



 # tells the engine that a StockTick instance will assume the

 # role (semantics) of events and that the default retention

 # policy will be 2 minutes

 *declare* StockTick

 @role( event )

 @expires( 1m )

 *end*



 # One can even declare helper facts to make rules easier and

 # simpler to write and maintain

 *declare* Statistics

 symbol : String @key()

 average : *double*

 readings : *int*

 total : *double*

 *end*



 *rule* Setup statistics

 *when*

$c : Company( $s : symbol )

*not*( Statistics( symbol == $s ) )

 *then*

Statistics s = *new* Statistics();

s.symbol = $s;

s.readings = s.readings + 1;

*insert*( s );



 *end*







 # a simple rule to show that it is possible to join

 # events from an entry-point (stream) with facts

 # present in the working memory

 *rule* Update stock stats

 *agenda-group* evaluation

 *lock-on-active*

 *when*



 $cp : Company( $sb : symbol )

 $st : StockTick( symbol == $sb, $pr : price ) *from* entry-point 
 StockTick
 stream



   $stats : Statistics( symbol == $sb  )



 *then*



   *modify*( $stats ) { readings = readings + 1};

   System.err.println($stats.symbol + readings:  + $stats.readings);

 // This shows an update on working memory facts with data from joined
 events

 //modify( $cp ) { currentPrice = $pr }



 // Although events are considered immutable, a common pattern is to
 use a class

 // to represent an event and enrich that event instance with data
 derived from other facts/events.

 // Bellow we enrich the event instance with the percentual change in
 the price,

 // based on the previous price

 //modify( $st ) { delta = $cp.delta }

 //modify( $st ) { readings = 5 }

 //System.out.println($st.delta)

 *end*

 ___
 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: Re[rules-users] sult Lists from Decision Tables

2009-05-27 Thread Michal Bali
Hi Bryan,

Can you use globals for this ?

Regards,
Michal


On Wed, May 27, 2009 at 9:21 PM, wasabifan
bryan.rick...@libertymutual.comwrote:


 I have worked directly with DRLs previously, but my new company would like
 to
 store their rules in decision tables.

 Basically, in the past, we would insert a custom object to maintain a list
 of results from the rules, which was pretty easy to do in a DRL.  However,
 in decision tables, I have not found a good way to create a named parameter
 for that controlled list without making up a bogus condition (that really
 doesn't matter).

 Is there an easy way to pass an object to really only be used in the
 actions
 columns?

 Thanks,
 Bryan
 --
 View this message in context:
 http://www.nabble.com/Result-Lists-from-Decision-Tables-tp23749077p23749077.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] keeping running stats

2009-05-27 Thread Chris Richmond
Yes.tha's what I'm looking for and as a matter of fact I tried to implement
that rule into the stocktick example thusly.I want to see the average over
the last 5m..but this rule NEVER fires and I don't know why

 

rule identify when the average is over a value

when

 

Number( doubleValue  1.0 ) from accumulate(

StockTick( $pr : price, symbol == IBM ) over window:time( 5m ),

average( $pr ) )

then

System.out.println(average over 105);

end

 

  _  

From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Michal Bali
Sent: Wednesday, May 27, 2009 11:09 AM
To: Rules Users List
Subject: Re: [rules-users] keeping running stats

 

Hi Chris,

You can use 'accumulate' with sliding time window. Have a look here
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/
ch02.html#d0e1169

rule Sound the alarm in case temperature rises above threshold


when


TemperatureThreshold( $max : max )


Number( doubleValue  $max ) from accumulate(






SensorReading( $temp : temperature ) over window:time( 10m ),


average( $temp ) )


then


// sound the alarm


end

The engine will automatically discard any SensorReading older than 10
minutes and keep the calculated average consistent.

Is that what you're looking for?

Michal



2009/5/27 Chris Richmond crichm...@referentia.com

Hello,

 

I have modified the stockTicker fusion example to keep some running stats,
you can see from the rule snippet below that it injects a stats object based
on the symbol then matches them as updates come in later.  You can see for
now I am just updating the running counts and outputting the readings count
on each stock tick and this works fine.

 

What I would like to do however is only have the running averages,stats
object reflect stock ticks that are still in memory..essentiall only stock
tick items that have not expired.  As it is now the count just keeps growing
and growing, I want the count to only reflect the stock ticks within the
expiration time in the past for stock ticks, but I cannot figure out how to
make this happen?Could anyone give me a pointer on how to do this?  How
to make the stats object only reflect those stock ticks that have not
expired?  I do not know the strategy for this.

 

Thanks,

Chris

 

# tells the engine that a StockTick instance will assume the

# role (semantics) of events and that the default retention 

# policy will be 2 minutes 

declare StockTick

@role( event )

@expires( 1m )

end 

 

# One can even declare helper facts to make rules easier and

# simpler to write and maintain

declare Statistics

symbol : String @key()

average : double

readings : int

total : double

end

 

rule Setup statistics

when

   $c : Company( $s : symbol )

   not( Statistics( symbol == $s ) )

then

   Statistics s = new Statistics();

   s.symbol = $s;

   s.readings = s.readings + 1;

   insert( s );

 

end

 

 

 

# a simple rule to show that it is possible to join

# events from an entry-point (stream) with facts 

# present in the working memory

rule Update stock stats

agenda-group evaluation

lock-on-active

when

  

$cp : Company( $sb : symbol )

$st : StockTick( symbol == $sb, $pr : price ) from entry-point
StockTick stream

 

  $stats : Statistics( symbol == $sb  )

 

then

 

  modify( $stats ) { readings = readings + 1};

  System.err.println($stats.symbol + readings:  + $stats.readings);

// This shows an update on working memory facts with data from joined
events

//modify( $cp ) { currentPrice = $pr }



// Although events are considered immutable, a common pattern is to use
a class

// to represent an event and enrich that event instance with data
derived from other facts/events.

// Bellow we enrich the event instance with the percentual change in
the price, 

// based on the previous price

//modify( $st ) { delta = $cp.delta }

//modify( $st ) { readings = 5 }

//System.out.println($st.delta)

end


___
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] keeping running stats

2009-05-27 Thread Chris Richmond
Notice I set the average to something very low that I know would be
exceeded.

 

  _  

From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Michal Bali
Sent: Wednesday, May 27, 2009 11:09 AM
To: Rules Users List
Subject: Re: [rules-users] keeping running stats

 

Hi Chris,

You can use 'accumulate' with sliding time window. Have a look here
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/
ch02.html#d0e1169

rule Sound the alarm in case temperature rises above threshold


when


TemperatureThreshold( $max : max )


Number( doubleValue  $max ) from accumulate(






SensorReading( $temp : temperature ) over window:time( 10m ),


average( $temp ) )


then


// sound the alarm


end

The engine will automatically discard any SensorReading older than 10
minutes and keep the calculated average consistent.

Is that what you're looking for?

Michal



2009/5/27 Chris Richmond crichm...@referentia.com

Hello,

 

I have modified the stockTicker fusion example to keep some running stats,
you can see from the rule snippet below that it injects a stats object based
on the symbol then matches them as updates come in later.  You can see for
now I am just updating the running counts and outputting the readings count
on each stock tick and this works fine.

 

What I would like to do however is only have the running averages,stats
object reflect stock ticks that are still in memory..essentiall only stock
tick items that have not expired.  As it is now the count just keeps growing
and growing, I want the count to only reflect the stock ticks within the
expiration time in the past for stock ticks, but I cannot figure out how to
make this happen?Could anyone give me a pointer on how to do this?  How
to make the stats object only reflect those stock ticks that have not
expired?  I do not know the strategy for this.

 

Thanks,

Chris

 

# tells the engine that a StockTick instance will assume the

# role (semantics) of events and that the default retention 

# policy will be 2 minutes 

declare StockTick

@role( event )

@expires( 1m )

end 

 

# One can even declare helper facts to make rules easier and

# simpler to write and maintain

declare Statistics

symbol : String @key()

average : double

readings : int

total : double

end

 

rule Setup statistics

when

   $c : Company( $s : symbol )

   not( Statistics( symbol == $s ) )

then

   Statistics s = new Statistics();

   s.symbol = $s;

   s.readings = s.readings + 1;

   insert( s );

 

end

 

 

 

# a simple rule to show that it is possible to join

# events from an entry-point (stream) with facts 

# present in the working memory

rule Update stock stats

agenda-group evaluation

lock-on-active

when

  

$cp : Company( $sb : symbol )

$st : StockTick( symbol == $sb, $pr : price ) from entry-point
StockTick stream

 

  $stats : Statistics( symbol == $sb  )

 

then

 

  modify( $stats ) { readings = readings + 1};

  System.err.println($stats.symbol + readings:  + $stats.readings);

// This shows an update on working memory facts with data from joined
events

//modify( $cp ) { currentPrice = $pr }



// Although events are considered immutable, a common pattern is to use
a class

// to represent an event and enrich that event instance with data
derived from other facts/events.

// Bellow we enrich the event instance with the percentual change in
the price, 

// based on the previous price

//modify( $st ) { delta = $cp.delta }

//modify( $st ) { readings = 5 }

//System.out.println($st.delta)

end


___
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] keeping running stats

2009-05-27 Thread Chris Richmond
I think the problem is that the stockticks aren't being processed unless I
use the:

 

From entry-point StockTick stream 

 

But I can't combine  from accumulate with that from statement successfully
in that sample I sent.  I think that is the problem .  The sample I sent,
none of those ever get processed since it is not looking at the proper entry
point.

 

 

 

 

 

  _  

From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Michal Bali
Sent: Wednesday, May 27, 2009 11:09 AM
To: Rules Users List
Subject: Re: [rules-users] keeping running stats

 

Hi Chris,

You can use 'accumulate' with sliding time window. Have a look here
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/
ch02.html#d0e1169

rule Sound the alarm in case temperature rises above threshold


when


TemperatureThreshold( $max : max )


Number( doubleValue  $max ) from accumulate(






SensorReading( $temp : temperature ) over window:time( 10m ),


average( $temp ) )


then


// sound the alarm


end

The engine will automatically discard any SensorReading older than 10
minutes and keep the calculated average consistent.

Is that what you're looking for?

Michal



2009/5/27 Chris Richmond crichm...@referentia.com

Hello,

 

I have modified the stockTicker fusion example to keep some running stats,
you can see from the rule snippet below that it injects a stats object based
on the symbol then matches them as updates come in later.  You can see for
now I am just updating the running counts and outputting the readings count
on each stock tick and this works fine.

 

What I would like to do however is only have the running averages,stats
object reflect stock ticks that are still in memory..essentiall only stock
tick items that have not expired.  As it is now the count just keeps growing
and growing, I want the count to only reflect the stock ticks within the
expiration time in the past for stock ticks, but I cannot figure out how to
make this happen?Could anyone give me a pointer on how to do this?  How
to make the stats object only reflect those stock ticks that have not
expired?  I do not know the strategy for this.

 

Thanks,

Chris

 

# tells the engine that a StockTick instance will assume the

# role (semantics) of events and that the default retention 

# policy will be 2 minutes 

declare StockTick

@role( event )

@expires( 1m )

end 

 

# One can even declare helper facts to make rules easier and

# simpler to write and maintain

declare Statistics

symbol : String @key()

average : double

readings : int

total : double

end

 

rule Setup statistics

when

   $c : Company( $s : symbol )

   not( Statistics( symbol == $s ) )

then

   Statistics s = new Statistics();

   s.symbol = $s;

   s.readings = s.readings + 1;

   insert( s );

 

end

 

 

 

# a simple rule to show that it is possible to join

# events from an entry-point (stream) with facts 

# present in the working memory

rule Update stock stats

agenda-group evaluation

lock-on-active

when

  

$cp : Company( $sb : symbol )

$st : StockTick( symbol == $sb, $pr : price ) from entry-point
StockTick stream

 

  $stats : Statistics( symbol == $sb  )

 

then

 

  modify( $stats ) { readings = readings + 1};

  System.err.println($stats.symbol + readings:  + $stats.readings);

// This shows an update on working memory facts with data from joined
events

//modify( $cp ) { currentPrice = $pr }



// Although events are considered immutable, a common pattern is to use
a class

// to represent an event and enrich that event instance with data
derived from other facts/events.

// Bellow we enrich the event instance with the percentual change in
the price, 

// based on the previous price

//modify( $st ) { delta = $cp.delta }

//modify( $st ) { readings = 5 }

//System.out.println($st.delta)

end


___
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: Re[rules-users] sult Lists from Decision Tables

2009-05-27 Thread wasabifan

Possibly.  Is that set by the Variables keyword in Decision Tables?  Then in
the Java code you just set the global variable by session.setGlobal(string,
object)?


Michal Bali-2 wrote:
 
 Hi Bryan,
 
 Can you use globals for this ?
 
 Regards,
 Michal
 

-- 
View this message in context: 
http://www.nabble.com/Result-Lists-from-Decision-Tables-tp23749077p23752966.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] fact granularity, performance, and other questions

2009-05-27 Thread David Zeigler
Hi,
I could use some experienced guidance.  I'm in the process of
evaluating Drools for use of using in a real-time transactional
environment to process about 3000 messages/second.  I realize a lot of
this depends on the type and quantity of rules, hardware, etc.  I'm
curious what steps others have taken to improve performance and if
there are any recommendations for my case detailed below.

A few specific questions I have are:
 - Should each field in a message be a fact? (more info on my message
below)  What fact granularity have you settled on in your usage and
why?
 - Does the order of the conditions in a rule affect performance, the
execution order, or the structure of the Rete network?
 - Does the order the facts are inserted into a stateless session (as
a list via the CommandFactory.newInsertElements) affect performance at
all?

The message is an EDI format and will typically have anywhere from 80
to 200 fields, potentially more.  The message is divided into
transactions, then segments, then fields.  We have an object model
that represents the message.  We're using a stateless session and most
of the rules will modify fields or add fields and segments based on
the values of other fields.  Currently, I flatten the object model
into a List containing the message, transactions, segments, and each
field, and then insert the list into the stateless session and fire.
I'm avoiding sequential mode for now until we have a better idea of
our requirements.

Here's a simplified example of what I'm doing now (using json-esque
syntax instead of the EDI format).
message {
  segment {
SG:header
A0:agents
  }
  segment {
SG:agent
A1:000
A2:JAMES
A3:BOND
  }
  segment {
SG:agent
A1:86
A2:MAXWELL
A3:SMART
  }
}

Each field has an id and a value.  For this message, I would insert 14
facts:  the message object, 3 segments objects, and 10 field objects.

rule set James Bond's A1 to 007
when
  $a1 : Field(id == A1,  value != 007)
  Field(id == A2,  value == JAMES)
  Field(id == A3,  value == BOND)
then
  $a1.setValue(007);
  update($a1);
end

A relatively more complicated, but typical rule would be set James
Bond's A1 to 007 iff he's the second agent in the message and one of
the other agents' first names does not contain AUSTIN and an agency
segment exists

The above example assumes each segment and field is a fact and I think
it's a clean and flexible approach, but I'm concerned about the
overhead of inserting potentially 250 facts for each message.  The
only other alternatives I can think of seem to have their own set of
problems:
1. limit the fields that rules can be written against to a limited
subset, which may not be feasible depending on how the requirements
evolve, and only assert those as facts.  Doing this seems to double
the number of transactions per second in my nonscientific benchmark.
2. insert the Message object as a single fact and then write a slew of
accessor methods in that object to get at all possible fields in the
tree: getA1FromSecondAgentSegmentInFirstTransaction().  This seems
like it might perform well, but could be very messy.
3. provide an api in the message object model to find various
occurrences of fields in the messages, then use eval() in the rule.
like eval(msg.findSegment(agent, secondOccurrence).getField(A1)).
I've read that would be less efficient once the ruleset grows.

I'm sure many of you have dealt with this type scenario before, what
did you determine the best approach to be?

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


Re: [rules-users] fact granularity, performance, and other questions

2009-05-27 Thread Ingomar Otter

David,
- Does the order of the conditions in a rule affect performance, the
execution order, or the structure of the Rete network?
Yes, quite a lot has been written about this. The drools documentation  
has a few paragraphs with good heuristics...
 A popular read seems to be this paper, which provides good insight  
into RETE performance aspects:


Production Matching for Large Learning Systems (Rete/UL)
by Robert B. Doorenbos
PhD thesis, Carnegie Mellon University, January 31, 1995



- Does the order the facts are inserted into a stateless session (as
 a list via the CommandFactory.newInsertElements) affect performance  
at

all?
All I can say that this is true (it has impact) for statefull  
sessions. The deal here is how often the agenda may get changed while  
inserting objects.

I have no experience with stateless sessions and I hope others do;-)

- Should each field in a message be a fact? (more info on my message
below)  What fact granularity have you settled on in your usage and
why?
I would suggest to start with a model which is most natural to your  
rules (with the lowest WTF factor) and take it from there.


I assume that you need to correlate information from all segments of a  
message?
I would stay well clear from your option 3 (eval()) - just because I  
always do ;-)
Eval() simply defies RETE optimizations so it can be very sensitive to  
both number of facts and number of rules (using eval).


If you know the field IDs (which I assume you would, using an EDI  
formant) -  I would see whether you can avoid the field facts and turn  
them into slots (attributes) instead.
But not to the extend you outline in #2, that seems to be too awkward.  
If you have buy another server ;-)



what did you determine the best approach to be?
I am pretty sure that there is no generic best approach.
I would proceed trying to understand the nature of the rules (are they  
regular, ie following the same scheme, can they be generated?) and the  
data and create
regression performance test-suite ASAP to monitor performance during  
development.


In our application we for example have analyzed bottlenecks and found  
that (no surprise) accessing properties like facta.factb.value is  
slower compared to facta.facbtValue  - that's in 4.07 - due to the  
different mechanism the value is obtained. From there we have added  
about three of these shortcut accessors. However we have first  
focused on optimizing the rules themself to avoid excessive matching  
in the first place so there was no need for us to flatten our entire  
model.



my 0.02EUR
 -- Ingomar

Am 28.05.2009 um 02:17 schrieb David Zeigler:


Hi,
I could use some experienced guidance.  I'm in the process of
evaluating Drools for use of using in a real-time transactional
environment to process about 3000 messages/second.  I realize a lot of
this depends on the type and quantity of rules, hardware, etc.  I'm
curious what steps others have taken to improve performance and if
there are any recommendations for my case detailed below.

A few specific questions I have are:
- Should each field in a message be a fact? (more info on my message
below)  What fact granularity have you settled on in your usage and
why?
- Does the order of the conditions in a rule affect performance, the
execution order, or the structure of the Rete network?
- Does the order the facts are inserted into a stateless session (as
a list via the CommandFactory.newInsertElements) affect performance at
all?

The message is an EDI format and will typically have anywhere from 80
to 200 fields, potentially more.  The message is divided into
transactions, then segments, then fields.  We have an object model
that represents the message.  We're using a stateless session and most
of the rules will modify fields or add fields and segments based on
the values of other fields.  Currently, I flatten the object model
into a List containing the message, transactions, segments, and each
field, and then insert the list into the stateless session and fire.
I'm avoiding sequential mode for now until we have a better idea of
our requirements.

Here's a simplified example of what I'm doing now (using json-esque
syntax instead of the EDI format).
message {
 segment {
   SG:header
   A0:agents
 }
 segment {
   SG:agent
   A1:000
   A2:JAMES
   A3:BOND
 }
 segment {
   SG:agent
   A1:86
   A2:MAXWELL
   A3:SMART
 }
}

Each field has an id and a value.  For this message, I would insert 14
facts:  the message object, 3 segments objects, and 10 field objects.

rule set James Bond's A1 to 007
when
 $a1 : Field(id == A1,  value != 007)
 Field(id == A2,  value == JAMES)
 Field(id == A3,  value == BOND)
then
 $a1.setValue(007);
 update($a1);
end

A relatively more complicated, but typical rule would be set James
Bond's A1 to 007 iff he's the second agent in the message and one of
the other agents' first names does not contain AUSTIN and an agency
segment exists

The above example assumes each segment and field is 

Re: [rules-users] fact granularity, performance, and other questions

2009-05-27 Thread Greg Barton

To address some points in order:

Yes, having each field in a message as a fact is the most straightforward.  The 
catch is that the rejoining conditions should be as fast as possible.  I'm 
thinking this structure would be best:

class Message {
  ...message level properties...
}

class Segment {
  public Message message;
  public int position;
  ...Segment level properties
}

Then the rules would be like this:

when
  m: Message(...foo...);
  s0: Segment(position == 0, message == m, ...bar...)
  s1: Segment(position == 1, message == m, ...bas...)
then
...
end

That's about as fast as you'll get with this setup, I figure.  And you're 
right, it is important to list the conditions in a certain order: with the 
position == n condition before the message == m condition, MANY Segments in 
working memory are eliminated from consideration before getting to the more 
expensive cross object join. (Even though the cross object condition is about 
as cheap as you can get, a straight == check.)

I'm not sure about the answer to the fact insertion order question vis a vis 
performance in a stateless session.  My guess is no effect, but probably a 
question for the devs. (Or a bit 'o' experimentation.)

It would be nice if your item #2 could be accomplished with a class property 
that's a multidimensional String array, though it throws an array out of bounds 
exception if you try testing for an array position that's too high.  Another 
way (which I think is what you suggest below) would be to have a one time 
generated class to with the following structure:

class Fact {
  String[][][] facts;
  
  public String geta0s0t0() {
if(facts.length =1  facts[0].length = 1 facts[0][0].length = 0) {
  return facts[0][0][0];
} else {
  return ;
}
  }
}

Initialize each one with a String[][][] and you're on your way.  This would 
absolutely be faster than the first method above, probably by several orders of 
magnitude.  

Another approach would be to see how hard it would be to alter mvel so it 
evaluates the array[out_of_bounds_index] expressions to false instead of 
throwing an exception.  Maybe for the long term...  

--- On Wed, 5/27/09, David Zeigler dzeig...@gmail.com wrote:

 From: David Zeigler dzeig...@gmail.com
 Subject: [rules-users] fact granularity, performance, and other questions
 To: Rules Users List rules-users@lists.jboss.org
 Date: Wednesday, May 27, 2009, 7:17 PM
 Hi,
 I could use some experienced guidance.  I'm in the
 process of
 evaluating Drools for use of using in a real-time
 transactional
 environment to process about 3000 messages/second.  I
 realize a lot of
 this depends on the type and quantity of rules, hardware,
 etc.  I'm
 curious what steps others have taken to improve performance
 and if
 there are any recommendations for my case detailed below.
 
 A few specific questions I have are:
  - Should each field in a message be a fact? (more info on
 my message
 below)  What fact granularity have you settled on in
 your usage and
 why?
  - Does the order of the conditions in a rule affect
 performance, the
 execution order, or the structure of the Rete network?
  - Does the order the facts are inserted into a stateless
 session (as
 a list via the CommandFactory.newInsertElements) affect
 performance at
 all?
 
 The message is an EDI format and will typically have
 anywhere from 80
 to 200 fields, potentially more.  The message is
 divided into
 transactions, then segments, then fields.  We have an
 object model
 that represents the message.  We're using a stateless
 session and most
 of the rules will modify fields or add fields and segments
 based on
 the values of other fields.  Currently, I flatten the
 object model
 into a List containing the message, transactions, segments,
 and each
 field, and then insert the list into the stateless session
 and fire.
 I'm avoiding sequential mode for now until we have a better
 idea of
 our requirements.
 
 Here's a simplified example of what I'm doing now (using
 json-esque
 syntax instead of the EDI format).
 message {
   segment {
     SG:header
     A0:agents
   }
   segment {
     SG:agent
     A1:000
     A2:JAMES
     A3:BOND
   }
   segment {
     SG:agent
     A1:86
     A2:MAXWELL
     A3:SMART
   }
 }
 
 Each field has an id and a value.  For this message, I
 would insert 14
 facts:  the message object, 3 segments objects, and 10
 field objects.
 
 rule set James Bond's A1 to 007
 when
   $a1 : Field(id == A1,  value != 007)
   Field(id == A2,  value == JAMES)
   Field(id == A3,  value == BOND)
 then
   $a1.setValue(007);
   update($a1);
 end
 
 A relatively more complicated, but typical rule would be
 set James
 Bond's A1 to 007 iff he's the second agent in the message
 and one of
 the other agents' first names does not contain AUSTIN and
 an agency
 segment exists
 
 The above example assumes each segment and field is a fact
 and I think
 it's a clean and flexible approach, but I'm concerned about
 the
 overhead of 

Re: [rules-users] keeping running stats

2009-05-27 Thread Edson Tirelli
   Definitively. That for sure will cause a problem, because each entry
point is like a partition in the data set space.

   To make this work, just use the from entry-point:

Number( doubleValue  1.0 ) *from* *accumulate*(

StockTick( $pr : price, symbol == IBM ) over window:time( 5m )
from entry-point StockTick stream,
average( $pr ) )


   []s
   Edson

2009/5/27 Chris Richmond crichm...@referentia.com

  I think the problem is that the stockticks aren’t being processed unless
 I use the:



 From entry-point “StockTick stream”



 But I can’t combine  “from accumulate” with that from statement
 successfully in that sample I sent.  I think that is the problem .  The
 sample I sent, none of those ever get processed since it is not looking at
 the proper entry point…










  --

 *From:* rules-users-boun...@lists.jboss.org [mailto:
 rules-users-boun...@lists.jboss.org] *On Behalf Of *Michal Bali
 *Sent:* Wednesday, May 27, 2009 11:09 AM
 *To:* Rules Users List
 *Subject:* Re: [rules-users] keeping running stats



 Hi Chris,


 You can use 'accumulate' with sliding time window. Have a look here
 http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/html/ch02.html#d0e1169

 rule Sound the alarm in case temperature rises above threshold

 when

 TemperatureThreshold( $max : max )

 Number( doubleValue  $max ) from accumulate(

 SensorReading( $temp : temperature ) over window:time( 10m ),

 average( $temp ) )

 then

 // sound the alarm

 end

 The engine will automatically discard any SensorReading older than 10
 minutes and keep the calculated average consistent.

 Is that what you're looking for?

 Michal

  2009/5/27 Chris Richmond crichm...@referentia.com

 Hello,



 I have modified the stockTicker fusion example to keep some running stats,
 you can see from the rule snippet below that it injects a stats object based
 on the symbol then matches them as updates come in later.  You can see for
 now I am just updating the running counts and outputting the readings count
 on each stock tick and this works fine.



 What I would like to do however is only have the running averages,stats
 object reflect stock ticks that are still in memory….essentiall only stock
 tick items that have not expired.  As it is now the count just keeps growing
 and growing, I want the count to only reflect the stock ticks within the
 expiration time in the past for stock ticks, but I cannot figure out how to
 make this happen?Could anyone give me a pointer on how to do this?  How
 to make the stats object only reflect those stock ticks that have not
 expired?  I do not know the strategy for this.



 Thanks,

 Chris



 # tells the engine that a StockTick instance will assume the

 # role (semantics) of events and that the default retention

 # policy will be 2 minutes

 *declare* StockTick

 @role( event )

 @expires( 1m )

 *end*



 # One can even declare helper facts to make rules easier and

 # simpler to write and maintain

 *declare* Statistics

 symbol : String @key()

 average : *double*

 readings : *int*

 total : *double*

 *end*



 *rule* Setup statistics

 *when*

$c : Company( $s : symbol )

*not*( Statistics( symbol == $s ) )

 *then*

Statistics s = *new* Statistics();

s.symbol = $s;

s.readings = s.readings + 1;

*insert*( s );



 *end*







 # a simple rule to show that it is possible to join

 # events from an entry-point (stream) with facts

 # present in the working memory

 *rule* Update stock stats

 *agenda-group* evaluation

 *lock-on-active*

 *when*



 $cp : Company( $sb : symbol )

 $st : StockTick( symbol == $sb, $pr : price ) *from* entry-point 
 StockTick
 stream



   $stats : Statistics( symbol == $sb  )



 *then*



   *modify*( $stats ) { readings = readings + 1};

   System.err.println($stats.symbol + readings:  + $stats.readings);

 // This shows an update on working memory facts with data from joined
 events

 //modify( $cp ) { currentPrice = $pr }



 // Although events are considered immutable, a common pattern is to
 use a class

 // to represent an event and enrich that event instance with data
 derived from other facts/events.

 // Bellow we enrich the event instance with the percentual change in
 the price,

 // based on the previous price

 //modify( $st ) { delta = $cp.delta }

 //modify( $st ) { readings = 5 }

 //System.out.println($st.delta)

 *end*


 ___
 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




-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com

[rules-users] Date questions

2009-05-27 Thread Armaghan Mahmud
Hi guys,

I'm looking to do the following and I was wondering how to use Date objects
in Drools. This is what I currently have:

rule Difference between end and start time is less than a very small
(threshold) value.

*salience* 100

when

*obs*: ObsClass((endTime - startTime)  someVerySmallValue)

then

System.out.*println*(Difference between end and start time is less than
a very small (threshold) value.);

End



rule Check if user defined time frame falls between startTime and endTime
variables

*salience* 100

when

*obs*: ObsClass((endTime - userDefinedTime)  0  (userDefinedTime -
startTime)  0)

then

   System.out.println(Check if user defined time frame falls between
startTime and endTime variables)

end

The problem I'm having with dates is in comparing them. The mathematical
portion of the rules above kind of explain what I want to do but I doubt
I'll be able to achieve my goals. Any help would be greatly appreciated.

Thanks in advance,
Armaghan
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] fact granularity, performance, and other questions

2009-05-27 Thread Wolfgang Laun
I also think that the approach proposed by Greg of having a Message fact
type and various Segment fact types would let you write efficient and
maintainable rules. (The extreme splitting into Field facts has several
drawbacks, as has been pointed out, and also: 'value' is always a string,
so you lose type checking.) One thing I could not see is the effect of
the structural layer of transactions. And another one: are there several
(sub)types of Segment? If so, it will be possible of writing rules against
(abstract) base types, e.g.

abstract class Segment
class DebitSeg extends Segment
class CreditSeg extends Segment

rule notPositive
when
 $s : Segment( amount = 0 )
then
weird( $s );

Also, Segment subtypes might implement interfaces, and its
also possible to use them as fact names in patterns.

-W


On Thu, May 28, 2009 at 2:17 AM, David Zeigler dzeig...@gmail.com wrote:

 Hi,
 I could use some experienced guidance.  I'm in the process of
 evaluating Drools for use of using in a real-time transactional
 environment to process about 3000 messages/second.  I realize a lot of
 this depends on the type and quantity of rules, hardware, etc.  I'm
 curious what steps others have taken to improve performance and if
 there are any recommendations for my case detailed below.

 A few specific questions I have are:
  - Should each field in a message be a fact? (more info on my message
 below)  What fact granularity have you settled on in your usage and
 why?
  - Does the order of the conditions in a rule affect performance, the
 execution order, or the structure of the Rete network?
  - Does the order the facts are inserted into a stateless session (as
 a list via the CommandFactory.newInsertElements) affect performance at
 all?

 The message is an EDI format and will typically have anywhere from 80
 to 200 fields, potentially more.  The message is divided into
 transactions, then segments, then fields.  We have an object model
 that represents the message.  We're using a stateless session and most
 of the rules will modify fields or add fields and segments based on
 the values of other fields.  Currently, I flatten the object model
 into a List containing the message, transactions, segments, and each
 field, and then insert the list into the stateless session and fire.
 I'm avoiding sequential mode for now until we have a better idea of
 our requirements.

 Here's a simplified example of what I'm doing now (using json-esque
 syntax instead of the EDI format).
 message {
  segment {
SG:header
A0:agents
  }
  segment {
SG:agent
A1:000
A2:JAMES
A3:BOND
  }
  segment {
SG:agent
A1:86
A2:MAXWELL
A3:SMART
  }
 }

 Each field has an id and a value.  For this message, I would insert 14
 facts:  the message object, 3 segments objects, and 10 field objects.

 rule set James Bond's A1 to 007
 when
  $a1 : Field(id == A1,  value != 007)
  Field(id == A2,  value == JAMES)
  Field(id == A3,  value == BOND)
 then
  $a1.setValue(007);
  update($a1);
 end

 A relatively more complicated, but typical rule would be set James
 Bond's A1 to 007 iff he's the second agent in the message and one of
 the other agents' first names does not contain AUSTIN and an agency
 segment exists

 The above example assumes each segment and field is a fact and I think
 it's a clean and flexible approach, but I'm concerned about the
 overhead of inserting potentially 250 facts for each message.  The
 only other alternatives I can think of seem to have their own set of
 problems:
 1. limit the fields that rules can be written against to a limited
 subset, which may not be feasible depending on how the requirements
 evolve, and only assert those as facts.  Doing this seems to double
 the number of transactions per second in my nonscientific benchmark.
 2. insert the Message object as a single fact and then write a slew of
 accessor methods in that object to get at all possible fields in the
 tree: getA1FromSecondAgentSegmentInFirstTransaction().  This seems
 like it might perform well, but could be very messy.
 3. provide an api in the message object model to find various
 occurrences of fields in the messages, then use eval() in the rule.
 like eval(msg.findSegment(agent, secondOccurrence).getField(A1)).
 I've read that would be less efficient once the ruleset grows.

 I'm sure many of you have dealt with this type scenario before, what
 did you determine the best approach to be?

 Thanks,
 David
 ___
 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