Re: [rules-users] Run Drool Application From Command Prompt
by Greg Barton
heh. I just remembered that Thread.currentThread().getContextClassLoader() can return null as well. :) A good thing to do is have a utility function like the attached class loading utility class. Rearrange the class loading order to suit your taste.
--- On Tue, 7/28/09, Greg Barton <greg_barton(a)yahoo.com> wrote:
> From: Greg Barton <greg_barton(a)yahoo.com>
> Subject: Re: [rules-users] Run Drool Application From Command Prompt
> To: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Tuesday, July 28, 2009, 12:59 AM
>
> It's unclear from your post when you get the NPE: from the
> command line, from eclipse, or when integrated with OFBiz.
> (I assume you're referring to http://ofbiz.apache.org/)
>
> It's undoubtedly a classpath issue. Just peek at the
> source a bit. I'm not sure what version you're using,
> but if you look at the source in the svn repo you'll see
> that line 92 of JavaDialectConfiguration is this:
>
> getClass().getClassLoader().loadClass(
> "org.eclipse.jdt.internal.compiler.Compiler" );
>
> See the javadoc for Class.getClassLoader() that says
> "Returns the class loader for the class. Some
> implementations may use null to represent the bootstrap
> class loader. This method will return null in such
> implementations if this class was loaded by the bootstrap
> class loader."
>
> So, it looks probable that in the environment that's having
> problems, the JavaDialectConfiguration class is loaded by
> the bootstrap classloader. What is the VM
> implementation you're using?
>
> It might be best if
> Thread.currentThread().getContextClassLoader() was used
> instead of getClass().getClassLoader() in
> JavaDialectConfiguration and elsewhere. Devs, have an
> opinion on that?
>
> --- On Mon, 7/27/09, Pankaj.Jain(a)lntinfotech.com
> <Pankaj.Jain(a)lntinfotech.com>
> wrote:
>
> > From: Pankaj.Jain(a)lntinfotech.com
> <Pankaj.Jain(a)lntinfotech.com>
> > Subject: Re: [rules-users] Run Drool Application From
> Command Prompt
> > To: rules-users(a)lists.jboss.org
> > Date: Monday, July 27, 2009, 11:50 PM
> >
> >
> > Hi
> >
> >
> >
> > I still have not got any
> > solution
> > of my problem that I posted previously. I have
> included all
> > required jar
> > files and set proper class path .. Please do help ?
> >
> >
> >
> > problem:
> >
> >
> >
> >
> > I am trying to
> > integrate Drool with
> > ofbiz and run application from command prompt. In one
> way I
> > have integrated
> > it properly and I am able to run it
> > successfully.
> >
> >
> >
> >
> > Code : Which I was using initially
> >
> >
> >
> > KnowledgeBuilder kbuilder =
> > KnowledgeBuilderFactory.newKnowledgeBuilder();
> >
> >
> >
> >
> > or
> >
> >
> >
> > PackageBuilderConfiguration cfg = new
> > PackageBuilderConfiguration();
> >
> >
> > KnowledgeBuilder kbuilder =
> > KnowledgeBuilderFactory.newKnowledgeBuilder();
> >
> >
> >
> >
> > Exception I got :
> >
> >
> >
> > org.drools.RuntimeDroolsException: Unable to load
> dialect
> >
> 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java
> >
> >
> >
> :org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
> >
> >
> > at
> >
> org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:274)
> > at
> >
> org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:259)
> >
> >
> >
> >
> > at
> >
> org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:176)
> > at
> >
> org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
> > at
> >
> org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
> >
> >
> > .
> >
> > .
> >
> > .
> >
> > Caused by: java.lang.NullPointerException
> >
> > at
> >
> org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:92)
> > at
> >
> org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
> > at
> >
> org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:270
> >
> >
> >
> >
> > Problem I found :
> >
> > In the class JavaDialectConfiguration in jar file
> > drools-compiler.jar there
> > is a method named "setCompliler", in this
> > method Null Pointer
> > Exception was coming.
> >
> >
> >
> > Solution I provided :
> >
> >
> > In my application I created my custom class
> > CustomJavaDialectConfiguration
> > by extending to class JavaDialectConfiguration, In
> this
> > class I overrided
> > the method setCompiler. My method was exactly same as
> that
> > of method setCompiler
> > in JavaDialectConfiguration . To call my dialect class
> I
> > also overrided
> > the method "addDialect" of
> > PackageBuilderConfiguration class
> > . For that I created class
> > CustomPackageBuilderConfiguration by extending
> > to PackageBuilderConfiguration.
> >
> > after that I wrote the code:
> >
> >
> >
> > PackageBuilderConfiguration cfg = new
> > CustomPackageBuilderConfiguration();
> >
> >
> > KnowledgeBuilder kbuilder =
> > KnowledgeBuilderFactory.newKnowledgeBuilder(cfg);
> >
> >
> >
> >
> >
> >
> > Now application is running perfectly fine from both
> eclipse
> > and command
> > prompt without any exception.
> >
> >
> >
> > I want to know as my overrided method
> > "setCompiler" was exactly
> > same then why I had to override method, and In
> original
> > code (ie in drools-compiler.jar
> > file) why it was giving exception ??? Was that
> > due to class
> > lader or something else ?? Please do help in this
> > regard ....
> >
> >
> >
> >
> >
> >
> >
> >
> > Thanks & Regards:
> >
> >
> >
> > Pankaj Jain | L&T infotech |Navi Mumbai
> >
> > Mobile: +91 9920218945
> >
> > Email : pankaj.jain(a)lntinfotech.com
> >
> > www.Lntinfotech.com
> >
> >
> >
> > "Whatever the mind of man can conceive & believe,
> > it can achieve."
> >
> >
> >
> > Larsen & Toubro Infotech Ltd.
> >
> > www.Lntinfotech.com
> >
> >
> >
> > This Document is classified as:
> >
> >
> >
> > L&T
> > Infotech Proprietary L&T
> > Infotech Confidential L&T
> > Infotech Internal Use Only L&T
> > Infotech General Business
> >
> >
> >
> > This Email may contain confidential or privileged
> > information for the intended
> > recipient (s) If you are not the intended recipient,
> please
> > do not use
> > or disseminate the information, notify the sender and
> > delete it from your
> > system.
> >
> >
> >
> >
> ______________________________________________________________________
> >
> >
> > -----Inline Attachment Follows-----
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 11 months
Drools Guvnor Remote API
by Steve Ronderos
Does anyone know if there is a Remoting API in Guvnor? I see mention of it
in some wiki pages, and in the web.xml in the Guvnor source.
I'm trying to see if I can remotely trigger a build for a specific
package, with a selector for the build, then create a snapshot for the
same package.
If anyone has any information about the API please let me know.
Thanks,
Steve Ronderos
16 years, 11 months
question on adding manual workitem within flow editor
by Pang, Yonghua
Hi,
I'm a newbie of Drools and I just met a problem when learning Drools
Flow according to Drools online documents.
I create a workitem, Notification, exactly according to Chapter 8 in
Drools Flow Doc. I create MyWorkDefinitions.conf and
drools.rulebase.conf, and then put them in classpath. Also, I create one
image to be used by the item.
However, this new workitem is not found in RuleFlow Editor. I'm not
sure if something else is needed. Can you guys please guide me to adding
new workitem and dragging/drawing it in RuleFlow Editor?
FYI. Though the RuleFlow editor cannot work with the new workitem, the
XML style works. I mean, I could manually change the XML of .rf file to
use the new workitem.
The work environment is JDK5, Drools5, Eclipse 3.4.5 and GEF 3.5.
The two conf files are also attached.
<<drools.rulebase.conf>> <<MyWorkDefinitions.conf>>
Thanks,
Paul
16 years, 11 months
Re: [rules-users] Customize the UI
by Radha Sreedharan
Hi ,
I did not find any example for customizing the UI, or the jar.
However I downloaded the file ServiceImplentation.java and other related
files from the Lucene SVN and and called the methods on ServiceImplentation
directly from my class.
However I did not take this forward after this as we had decided to follow a
different approach for implementation.
Regard,
Radha
2009/7/22 João Mouta Ferreira <jcf(a)holos.pt>
> Hello Radha,
>
> I am currently looking for the same as you posted in this email.
>
> My goal is to create an eclipse RCP user interface for creating rules.
> Since the Guvnor is web based, I am trying to find the classes which
> implement rule editing to translate them to my system.
>
> Have you found what you were looking for?
>
> Best regards,
> João Mouta
>
>
> Rads2029 wrote:
>
>> Hi,
>>
>> Can anyone give me an example of what exactly needs to be done if I need
>> to
>> use my own custom UI for rule creation etc. ( In this case my UI is Flex)
>>
>> As per the rules documentation , we need to to use the
>> ServiceImplementation
>> class which implements the RepositoryService. ( both of these are in the
>> package structure org.drools.guvnor.server)
>>
>> However I could not find any jar where these classes are readily
>> available.
>> :-((
>>
>> It would be great if i can get pointers to the jar location and also a
>> small
>> end to end example of how to plug in custom UI to call the drools guvnor (
>> brms) service.
>>
>> Thanks,
>> Radha
>>
>>
>
>
16 years, 11 months
Delivery reports about your e-mail
by Post Office
Dear user of lists.jboss.org,
Your account was used to send a large amount of spam during the last week.
We suspect that your computer was compromised and now contains a trojan proxy server.
We recommend you to follow instruction in order to keep your computer safe.
Have a nice day,
lists.jboss.org support team.
16 years, 11 months
Re: [rules-users] Using eval in LHS
by nash.8103@gmail.com
Thanks Greg.....
The reason I chose HashMap is that an accident is said to occur if and only if more than 1 vehicle contains four consecutive position report as same. So in my hashmap key is vehicle id and value is the no. Of times same position report received... Can you suggest me a way to
1. Collect all vehicles stopped at some point and the occurance of that event is reported more than thrice
2. Report accident if there are more than one vehicle found in step 1
---Priya
-original message-
Subject: Re: [rules-users] Using eval in LHS
From: Greg Barton <greg_barton(a)yahoo.com>
Date: 24/07/2009 10:36 pm
Try this:
rule "Create Collision Location"
salience 90
no-loop true
when
vehLoc : VehicleLocation()
not CollisionLocation(xway == vehLoc.xway, pos ==
vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane)
then
CollisionLocation collisionLoc = new CollisionLocation(vehLoc.getXway(),
vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane());
insert(collisionLoc);
end
rule "Collect Collided Vehicles"
salience 90
no-loop true
when
vehLoc : VehicleLocation()
$collisionLoc : CollisionLocation(xway == vehLoc.xway, pos ==
vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane)
then
collisionLoc.getVehicleLocations().add(vehLoc);
update(collisionLoc);
end
And now, the rule that detects more than three coinciding vehicle locations is simple:
rule "Detect Too Many"
when
CollisionLocation(vehicleLocations.size > 2)
then
...foo...
end
And, if you want to make the execution a bit more efficient, put a reference in VehicleLocation to it's associated CollisionLocation. That way you can have "vehLoc : VehicleLocation(collisionLocation == null)" to reduce partial matches.
--- On Fri, 7/24/09, PriyaSha <nash.8103(a)gmail.com> wrote:
> From: PriyaSha <nash.8103(a)gmail.com>
> Subject: [rules-users] Using eval in LHS
> To: rules-users(a)lists.jboss.org
> Date: Friday, July 24, 2009, 10:45 AM
>
> Input:
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,106,28,0,0,0,26,137745,-1,-1,-1,-1,-1,-1
> 0,0,108,32,0,0,0,67,354281,-1,-1,-1,-1,-1,-1
> 0,0,105,30,0,0,1,94,501089,-1,-1,-1,-1,-1,-1
>
> Problem:
>
> Should find vehicles with same data (if it occurs more than
> thrice).
>
> Though eval in rule 'Detect Accident' results in true,
> consequence is not
> fired.
>
> Output:
>
> Added
> Not Found -- 107---2
> test---2----107
> Not Found -- 107---3
> test---3----107
> Not Found -- 107---4
> test---4----107
> no of veh : 1
> no of veh : 1
> no of veh : 1
> Not Found -- 109---5
> test---1----109
> Not Found -- 109---6
> test---2----109
> Not Found -- 106---7
>
> Please find the DRL below.
>
>
> package com.hp.hpl.CHAOS.LR;
>
> # importing classes
> import java.lang.Integer;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Iterator;
>
> import com.hp.hpl.CHAOS.Rules.VehicleLocation;
>
> global java.lang.String output
>
> declare VehicleLocation
> @role ( event )
> @expires ( 1m )
> end
>
> declare Statistics
> smashedcars : ArrayList
> stopped_cars : ArrayList
> accidents : ArrayList
> collided_at : HashMap
> end
>
> rule "Setup statistics"
> salience 110
> no-loop true
> when
> not( Statistics( ) )
> vehLoc : VehicleLocation()
> then
> Statistics s = new Statistics();
> s.setSmashedcars (new ArrayList());
> s.setStopped_cars (new ArrayList());
> s.getStopped_cars().add(vehLoc);
> s.setCollided_at(new HashMap());
> insert( s );
>
> System.out.println("Added");
> end
>
> rule "Add to stopped cars"
> salience 100
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> ((not( VehicleLocation(vid ==
> vehLoc.vid) from $stat.getSmashedcars())))
> then
> modify($stat) {
>
> getStopped_cars().add(vehLoc);
> }
> System.out.println("Not Found -- " +
> vehLoc.getVid() + "---" +
> $stat.getStopped_cars().size());
> end
>
>
> rule "Identify Collided Vehicles"
> salience 90
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> $allStoppedcars : ArrayList( size > 0
> )
> from
> collect ( VehicleLocation(xway == vehLoc.xway, pos ==
> vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane) from
> $stat.stopped_cars)
> then
> System.out.println("test" + "---" +
> $allStoppedcars.size() + "----" +
> vehLoc.getVid());
>
> modify($stat) {
>
> setCollided_at(collided_at($allStoppedcars,
> vehLoc.getXway(),
> vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane()));
> }
> retract (vehLoc);
> end
>
> rule "Detect Accident"
> salience 80
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
>
> eval(collision_occured($stat.getCollided_at()))
> then
> System.out.println("Detect Accident");
> end
>
> function HashMap collided_at(ArrayList stopped_cars, int x,
> int pos, int
> dir, int lane) {
> HashMap collided_at = new HashMap();
> for (Iterator iterator =
> stopped_cars.iterator(); iterator.hasNext(); )
> {
> VehicleLocation vehLoc =
> (VehicleLocation) iterator.next();
> if (vehLoc.getXway() == x
> &&
> vehLoc.getPos() == pos
> &&
> vehLoc.getDir() == dir
> &&
> vehLoc.getLane() == lane) {
>
> int key =
> vehLoc.getVid();
> if
> (!collided_at.containsKey(key)) {
>
> collided_at.put (key, new Integer(1));
>
> continue;
> }
> collided_at.put
> (key,
> ((Integer)collided_at.get(key)).intValue()+1);
> }
> }
> return collided_at;
> }
>
> function boolean collision_occured(HashMap
> collided_vehicles) {
> java.util.Set entries =
> collided_vehicles.entrySet();
> int noOfCollidedVehicles = 0;
> java.util.Iterator iterator =
> entries.iterator();
>
> while ( iterator.hasNext() ) {
> java.util.Map.Entry object =
> (java.util.Map.Entry) iterator.next();
> if ((Integer)object.getValue()
> > 3) {
>
> noOfCollidedVehicles += 1;
> }
> }
>
> if (noOfCollidedVehicles > 0) {
> System.out.println("no of veh :
> " + noOfCollidedVehicles);
> return true;
> }
> return false;
> }
>
> Please let me know what should I correct here.
> --
> View this message in context: http://www.nabble.com/Using-eval-in-LHS-tp24646946p24646946.html
> Sent from the drools - user mailing list archive at
> Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
16 years, 11 months
Re: [rules-users] Using eval in LHS
by Greg Barton
Try this:
rule "Create Collision Location"
salience 90
no-loop true
when
vehLoc : VehicleLocation()
not CollisionLocation(xway == vehLoc.xway, pos ==
vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane)
then
CollisionLocation collisionLoc = new CollisionLocation(vehLoc.getXway(),
vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane());
insert(collisionLoc);
end
rule "Collect Collided Vehicles"
salience 90
no-loop true
when
vehLoc : VehicleLocation()
$collisionLoc : CollisionLocation(xway == vehLoc.xway, pos ==
vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane)
then
collisionLoc.getVehicleLocations().add(vehLoc);
update(collisionLoc);
end
And now, the rule that detects more than three coinciding vehicle locations is simple:
rule "Detect Too Many"
when
CollisionLocation(vehicleLocations.size > 2)
then
...foo...
end
And, if you want to make the execution a bit more efficient, put a reference in VehicleLocation to it's associated CollisionLocation. That way you can have "vehLoc : VehicleLocation(collisionLocation == null)" to reduce partial matches.
--- On Fri, 7/24/09, PriyaSha <nash.8103(a)gmail.com> wrote:
> From: PriyaSha <nash.8103(a)gmail.com>
> Subject: [rules-users] Using eval in LHS
> To: rules-users(a)lists.jboss.org
> Date: Friday, July 24, 2009, 10:45 AM
>
> Input:
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,106,28,0,0,0,26,137745,-1,-1,-1,-1,-1,-1
> 0,0,108,32,0,0,0,67,354281,-1,-1,-1,-1,-1,-1
> 0,0,105,30,0,0,1,94,501089,-1,-1,-1,-1,-1,-1
>
> Problem:
>
> Should find vehicles with same data (if it occurs more than
> thrice).
>
> Though eval in rule 'Detect Accident' results in true,
> consequence is not
> fired.
>
> Output:
>
> Added
> Not Found -- 107---2
> test---2----107
> Not Found -- 107---3
> test---3----107
> Not Found -- 107---4
> test---4----107
> no of veh : 1
> no of veh : 1
> no of veh : 1
> Not Found -- 109---5
> test---1----109
> Not Found -- 109---6
> test---2----109
> Not Found -- 106---7
>
> Please find the DRL below.
>
>
> package com.hp.hpl.CHAOS.LR;
>
> # importing classes
> import java.lang.Integer;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Iterator;
>
> import com.hp.hpl.CHAOS.Rules.VehicleLocation;
>
> global java.lang.String output
>
> declare VehicleLocation
> @role ( event )
> @expires ( 1m )
> end
>
> declare Statistics
> smashedcars : ArrayList
> stopped_cars : ArrayList
> accidents : ArrayList
> collided_at : HashMap
> end
>
> rule "Setup statistics"
> salience 110
> no-loop true
> when
> not( Statistics( ) )
> vehLoc : VehicleLocation()
> then
> Statistics s = new Statistics();
> s.setSmashedcars (new ArrayList());
> s.setStopped_cars (new ArrayList());
> s.getStopped_cars().add(vehLoc);
> s.setCollided_at(new HashMap());
> insert( s );
>
> System.out.println("Added");
> end
>
> rule "Add to stopped cars"
> salience 100
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> ((not( VehicleLocation(vid ==
> vehLoc.vid) from $stat.getSmashedcars())))
> then
> modify($stat) {
>
> getStopped_cars().add(vehLoc);
> }
> System.out.println("Not Found -- " +
> vehLoc.getVid() + "---" +
> $stat.getStopped_cars().size());
> end
>
>
> rule "Identify Collided Vehicles"
> salience 90
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> $allStoppedcars : ArrayList( size > 0
> )
> from
> collect ( VehicleLocation(xway == vehLoc.xway, pos ==
> vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane) from
> $stat.stopped_cars)
> then
> System.out.println("test" + "---" +
> $allStoppedcars.size() + "----" +
> vehLoc.getVid());
>
> modify($stat) {
>
> setCollided_at(collided_at($allStoppedcars,
> vehLoc.getXway(),
> vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane()));
> }
> retract (vehLoc);
> end
>
> rule "Detect Accident"
> salience 80
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
>
> eval(collision_occured($stat.getCollided_at()))
> then
> System.out.println("Detect Accident");
> end
>
> function HashMap collided_at(ArrayList stopped_cars, int x,
> int pos, int
> dir, int lane) {
> HashMap collided_at = new HashMap();
> for (Iterator iterator =
> stopped_cars.iterator(); iterator.hasNext(); )
> {
> VehicleLocation vehLoc =
> (VehicleLocation) iterator.next();
> if (vehLoc.getXway() == x
> &&
> vehLoc.getPos() == pos
> &&
> vehLoc.getDir() == dir
> &&
> vehLoc.getLane() == lane) {
>
> int key =
> vehLoc.getVid();
> if
> (!collided_at.containsKey(key)) {
>
> collided_at.put (key, new Integer(1));
>
> continue;
> }
> collided_at.put
> (key,
> ((Integer)collided_at.get(key)).intValue()+1);
> }
> }
> return collided_at;
> }
>
> function boolean collision_occured(HashMap
> collided_vehicles) {
> java.util.Set entries =
> collided_vehicles.entrySet();
> int noOfCollidedVehicles = 0;
> java.util.Iterator iterator =
> entries.iterator();
>
> while ( iterator.hasNext() ) {
> java.util.Map.Entry object =
> (java.util.Map.Entry) iterator.next();
> if ((Integer)object.getValue()
> > 3) {
>
> noOfCollidedVehicles += 1;
> }
> }
>
> if (noOfCollidedVehicles > 0) {
> System.out.println("no of veh :
> " + noOfCollidedVehicles);
> return true;
> }
> return false;
> }
>
> Please let me know what should I correct here.
> --
> View this message in context: http://www.nabble.com/Using-eval-in-LHS-tp24646946p24646946.html
> Sent from the drools - user mailing list archive at
> Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 11 months
Re: [rules-users] Using eval in LHS
by Greg Barton
heh. I shouldn't reply to posts while doing three other things. :) I didn't see your use of collect and insertion of VehicleLocation objects below.
What you need is an intermediate object, something like CollisionLocation, with all of the attributes you use to create the counters in the HashMap constructed in the rule functions. The CollisionLocation should also include a list of the vehicles participating in the collision. When that list gets longer than three vehicles, trigger the action.
--- On Fri, 7/24/09, Greg Barton <greg_barton(a)yahoo.com> wrote:
> From: Greg Barton <greg_barton(a)yahoo.com>
> Subject: Re: [rules-users] Using eval in LHS
> To: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Friday, July 24, 2009, 11:08 AM
>
> 1) You are completely circumventing the need for rules by
> putting business logic in the functions. If you want
> to do this, there's no reason to use rules at all.
> 2) To do it properly insert the VehicleLocation objects
> into working memory and use the "accumulate" keyword to
> determine if there are three of them that fit your
> criteria. See section "4.8.2.10. Conditional Element
> accumulate" here:
>
> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/t...
>
> --- On Fri, 7/24/09, PriyaSha <nash.8103(a)gmail.com>
> wrote:
>
> > From: PriyaSha <nash.8103(a)gmail.com>
> > Subject: [rules-users] Using eval in LHS
> > To: rules-users(a)lists.jboss.org
> > Date: Friday, July 24, 2009, 10:45 AM
> >
> > Input:
> > 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> > 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> > 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> > 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> > 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> > 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> > 0,0,106,28,0,0,0,26,137745,-1,-1,-1,-1,-1,-1
> > 0,0,108,32,0,0,0,67,354281,-1,-1,-1,-1,-1,-1
> > 0,0,105,30,0,0,1,94,501089,-1,-1,-1,-1,-1,-1
> >
> > Problem:
> >
> > Should find vehicles with same data (if it occurs more
> than
> > thrice).
> >
> > Though eval in rule 'Detect Accident' results in
> true,
> > consequence is not
> > fired.
> >
> > Output:
> >
> > Added
> > Not Found -- 107---2
> > test---2----107
> > Not Found -- 107---3
> > test---3----107
> > Not Found -- 107---4
> > test---4----107
> > no of veh : 1
> > no of veh : 1
> > no of veh : 1
> > Not Found -- 109---5
> > test---1----109
> > Not Found -- 109---6
> > test---2----109
> > Not Found -- 106---7
> >
> > Please find the DRL below.
> >
> >
> > package com.hp.hpl.CHAOS.LR;
> >
> > # importing classes
> > import java.lang.Integer;
> >
> > import java.util.ArrayList;
> > import java.util.HashMap;
> > import java.util.Iterator;
> >
> > import com.hp.hpl.CHAOS.Rules.VehicleLocation;
> >
> > global java.lang.String output
> >
> > declare VehicleLocation
> > @role ( event )
> > @expires ( 1m )
> > end
> >
> > declare Statistics
> > smashedcars : ArrayList
> > stopped_cars : ArrayList
> > accidents : ArrayList
> > collided_at : HashMap
> > end
> >
> > rule "Setup statistics"
> > salience 110
> > no-loop true
> > when
> > not( Statistics( ) )
> > vehLoc : VehicleLocation()
> > then
> > Statistics s = new Statistics();
> > s.setSmashedcars (new ArrayList());
> > s.setStopped_cars (new ArrayList());
> > s.getStopped_cars().add(vehLoc);
> > s.setCollided_at(new HashMap());
> > insert( s );
> >
> > System.out.println("Added");
> > end
> >
> > rule "Add to stopped cars"
> > salience 100
> > no-loop true
> > when
> > vehLoc : VehicleLocation()
> > $stat : Statistics ()
> > ((not( VehicleLocation(vid ==
> > vehLoc.vid) from $stat.getSmashedcars())))
> > then
> > modify($stat) {
> >
> > getStopped_cars().add(vehLoc);
> > }
> > System.out.println("Not Found -- " +
> > vehLoc.getVid() + "---" +
> > $stat.getStopped_cars().size());
> > end
> >
> >
> > rule "Identify Collided Vehicles"
> > salience 90
> > no-loop true
> > when
> > vehLoc : VehicleLocation()
> > $stat : Statistics ()
> > $allStoppedcars : ArrayList( size > 0
> > )
> > from
> > collect ( VehicleLocation(xway == vehLoc.xway, pos ==
> > vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane)
> from
> > $stat.stopped_cars)
> > then
> > System.out.println("test" + "---" +
> > $allStoppedcars.size() + "----" +
> > vehLoc.getVid());
> >
> > modify($stat) {
> >
> > setCollided_at(collided_at($allStoppedcars,
> > vehLoc.getXway(),
> > vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane()));
> > }
> > retract (vehLoc);
> > end
> >
> > rule "Detect Accident"
> > salience 80
> > no-loop true
> > when
> > vehLoc : VehicleLocation()
> > $stat : Statistics ()
> >
> > eval(collision_occured($stat.getCollided_at()))
> > then
> > System.out.println("Detect Accident");
> > end
> >
> > function HashMap collided_at(ArrayList stopped_cars,
> int x,
> > int pos, int
> > dir, int lane) {
> > HashMap collided_at = new HashMap();
> > for (Iterator iterator =
> > stopped_cars.iterator(); iterator.hasNext(); )
> > {
> > VehicleLocation vehLoc =
> > (VehicleLocation) iterator.next();
> > if (vehLoc.getXway() == x
> > &&
> > vehLoc.getPos() == pos
> > &&
> > vehLoc.getDir() == dir
> > &&
> > vehLoc.getLane() == lane) {
> >
> > int key =
> > vehLoc.getVid();
> > if
> > (!collided_at.containsKey(key)) {
> >
> > collided_at.put (key, new Integer(1));
> >
> > continue;
> > }
> > collided_at.put
> > (key,
> > ((Integer)collided_at.get(key)).intValue()+1);
> > }
> > }
> > return collided_at;
> > }
> >
> > function boolean collision_occured(HashMap
> > collided_vehicles) {
> > java.util.Set entries =
> > collided_vehicles.entrySet();
> > int noOfCollidedVehicles = 0;
> > java.util.Iterator iterator =
> > entries.iterator();
> >
> > while ( iterator.hasNext() ) {
> > java.util.Map.Entry object =
> > (java.util.Map.Entry) iterator.next();
> > if ((Integer)object.getValue()
> > > 3) {
> >
> > noOfCollidedVehicles += 1;
> > }
> > }
> >
> > if (noOfCollidedVehicles > 0) {
> > System.out.println("no of veh :
> > " + noOfCollidedVehicles);
> > return true;
> > }
> > return false;
> > }
> >
> > Please let me know what should I correct here.
> > --
> > View this message in context: http://www.nabble.com/Using-eval-in-LHS-tp24646946p24646946.html
> > Sent from the drools - user mailing list archive at
> > Nabble.com.
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 11 months
Re: [rules-users] Using eval in LHS
by Greg Barton
1) You are completely circumventing the need for rules by putting business logic in the functions. If you want to do this, there's no reason to use rules at all.
2) To do it properly insert the VehicleLocation objects into working memory and use the "accumulate" keyword to determine if there are three of them that fit your criteria. See section "4.8.2.10. Conditional Element accumulate" here:
https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/t...
--- On Fri, 7/24/09, PriyaSha <nash.8103(a)gmail.com> wrote:
> From: PriyaSha <nash.8103(a)gmail.com>
> Subject: [rules-users] Using eval in LHS
> To: rules-users(a)lists.jboss.org
> Date: Friday, July 24, 2009, 10:45 AM
>
> Input:
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,107,32,0,0,0,10,53320,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,109,20,0,0,0,19,100644,-1,-1,-1,-1,-1,-1
> 0,0,106,28,0,0,0,26,137745,-1,-1,-1,-1,-1,-1
> 0,0,108,32,0,0,0,67,354281,-1,-1,-1,-1,-1,-1
> 0,0,105,30,0,0,1,94,501089,-1,-1,-1,-1,-1,-1
>
> Problem:
>
> Should find vehicles with same data (if it occurs more than
> thrice).
>
> Though eval in rule 'Detect Accident' results in true,
> consequence is not
> fired.
>
> Output:
>
> Added
> Not Found -- 107---2
> test---2----107
> Not Found -- 107---3
> test---3----107
> Not Found -- 107---4
> test---4----107
> no of veh : 1
> no of veh : 1
> no of veh : 1
> Not Found -- 109---5
> test---1----109
> Not Found -- 109---6
> test---2----109
> Not Found -- 106---7
>
> Please find the DRL below.
>
>
> package com.hp.hpl.CHAOS.LR;
>
> # importing classes
> import java.lang.Integer;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Iterator;
>
> import com.hp.hpl.CHAOS.Rules.VehicleLocation;
>
> global java.lang.String output
>
> declare VehicleLocation
> @role ( event )
> @expires ( 1m )
> end
>
> declare Statistics
> smashedcars : ArrayList
> stopped_cars : ArrayList
> accidents : ArrayList
> collided_at : HashMap
> end
>
> rule "Setup statistics"
> salience 110
> no-loop true
> when
> not( Statistics( ) )
> vehLoc : VehicleLocation()
> then
> Statistics s = new Statistics();
> s.setSmashedcars (new ArrayList());
> s.setStopped_cars (new ArrayList());
> s.getStopped_cars().add(vehLoc);
> s.setCollided_at(new HashMap());
> insert( s );
>
> System.out.println("Added");
> end
>
> rule "Add to stopped cars"
> salience 100
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> ((not( VehicleLocation(vid ==
> vehLoc.vid) from $stat.getSmashedcars())))
> then
> modify($stat) {
>
> getStopped_cars().add(vehLoc);
> }
> System.out.println("Not Found -- " +
> vehLoc.getVid() + "---" +
> $stat.getStopped_cars().size());
> end
>
>
> rule "Identify Collided Vehicles"
> salience 90
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
> $allStoppedcars : ArrayList( size > 0
> )
> from
> collect ( VehicleLocation(xway == vehLoc.xway, pos ==
> vehLoc.pos, dir == vehLoc.dir, lane == vehLoc.lane) from
> $stat.stopped_cars)
> then
> System.out.println("test" + "---" +
> $allStoppedcars.size() + "----" +
> vehLoc.getVid());
>
> modify($stat) {
>
> setCollided_at(collided_at($allStoppedcars,
> vehLoc.getXway(),
> vehLoc.getPos(), vehLoc.getDir(), vehLoc.getLane()));
> }
> retract (vehLoc);
> end
>
> rule "Detect Accident"
> salience 80
> no-loop true
> when
> vehLoc : VehicleLocation()
> $stat : Statistics ()
>
> eval(collision_occured($stat.getCollided_at()))
> then
> System.out.println("Detect Accident");
> end
>
> function HashMap collided_at(ArrayList stopped_cars, int x,
> int pos, int
> dir, int lane) {
> HashMap collided_at = new HashMap();
> for (Iterator iterator =
> stopped_cars.iterator(); iterator.hasNext(); )
> {
> VehicleLocation vehLoc =
> (VehicleLocation) iterator.next();
> if (vehLoc.getXway() == x
> &&
> vehLoc.getPos() == pos
> &&
> vehLoc.getDir() == dir
> &&
> vehLoc.getLane() == lane) {
>
> int key =
> vehLoc.getVid();
> if
> (!collided_at.containsKey(key)) {
>
> collided_at.put (key, new Integer(1));
>
> continue;
> }
> collided_at.put
> (key,
> ((Integer)collided_at.get(key)).intValue()+1);
> }
> }
> return collided_at;
> }
>
> function boolean collision_occured(HashMap
> collided_vehicles) {
> java.util.Set entries =
> collided_vehicles.entrySet();
> int noOfCollidedVehicles = 0;
> java.util.Iterator iterator =
> entries.iterator();
>
> while ( iterator.hasNext() ) {
> java.util.Map.Entry object =
> (java.util.Map.Entry) iterator.next();
> if ((Integer)object.getValue()
> > 3) {
>
> noOfCollidedVehicles += 1;
> }
> }
>
> if (noOfCollidedVehicles > 0) {
> System.out.println("no of veh :
> " + noOfCollidedVehicles);
> return true;
> }
> return false;
> }
>
> Please let me know what should I correct here.
> --
> View this message in context: http://www.nabble.com/Using-eval-in-LHS-tp24646946p24646946.html
> Sent from the drools - user mailing list archive at
> Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 11 months