About for and inheritance
by Chris Woodrow
Hi,
I recently find out a few issues using for, and I wanted to share it with
you. I made a simple exemple to illustrate my purpose.
My classes are (I did not represent accessors & constructors):
public class Cheese {
protected String name;
}
public class FrenchCheese extends Cheese{
private String smell;
}
public class Person {
private Cheese likes;
}
Here is my rule set :
package rules
rule "likes cheese"
when
$person : Person ()
Cheese( ) from $person.getLikes()
then
System.out.println("likes cheese");
end
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
First test :
Cheese cheese = new FrenchCheese("good", "camembert");
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
Wich is expected...
Second test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
That's the first strange thing. As far as I am concerned, rule "likes french
cheese" should not match (since a Cheese is not a FrenchCheese).
I made a change to the second rule :
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( smell == "good" ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
Third test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
output :
It throwed an exception : Exception in thread "main"
java.lang.ClassCastException: rules.Cheese
I am not saying the ClassCastException is not to expect in such a case but I
think I would simply expect it not to match (as far as a Cheese is not a
FrenchCheese).
Chris
13 years, 10 months
Upload an existing .drl for the Guvnor dynamically
by Vandewilly
Is there any api available that allows me to load an existing file drl for
the Guvnor repository. In my case, I can not upload through the web
interface, only in a dynamic way through a java class.
--
Vandewilly Oliveira
13 years, 11 months
Drools 4.0, Support for multiple pattern in accumulate source pattern
by Juergen
It appears as if accumulate does support only a single pattern CE as
source pattern, e.g.:
Number() from accumulate(
Cheese(
price : price
),
sum( price )
)
Is it possible to have more than one pattern in the source pattern, e.g.:
Number() from accumulate(
Cheese(
price : price,
type : type
)
Person(
favouriteCheese == type,
age > 30
),
sum( price )
)
The same could be said for collect, but there the problem to specify
which item of a matching tuple is to be collected, but this could be
handled recreating collect via accumulate, e.g.:
Collection() from accumulate(
cheese : Cheese(
type : type
)
Person(
favouriteCheese == type,
age > 30
),
collect( cheese )
)
13 years, 11 months
forall not delivering as expected
by Wolfgang Laun
Given classes
class Triangle { int a, b, c;... }
class Quadrangle { int a, b, c, d;... }
with appropriate getters (but no hashCode or equals) and these facts
Triangle( 3, 3, 3 )
Triangle( 3, 3, 3 ) // a duplicate, intentional
Quadrangle ( 3, 4, 5, 6 );
the rule
rule "all equilaterals have a 'fitting' quadrangle"
when
forall( Triangle( $a: a, b == $a, c == $a )
Quadrangle( a == $a || b == $a || c == $a || d == $a ) )
then // ...
end
works as expected - it fires.
But the rule
rule "all equilaterals have a duplicate"
when
forall( $t: Triangle( $a: a, b == $a, c == $a )
Triangle( this != $t, a == $a, b == $a , c == $a ) )
then // ...
end
does not fire, not even when I omit this != $t. Why?
Do I have a white spot in my grey cells? Please tint my taint...
-W
14 years
BuildError: Unable to resolve ObjectType
by BS
Hi all,
I'm quite new to Drools and have a problem with the guided editor of the
Eclipse plugin. I'm using Drools 5.0.1.
These are the two BuildErrors for "TestGuided.brl" in Eclipse:
1) BuildError: Unable to build expression for 'consequence': Failed to
compile: 1 compilation error(s): - (1,1) unqualified type in strict mode
for: p ' update( p );
2) BuildError: Unable to resolve ObjectType 'Produkt'
In "drools.package" I have all necessary imports and also the package
statement. This is the BRL source of "TestGuided.brl":
<rule>
<name>TestGuided</name>
<modelVersion>1.0</modelVersion>
<attributes/>
<metadataList/>
<lhs>
<fact>
<factType>Produkt</factType>
<boundName>p</boundName>
</fact>
</lhs>
<rhs>
<modify>
<fieldValues/>
<variable>p</variable>
</modify>
</rhs>
</rule>
When I use the generated DRL output of the guided editor in a DRL file, I do
not get any error message. The DRL file looks like this and compiles
perfectly in Eclipse:
package com.test
rule "TestGuided"
dialect "mvel"
when
p : Produkt( )
then
update( p );
end
Adding the BRL from above to Guvnor does not throw any error. The BRL
validates and compiles perfectly in Guvnor.
So, why is it only in the guided editor of Eclipse not working but in the
guided editor of Guvnor as well as DRL file? Maybe something in my
configuration is errorneous?
Any help is appreciated, many thanks
Bernd
--
View this message in context: http://n3.nabble.com/BuildError-Unable-to-resolve-ObjectType-tp702633p702...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
Drools and Java EE
by ljnelson
Hello; I've made a JCA resource adapter for Drools.
I've had to hack quite a bit to get it so that the KnowledgeAgent- and
resource-scanning-related parts don't use Threads, but, instead, use the
JCA-supplied WorkManager and BootstrapContext#createTimer() for asynchronous
operations (like resource scanning and notifying).
Here are some changes it would sure be nice to see, that I needed to hack
around in order to make it so that a KnowledgeAgent-produced KnowledgeBase
could be shared by Java EE components in a specification compliant manner:
1. ResourceChangeNotifierImpl#ProcessChangetSet is an inner class that is
marked as public static, but which has a package-protected constructor. I
have to create a new instance of this in order to create a
ResourceChangeNotifierImpl subclass that doesn't use threads. I hope this
constructor could be made public instead. Right now I'm calling
setAccessible(true). Yecch.
2. ResourceFactory#setFactoryService(): sure do wish this were public, or
that there were another way to install a ResourceFactoryService. I need to
do this so that the scanner and notifier are under my control (and don't use
Threads, but instead use Timers as provided by the JCA BootstrapContext
class). It appears that I do have some control here in Drools 5.1 with the
(undocumented) ServiceRegistry interface (how do I get an instance of it?
what does it do? is it used pervasively?), but I don't know, since it's
undocumented, whether it's the preferred way to do this sort of thing or
not.
3. All this indirection is really quite clunky, especially given the
META-INF/services facility. Was there a good reason this was not used? I'm
sure there was something, because having to consult a factory for a service
to get a provider to produce an instance of something is a bit much.
Hacking around those limitations, I was able to produce a Drools resource
adapter that vends KnowledgeBase instances as its user connection factories.
This means to use it in a spec-compliant manner, you do this in your
stateless (or stateful) session bean:
@Resource
private KnowledgeBase kb;
...and you get injected a wrapper KnowledgeBase that uses the Java EE
container's JCA machinery to invoke operations on the shared KnowledgeBase.
Is this something that would be interesting to other people? If so I am
happy to open source it.
Thanks for a great toolkit.
Best,
Laird
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-and-Java-EE-tp...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
JBoss Rule Trace feature with 5.0
by Kinjal Khandhar
Hi All,
Can anybody help me with Drools Audit Log(Rule Trace) feature.
My goal is to check which rule got executed,in what sequence and which
conditions got evaluated and which did not.
Any help/pointers greatly appreciated.
Thanks in advance.
Regards,
Kinjal
14 years
Creating a KnowledgeBase using a KnowledgeAgent, KnowledgeAgentConfiguration and KnowledgeBaseConfiguration
by Tina Vießmann
Hi,
I want to create a KnowledgeBase using stream processing mode, getting
its resources from an change-set xml and getting the updated when
resources are changed. So far I'm aware I need a KnowledgeAgent and a
configuration for the kagent and the kbase.
My code is:
// create knowledge base
// knowledge base configuration
KnowledgeBaseConfiguration kbaseConf =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseConf.setOption(EventProcessingOption.STREAM);
// knowledge base
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConf);
// create knowledge agent
// create knowledge agent configuration
KnowledgeAgentConfiguration kagentConf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
//enable incremental knowledge base build
kagentConf.setProperty("drools.agent.newInstance", "false");
//create knowledge agent
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("AITS CEP Engine Agent",
kbase, kagentConf);
// apply change-set XML to knowledge agent
kagent.applyChangeSet(ResourceFactory.newClassPathResource("changeset.xml"));
// get updated knowledge base object
kbase = kagent.getKnowledgeBase();
// create session
session = kbase.newStatefulKnowledgeSession();
Can it be done in a more compact way?
Thank you! :)
Tina
14 years
no visitor implementation for : class org.drools.rule.TypeDeclaration
by Tina Vießmann
Hi,
I'm getting a two red highlighted outputs in eclipse if I modify my
rules file during run time. Besides that the modifications seem to work.
What does it mean?
The full output I get when the resource change is detected is listed
below. The bold lines are the concerned ones.
Thanks for any help! :)
Tina
[2010:08:235 21:08:296:debug] ResourceChangeScanner attempt to scan 1
resources
[2010:08:235 21:08:296:debug] ResourceChangeScanner modified
resource=[ClassPathResource path='testRule.drl'] : 1282559206875 :
1282591705000
[2010:08:235 21:08:296:debug] ResourceChangeNotification received
ChangeSet notification
[2010:08:235 21:08:296:debug] ResourceChangeScanner thread is waiting
for 10 seconds.
[2010:08:235 21:08:296:debug] ResourceChangeNotification processing
ChangeSet
[2010:08:235 21:08:296:debug] ResourceChangeNotification ChangeSet
modified resource=[ClassPathResource path='testRule.drl'] for
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4
[2010:08:235 21:08:296:debug] KnowledgeAgent received ChangeSet changed
notification
[2010:08:235 21:08:296:info] KnowledgeAgent applying ChangeSet
[2010:08:235 21:08:296:debug] KnowledgeAgent removing mappings for
resource=[ClassPathResource path='testRule.drl'] with unsubscribe=true
[2010:08:235 21:08:296:debug] KnowledgeAgent notifier unsubscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:296:debug] ResourceChangeNotification unsubscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:296:debug] ResourceChangeScanner unsubcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@13576a2 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:296:debug] ResourceChangeScanner
resource=[ClassPathResource path='testRule.drl'] now has no subscribers
[2010:08:235 21:08:296:debug] KnowledgeAgent rebuilding KnowledgeBase
using ChangeSet
[2010:08:235 21:08:296:info] KnowledgeAgent performing an incremental
build of the ChangeSet
[2010:08:235 21:08:296:debug] ResourceChangeNotification thread is
waiting for queue update
[INFO ] 21:30:10,375 [main] "Event retracted." (DRL Logger)
[2010:08:235 21:08:453:debug] KnowledgeAgent: Diffing:
[ClassPathResource path='testRule.drl']
[INFO ] 21:30:10,453 [main] "Event retracted." (DRL Logger)
[2010:08:235 21:08:500:debug] BinaryResourceDiffProducerImpl: [Rule
name=delete parameter values, agendaGroup=MAIN, salience=0,
no-loop=false] is not present anymore. Adding to removed list.
[2010:08:235 21:08:500:debug] BinaryResourceDiffProducerImpl:
org.drools.rule.Function@67fe80 did change. Marking as removed so it new
version could be added later.
[2010:08:235 21:08:500:debug] BinaryResourceDiffProducerImpl: Comparing
[Rule name=Warning threshold exceeded to many times, agendaGroup=MAIN,
salience=0, no-loop=false] against [Rule name=Warning threshold exceeded
to many times, agendaGroup=MAIN, salience=0, no-loop=false]
*no visitor implementation for : class org.drools.rule.TypeDeclaration :
org.drools.rule.TypeDeclaration@95f290
no visitor implementation for : class org.drools.rule.TypeDeclaration :
org.drools.rule.TypeDeclaration@bfd66a*
[2010:08:235 21:08:546:debug] BinaryResourceDiffProducerImpl: [Rule
name=Warning threshold exceeded to many times, agendaGroup=MAIN,
salience=0, no-loop=false] didn't change. Removing from diff package and
adding it to unmodified list.
[2010:08:235 21:08:546:debug] BinaryResourceDiffProducerImpl: Comparing
[Rule name=Insert Watcher Into Knowledge Base, agendaGroup=MAIN,
salience=0, no-loop=false] against [Rule name=Insert Watcher Into
Knowledge Base, agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:546:debug] BinaryResourceDiffProducerImpl: The rules
have different LHS
[2010:08:235 21:08:546:debug] BinaryResourceDiffProducerImpl: Comparing
[Rule name=Add Event to Watcher Set, agendaGroup=MAIN, salience=0,
no-loop=false] against [Rule name=Add Event to Watcher Set,
agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:546:debug] BinaryResourceDiffProducerImpl: The rules
have different LHS
[2010:08:235 21:08:546:debug] KnowledgeAgent: Removing: [Rule
name=delete parameter values, agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:546:debug] KnowledgeAgent removing Rule=[Rule
name=delete parameter values, agendaGroup=MAIN, salience=0,
no-loop=false] from package=net.eads.astrium.aits.cep.rules
[2010:08:235 21:08:546:debug] KnowledgeAgent: Removing:
org.drools.rule.Function@67fe80
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=[Rule name=Warning threshold exceeded to many times,
agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:562:debug] KnowledgeAgent obtaining pkg
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=[Rule name=Insert Watcher Into Knowledge Base,
agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:562:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@13576a2 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=[Rule name=Add Event to Watcher Set,
agendaGroup=MAIN, salience=0, no-loop=false]
[2010:08:235 21:08:562:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=org.drools.rule.TypeDeclaration@17dff15
[2010:08:235 21:08:562:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=org.drools.rule.TypeDeclaration@f5cbda
[2010:08:235 21:08:562:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent mapping
resource=[ClassPathResource path='testRule.drl'] to
KnowledgeDefinition=org.drools.rule.Function@11a59ce
[2010:08:235 21:08:562:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b40ec4 to
resource=[ClassPathResource path='testRule.drl']
[2010:08:235 21:08:562:debug] KnowledgeAgent adding
KnowledgeDefinitionsPackage net.eads.astrium.aits.cep.rules
[2010:08:235 21:08:578:info] KnowledgeAgent incremental build of
KnowledgeBase finished and in use
[2010:08:235 21:08:578:debug] KnowledgeAgent finished rebuilding
KnowledgeBase using ChangeSet
14 years