Re: Date problem
by jack wu
i copy the following from the Documentation. i thought it means that drools is going to auto convert the string "27-Oct-2007" into a java Date object.
+++++++++
DateThe date format "dd-mmm-yyyy" is supported by default. You can customize this by providing an alternative date format mask as a System property ("drools.dateformat" is the name of the property). If more control is required, use the inline-eval constraint.
Example 6.20. Date Literal Restriction
Cheese( bestBefore < "27-Oct-2007" )
+++++++++++++++++++++++++
Newsgroups: gmane.comp.java.drools.user
Date: 2008-01-23 23:32:42 GMT (4 hours and 13 minutes ago)
Were you compairing Date agaist string here, as your double quotes indicate?
Xiandong
Sent from my iPhone
On Jan 23, 2008, at 17:33, jack wu <jackxwu <at> yahoo.com> wrote:
if i have several levels of java beans, the Date is not working. example:
m:Message( first.second.date > "01-jan-2007" )
---------------------------------
Never miss a thing. Make Yahoo your homepage.
16 years, 11 months
XmlDumper use
by Mark McNally
I would like to use the XmlDumper to convert my DRL to XML but am unsure
of its use.
In particular, I am wondering where to get the proper instance of
PackageDescr to feed to the dump() method:
XmlDumper xmlDumper = new XmlDumper();
String xml = xmlDumper.dump( packageDescr );
the code I'm using to read the DRL is straight from an example in the
distro:
Reader source = new InputStreamReader(
PartSelectorImpl.class.getResourceAsStream( ruleSetName ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
Would someone mind pointing in the right direction?
Thanks, Mark
16 years, 11 months
Reusing function definitions in rules
by Henry Canterburry
Hi,
I am trying to create a centralized drl file for all my functions which
I can then use across other drl packages. It this possible? I am getting
compilation errors stating that: the method "function name" is undefined
for the type "my rule name". When I place the function definition in the
same drl as the rule I am using it in, things compile fine. Am I maybe
missing some function import statement?
Thanks
HC
16 years, 11 months
Is there a better way?
by Dirk Bergstrom
I collect objects of type RLI that are related to instances of type NPI, and
"attach" them to their NPIs, and (in a later agenda group) collect subsets of
RLIs based on attributes of RLIs, NPIs, and other objects. In the first agenda
group, I need to update() the NPI object after the new list of RLIs is attached,
but I only want to do this when a *new* list is attached.
The only way I can find to do this requires an eval. Is there a better way?
Here's the rule that I have now. This works:
rule "RLIs for NPI"
agenda-group "010"
lock-on-active true
salience 50
when
$npi : NPIRecord( )
$rli_list : RecordSet( eval( ! $rli_list.equals($npi.getRelatedRLIs())) ) from
collect( RLIRecord( npi_program == $npi.synopsis ) )
then
$npi.setRelatedRecords($rli_list, DataSource.RLI);
update($npi);
end
I'd like to write something like this:
...
$rli_list : RecordSet( $rli_list != $npi.relatedRLIs ) from
...
But that doesn't compile. To get around that, I added a method called
getContents to RecordSet that just returns "this", so I could write:
...
$rli_list : RecordSet( contents != $npi.relatedRLIs ) from
...
But that always returns true. Best I can tell, it gets compiled into an
inequality test, as opposed to a call to equals(), and the new list is never the
same object as the old list, even though they may have the same contents.
I also tried this (setRelatedRecords returns true if the list is different):
...
then
$npi.setRelatedRecords($rli_list, DataSource.RLI) && update($npi);
end
But that won't compile at all.
--
Dirk Bergstrom dirk(a)juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905
16 years, 11 months
More Design Questions
by Christie, Blair
There is some commentary out there that says if the working memory gets
too big than the performance of the rule engine will slow down.
What is a good rule of thumb to know when to create a different working
memories?
Can the rule base be too big(have too many rules)?
Is it reasonable design to break up the .drls by types of rules and have
a separate rule base and working memory for each one?
Cheers,
Blair
16 years, 11 months
Fwd: [rules-users] Distributed Rete algorithem
by Johan Lindberg
Hi,
> > Does anyone knows of a effort to make Rete algorithm (Drools)
> > distributed? By any chance is there a implementation?
> >
> no, it's something we are interested in - but probably won't start on
> that until the end of this year. Unless someone wants to volunteer :)
Isn't Jamocha[1] an attempt at a distributed Rete implementation? Or
it used to be, at least.
BR
Johan Lindberg
johan(a)pulp.se
[1] http://sourceforge.net/projects/jamocha
16 years, 11 months
Design Question
by Christie, Blair
Does anyone have any examples of using the new 'from' element it is now
common to pass a Hibernate session as a global, to allow 'from' to pull
data from a named Hibernate query.
Would it be good design to store the values for a condition in a
database so they can be changed without having to go into the .drl file?
i.e.
So instead of ..
Rule "free food"
when
Food( $food : name == "hamburger" )
$: Person( favouriteFood == $food )
then
System.out.println( $person.getName() + " gets a hamburger" );
End
You would have
global Food food //where food is inserted as a global but populated from
a db.
Rule "free food"
when
$food : food
$person: Person( favouriteFood == $food )
then
System.out.println( $person.getName() + " gets a " +
$food.getName() );
End
Cheers,
Blair
16 years, 11 months
ClassCast Exception loading Packages built using BRMS 4.0.4
by pavi de alwis
I have a scenario where I'm building the rules packages using the BRMS and
using a standalone drools-core deployment to load these binaries. However,
with the 4.0.4 release the following exception is generated by the
Package.readExternal(…) method during de-serialization.
It's using the BRMS 4.0.4 distribution war and the drools-core.jar
4.0.4available via Maven.
------------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.ClassCastException: org.drools.rule.Package
at org.drools.rule.Package.readExternal(Package.java:176)
at com.gbv.platform.rules.drools.impl.RuleRuntimeImpl.init(
RuleRuntimeImpl.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod
(AbstractAutowireCapableBeanFactory.java
:1214)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods
(AbstractAutowireCapableBeanFactory.java:1179
)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean
(AbstractAutowireCapableBeanFactory.java:1145)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
(AbstractAutowireCapableBeanFactory.java:427)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(
AbstractBeanFactory.java:251)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton
(DefaultSingletonBeanRegistry.java:144)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:248)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:160)
at
org.springframework.osgi.service.exporter.OsgiServiceFactoryBean.afterPropertiesSet
(OsgiServiceFactoryBean.java:271)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods
(AbstractAutowireCapableBeanFactory.java:1175
)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean
(AbstractAutowireCapableBeanFactory.java:1145)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
(AbstractAutowireCapableBeanFactory.java:427)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(
AbstractBeanFactory.java:251)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton
(DefaultSingletonBeanRegistry.java:144)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:248)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:160)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons
(DefaultListableBeanFactory.java:276)
at
org.springframework.context.support.AbstractApplicationContext.refresh(
AbstractApplicationContext.java:360)
at
org.springframework.osgi.context.support.AbstractRefreshableOsgiBundleApplicationContext.refresh
(AbstractRefreshableOsgiBundleApplicationCo
ntext.java:170)
at
org.springframework.osgi.extender.support.ServiceDependentOsgiBundleXmlApplicationContext.refresh
(ServiceDependentOsgiBundleXmlApplicationC
ontext.java:76)
at
org.springframework.osgi.extender.support.ApplicationContextCreator.run(
ApplicationContextCreator.java:155)
at java.lang.Thread.run(Thread.java:595)
Error Loading DROOLS Package : org.drools.rule.Package
------------------------------------------------------------------------------------------------------------------------------------------------------
BTW, Running the debugger through it I was able to get the stack trace
below. This occurs on the first call to Package.readExternal(ObjectInput)
line: 176 after returning from ObjectInputStream.readObject() line: 348
------------------------------------------------------------------------------------------------------------------------------------------------------
Package.readExternal(ObjectInput) line: 176
ObjectInputStream.readExternalData(Externalizable,
ObjectStreamClass) line: 1755
ObjectInputStream.readOrdinaryObject(boolean) line:
1717
ObjectInputStream.readObject0(boolean) line: 1305
ObjectInputStream.readObject() line: 348
Package.readExternal(ObjectInput) line: 176
RuleRuntimeImpl.init() line: 61
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line:
not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line:
39
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 585
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).invokeCustomInitMethod(String,
Object, String, boolean) line: 1214
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).invokeInitMethods(String,
Object, RootBeanDefinition) line: 1179
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String,
Object, RootBeanDefinition) line: 1145
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String,
RootBeanDefinition, Object[]) line: 427
AbstractBeanFactory$1.getObject() line: 251
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String,
ObjectFactory) line: 144
DefaultListableBeanFactory(AbstractBeanFactory).getBean(String,
Class, Object[]) line: 248
DefaultListableBeanFactory(AbstractBeanFactory).getBean(String)
line: 160
OsgiServiceFactoryBean.afterPropertiesSet() line: 271
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).invokeInitMethods(String,
Object, RootBeanDefinition) line: 1175
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String,
Object, RootBeanDefinition) line: 1145
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String,
RootBeanDefinition, Object[]) line: 427
AbstractBeanFactory$1.getObject() line: 251
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String,
ObjectFactory) line: 144
DefaultListableBeanFactory(AbstractBeanFactory).getBean(String,
Class, Object[]) line: 248
DefaultListableBeanFactory(AbstractBeanFactory).getBean(String)
line: 160
DefaultListableBeanFactory.preInstantiateSingletons() line:
276
ServiceDependentOsgiBundleXmlApplicationContext(AbstractApplicationContext).refresh()
line: 360
ServiceDependentOsgiBundleXmlApplicationContext(AbstractRefreshableOsgiBundleApplicationContext).refresh()
line: 170
ServiceDependentOsgiBundleXmlApplicationContext.refresh() line:
76
ApplicationContextCreator.run() line: 155
Thread.run() line: 595
------------------------------------------------------------------------------------------------------------------------------------------------------
Cheers,
Pavi
16 years, 11 months