Question about Rete Tree example with NotNode in "Drools JBoss Rules 5.0 Developers Guide"
by Tina Vießmann
Hi,
I'm working through the explanations about Rete Trees in chapter 12 of
"Drools JBoss Rules 5.0 Developers Guide" on page 264-265. I have a
problem in understanding the input of the NotNode.
The rule says:
when
$address : Address ( addressLine == "Rossa Avenue" )
not (
$account : Account ( balance < 100 ) and
Customer ( accounts contains $account )
)
then
...
The related figure shows:
1. The Address object being processed and a tuple will be created by a
LeftInputAdapterNode.
2. The tuple of 1. will be joined with the Account fact with no
constraints (so that there's a tuple of size two?).
3. The tuple of 2. will be joined with the Customer fact with the
restriction 'accounts contains $account'. (That results in a tuple with
size 3!?)
4. The tuple of 3. will then be processed by a RightInputAdapterNode.
5. The tuple/fact from 3. will be processed using a NotNode together
with the Address-tuple from 1.
I don't understand while the tuple from 1. will in step 2 be joined with
the Account fact. I would have expected something like:
1. // same
2. The Account fact will be processed and a tuple will be created by a
LeftInputAdapterNode.
3. The Customer fact will be joined with the Account tuple with the
constraint 'accounts contains $address'. Resulting in a tuple.
4. // somehow the tuple from step 3 will be negated and joined with the
tuple from step 1.
Could anybody explain to me why it's done the way its drawn in the book?
Thank you! :)
Tina
14 years, 1 month
What's wrong with this rule
by 赵侃侃
Hello,
With the help from the community I managed to get my first rule working, and
I'm trying to write my second rule on my own but it just doesn't seem to
work correctly.
Here is the scenario, what I want is to identify a pattern that there's no
EventB coming in within 2 minutes with a particular index value.
For example, EventB would have a property named index and assume the value
of index would be either 0 or 1.
Before firing the rules, I would manually insert facts of possibleIndex with
value 0 and 1 into the workingMemory.
Within 2 minutes, if there only comes one EventB with index valued 0 then
the system should report no EventB coming in with index value 1 in last 2
minutes.
Vice versa, in the case of only coming one EventB with index valued 1 then
the system should report no EventB coming in with index value 0 in last 2
minutes.
If within 2 minutes, there comes 2 EventB with both value 0 and 1 then
nothing should report.
Here is what I wrote, but it doesn't seem to work correctly.
I used a timer to fire this rule every 10 seconds because I don't think the
rule would run automatically if I don't add that. (not too sure though)
rule "no B in 2 minutes"
timer (0 10s)
when
possibleIndex( $index : index ) from entry-point "Event stream"
$p : PatternConsumer ( name == 'no B' && index == $index )
not ( EventB( index == $index && this after[0ms,2m] $p) over window:time(2m)
from entry-point "Event stream" )
then
PatternConsumer pc = new PatternConsumer( "no B", $index );
insert(pc);
System.out.println("no B in 2 minutes " + $index);
end
Best Regards,
Kevin Zhao
14 years, 1 month
Drools Flow in EJBs
by tizo
Hi there,
I have seen in chapter 6 of the documentation, that Drools Flow can be
configured to use JPA and transactions to persist the running states.
However, I am in a EJB where I obtain entity managers with a
@PersistenceContext annotation, and the transactions are managed by the
container, whereas in the example an EntityManagerFactory and a
TransactionManager are used.
Could I configure Flow in a direct way to be used by my EJB?
Thanks very much,
tizo
14 years, 1 month
Replacing Hand Written Rules
by Nirmal Fernando
Hi,
I am having a 5000+ hand written rules which is used in an open source
project.
I am searching for the reasons, me to be shifted to a rule engine like
Drools, instead of using hand written once.
Drools rules can be debugged that will be a plus point, isn't it? I would
love to get a list of benefits that I will be getting.
Thanks.
--
Best Regards,
Nirmal
C.S.Nirmal J. Fernando
Department of Computer Science & Engineering,
Faculty of Engineering,
University of Moratuwa,
Sri Lanka.
Blog: http://nirmalfdo.blogspot.com/
14 years, 2 months
OSGi: Unable to Import Packages from Core Bundle
by O.S.
Hi,
i have some troubles while trying to use some classes (e.g.: Commands) from
the org.drools.core Bundle. I can't import packages or set the core bundle
as required:
Import-Package:
org.drools.command.runtime;version="5.1.1",
...
Error in Manifest.MF: Bundle 'org.drools.core' exporting package
'org.drools.command.runtime' is unresolved
But the Bundle can't be unresolved because it is startet correctly. At
Bundle Validation he has an "Uses Package Conflict" concerning:
com.sun.tools.xjc.
Can someone help me or give me a tip?
Kind regards,
O.S.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/OSGi-Unable-to-Import...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 2 months
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, 2 months
Drools Bug: Custom Operator with Maps results in Mvel Error
by Uday Kodukula
Hello,
I'm not sure if this is a bug, but I'd like to check with the Drools experts
to see if it is.
I noticed this when creating my custom operator, which doesn't appear to
recognize values from Maps, but works fine with non Map based values.
I have created a custom comparison operator which takes in a parameter to
determine how to execute the comparison logic.
So for example, I am able to do the following:
id udaycompare[gt] 1
where id is an integer. So for the sake of clarity this is equivalent to "id
> 1".
Now, when I try to extract an integer from a HashMap called myMap, who has
an integer value for the key "someKey", I get an error raised by MVEL:
myMap["someKey"] udaycompare[gt] 1
Error thrown:
Unable to determine the used declarations.
[Error: unknown class or illegal statement: org.mvel2.ParserContext@1d87b85]
[Near : {... myMap["someKey"] udaycompare ....}]
^
It appears that Mvel doesn't like getting values from HashMap when working
with custom operators. I also tried an alternate way of getting that key
from the map as follows:
myMap.someKey udaycompare[gt] 1
but i still get the same error.
Any thoughts would be greatly appreciated.
Thanks,
Uday
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Bug-Custom-Ope...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 2 months
Question about Drools Spring, StatelessKnowledgeSession and globals
by Patrick van Kann
Hello,
I've been trying out the Spring integration package in Drools 5.1.1 and it
works really well, but I have run into one issue I can't figure out.
I've defined 2 knowledge sessions from the same knowledge base in the app
context - one stateless, one stateful but otherwise identical. They both
refer to a collaborator defined as a bean in the app context which is to be
used as a global in my rules. This is just an excerpt of my full Spring
context, the kbase definition itself is not an issue.
<bean id="applicantDao" class="com.acme.app.dao.impl.ApplicantDaoImpl" />
<drools:ksession id="statelessKSession" type="stateless"
name="statelessKSession" kbase="kbase">
<drools:script>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:script>
</drools:ksession>
<drools:ksession id="statefulKSession" type="stateful"
name="statefulKSession" kbase="kbase">
<drools:script>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:script>
</drools:ksession>
The issue is that this configuration works for the stateful but not the
stateless session, in the sense that the stateful session appears to have a
valid reference to the applicantDao object in the Globals object but the
stateless session doesn't.
@Test
public void testStatelessGlobal() {
Globals globals = statelessKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
@Test
public void testStatefulGlobal() {
Globals globals = statefulKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
The first test fails (the global variable is null) but the second passes. No
errors are thrown by Drools during the setup of the Spring container.
What am I doing wrong? Should I be able to define globals in this way for
stateless sessions? The XSD seems to indicate this is a valid configuration,
but it just doesn't work.
Is anyone else working with the Spring integration that can point out my
error here?
Many thanks,
Patrick
14 years, 2 months
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, 2 months
enabling rules based on interval events
by Jaroslav Pullmann
Dear all,
I am wondering whether and how the rule activation might be contextualized
in respect to the existence of a time slot signalled via interval events (with a
non-null duration). The static rule attributes (date-effective, date-expires) are
not applicable here, neither is the temporal operator "during", which requires
the existence of an explicit second event. The following approach demonstrates the
case but does not work (return value restrictions are not allowed to invoke time-
dependent functions):
rule "active time slot"
when
// partial condition met when there is a "live"/ongoing IntervalEvent "foo"
$system : System()
$ongoing: IntervalEvent( id == "foo", $system.currentTimeMillis <= ( msecstart + msecdur ) )
... further patterns
then
...
end
Many thanks for your suggestions!
Jaro
14 years, 2 months