Using Enums in LHS
by Marcus Ilgner
Hi list,
I'm having problems using Enums in the LHS of my rules.
Running this rule
> rule "demo"
> when
> $t : Transition( from == PlayerCharacter.STATE_IDLE,
> to == PlayerCharacter.STATE_GENERATING,
> state != TransitionState.REQUESTED )
> then
> System.out.println("The state is: " + $t.getState());
> end
actually results in the output
> The state is: REQUESTED
Am I doing something wrong?
I'm currently using the experimental 3.1.0M1 release.
Best regards
Marcus
17 years, 9 months
Package serialization question
by Fabio Genovese
Hello people,
this is my first thread here, so I apologize for whathever I miss.
I'm working on a threat detection engine, based on Drools 3.0.5
The rule structure (written in XML) is something like this:
<rule name="SWL1_d0e32">
<lhs>
<column identifier="vulnObject" object-type="SoftwareElement">
<literal field-name="name" evaluator="matches"
value=".*?Firefox"/>
<literal field-name="version" evaluator="==" value="0.8"/>
</column>
</lhs>
<rhs>assert ( new SoftwareThreat ( vulnObject,
SoftwareThreat.HIGH_RISK, SoftwareThreat.LOW_RISK ,
SoftwareThreat.LOW_RISK ));</rhs>
</rule>
Well, the problem is: serializing a rulebase with more than 30000 rules
like this.
This is the code:
PackageBuilderConfiguration conf = new
PackageBuilderConfiguration();
conf.setJavaLanguageLevel( "1.5" );
PackageBuilder builder = new PackageBuilder( conf );
Reader source = new InputStreamReader(
DroolsCIMAPI.class.getResourceAsStream( "/DroolsRuleset_TEST32000.xml" ) );
try {
builder.addPackageFromXml( source );
Package pkg = builder.getPackage();
FileOutputStream tempFile = new
FileOutputStream("./SWL1_package_TEST.bin");
ObjectOutput oos = new ObjectOutputStream(tempFile);
pkg.writeExternal(oos);
oos.flush();
oos.close();
tempFile.flush();
tempFile.close();
} catch (DroolsParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Actually the serialization works for relatively "small" rulesets
(<20000, increasing max heapsize to 256m)... But when using rulesets
over 30000 rules (eg. this sample test) the process hangs exactly in
"pkg.writeExternal(oos)" filling up the cpu to 100%... without writing,
obviously.
I checked the filesize of every serialized pakage (smaller), seeing that
they are always under 50Mb.
A note: without serialization, everything works fine.
Maybe a 50Mb limit somewere? Maybe I'm the newbest Drools user ever? :)
Thanks in advance.
Fabio,
Politecnico di Torino
Italy
17 years, 9 months
RE: [rules-users] Rule definition help
by Anstis, Michael (M.)
It seems inefficient to make calls to a database from a rule LHS as (I'm
guessing [Edson?]) that the Rete network can't be built\optimised around
an evaluated predicate (trying to use the correct language, but possibly
failing badly). Would the AlertCondition not already have these
properties populated? Making the rule simpler too:
Rule "Device not working (condition id = 4)"
when
$ac : AlertCondition (conditionId ==4, $eid : entityID,
$p : power, $at : ambTemperature)
then
log("Triggered Device not working alert for " + $eid +
", power=" + $p + ", ambient temperature=" + $at);
end
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Rahul Phadnis
Sent: 22 February 2007 21:12
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Rule definition help
I am very new to JBoss rules and I am trying to use it
for evaluating alert conditions.
I am asserting the AlertDefinition object as a fact
into the working memory.
The rules file would define a variety of alert
condition rules.
for example
rule "Device not working (condition id = 4)"
# the if part
when
alertDefinition : AlertDefinition (conditionID
== 4,
eid : entityID)
# here i would like to get the last power
reading from device
# with id == eid
eval (dao.getPower(eid).doubleValue() < 1000)
# then get temperature from the device
eval ((dao.getTemperature(eid) != null &&
dao.getTemperature(eid) > 50)
|| (dao.getAmbTemperature(eid) != null &&
dao.getAmbTemperature(eid) > 40)
)
then
# what do we do if the rule evaluates to true
log("Triggered Device not working alert for "
+ eid);
end
Here are my questions:
1. Am using the evals correctly? Can I possibly split
this into multiple rules to make it work better?
2. Can assign dao.getTemperature(eid) to a field. The
getTemperature call is expensive and doing it twice is
not right.
Any pointer would be appreciated.
-Rahul
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
17 years, 9 months
Help writing rules
by mike20043
Hi
I’m having a little problem in writing rules for my expert system. I know
that this is probably written out very badly and I really don’t have much of
an idea on what I’m doing in drools but I’m trying to get the following rule
to run
Rule "test body button check"
when
(Bodyc(brownb == "true") || Bodyc(grayb == "true") || Bodyc(lightgrayb ==
"true") || Bodyc(redb == "true") || Bodyc(orangeb == "true") ||
Bodyc(yellowb == "true") || Bodyc(whiteb == "true")) && (Bodyc(blackb ==
"false") || Bodyc(greenb == "false") || Bodyc(blueb == "false") ||
Bodyc(cyanb == "false") || Bodyc(pinkb == "false"))
then
System.out.println("body check pass");
end
if I remove the double and symbols in the middle plus everything after the
rule does run. basically I need the first half of the rule to evaluate true
and the second half to evaluate false but in the same rule. Any help would
be greatly appreciated.
Thanks in advance
mike
--
View this message in context: http://www.nabble.com/Help-writing-rules-tf3279750.html#a9121875
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 9 months
RE: [rules-users] debugging with 3.1M1 IDE?
by Anstis, Michael (M.)
My reply is being held by the list moderator (due to its size).
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Kris Verlaenen
Sent: 23 February 2007 13:13
To: Rules Users List
Subject: Re: [rules-users] debugging with 3.1M1 IDE?
> When I've stopped at a breakpoint in my project the "Working Memory"
and
> "Agenda" views are empty.
> I've tried with a clean install of Eclipse 3.2.1 and they're still
both
> empty.
Are you talking about standard java breakpoints in your java code or
rule
breakpoints? Rule breakpoints should always show the working memory and
agenda. When using standard java breakpoints, the views only show
something
if a WorkingMemory variable has been selected in the variables view.
> ... whereas when creating a project from scratch (i.e. importing
3.1-M1
> jars manually) the variable names show as "arg0" through "arg1",
> "arg2" etc. I am also shown some additional objects
> "DefaultKnowledgeHelper" and "DefaultFactHandle". Is this a
consequence of
> ShadowFacts?
Did you change something in the compiler settings so that variable names
are
preserved in the class files? The IDE should filter out those
additional
objects (as they are caused by the way it is implemented and usually not
relevant when debugging) based on their name, but seems like the names
of
the variables have been reset to defaults.
If possible, could you send me a self-contained eclipse project (you
don't
have to include drools jar or dependencies of course) that is
experiencing
these problems and a way to reproduce them? I'll then see what I can do,
because I can't determine the problem based on this explanation alone.
Kris
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
17 years, 9 months
RE: [rules-users] debugging with 3.1M1 IDE?
by Anstis, Michael (M.)
Kris,
I've attached my entire (3.2.1) workspace (c.5MB):-
The breakpoints were RHS rule breakpoints.
One thought: is the problem caused by the classes residing in one
project referenced by another?
Neither issues are critical.
Thanks in advance,
Mike
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Kris Verlaenen
Sent: 23 February 2007 13:13
To: Rules Users List
Subject: Re: [rules-users] debugging with 3.1M1 IDE?
> When I've stopped at a breakpoint in my project the "Working Memory"
and
> "Agenda" views are empty.
> I've tried with a clean install of Eclipse 3.2.1 and they're still
both
> empty.
Are you talking about standard java breakpoints in your java code or
rule
breakpoints? Rule breakpoints should always show the working memory and
agenda. When using standard java breakpoints, the views only show
something
if a WorkingMemory variable has been selected in the variables view.
> ... whereas when creating a project from scratch (i.e. importing
3.1-M1
> jars manually) the variable names show as "arg0" through "arg1",
> "arg2" etc. I am also shown some additional objects
> "DefaultKnowledgeHelper" and "DefaultFactHandle". Is this a
consequence of
> ShadowFacts?
Did you change something in the compiler settings so that variable names
are
preserved in the class files? The IDE should filter out those
additional
objects (as they are caused by the way it is implemented and usually not
relevant when debugging) based on their name, but seems like the names
of
the variables have been reset to defaults.
If possible, could you send me a self-contained eclipse project (you
don't
have to include drools jar or dependencies of course) that is
experiencing
these problems and a way to reproduce them? I'll then see what I can do,
because I can't determine the problem based on this explanation alone.
Kris
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
17 years, 9 months
RE: [rules-users] debugging with 3.1M1 IDE?
by Anstis, Michael (M.)
OK, thanks.
It's my turn for a problem though!
When I've stopped at a breakpoint in my project the "Working Memory" and "Agenda" views are empty. I've tried with a clean install of Eclipse 3.2.1 and they're still both empty.
Less importantly, when testing the plug-in with the bundled "HelloWorld" project created automatically from the "new Jboss Rules Project wizard" variables in the "Variable" view have the correct name (e.g. "m" and "message" for the "HelloWorld" example) whereas when creating a project from scratch (i.e. importing 3.1-M1 jars manually) the variable names show as "arg0" through "arg1", "arg2" etc. I am also shown some additional objects "DefaultKnowledgeHelper" and "DefaultFactHandle". Is this a consequence of ShadowFacts?
I am using 3.1-M1 of both the IDE plug-in and DROOLS.
Cheers,
Mike
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Kris Verlaenen
Sent: 22 February 2007 23:18
To: Rules Users List
Subject: Re: [rules-users] debugging with 3.1M1 IDE?
For those having trouble trying to debug rules using breakpoints,
I added some information about this on the wiki:
http://wiki.jboss.org/wiki/Wiki.jsp?page=DebugRulesEclipse
There already existed documentation on this in svn, but the 3.1M1 release
does not seem to include the latest documentation.
Kris
----- Original Message -----
From: "Mark Proctor" <mproctor(a)codehaus.org>
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Sent: Thursday, February 22, 2007 7:10 PM
Subject: Re: [rules-users] debugging with 3.1M1 IDE?
> Kris,
>
> Can you put some notes up on how to do this, maybe a screen shot or two,
> in the wiki.
>
> Thanks
>
> Mark
> Kris Verlaenen wrote:
>> Debugging rules in the IDE is a new 3.1M1 feature.
>> You should install this version of the plugin if you want to use it.
>> It is not available in 3.0.5.
>>
>> Kris
>>
>> ----- Original Message ----- From: "Francisco Brum"
>> <francisco.brum(a)link.pt>
>> To: "Rules Users List" <rules-users(a)lists.jboss.org>
>> Sent: Thursday, February 22, 2007 12:25 PM
>> Subject: RE: [rules-users] debugging with 3.1M1 IDE?
>>
>>
>>> I'm using 3.0.5, but I think I don't have the debug feature installed!
>>>
>>> I can create a drools project or rule or etc, but there is nothing about
>>> drools debug. Am I missing something????
>>>
>>> __________________________________
>>> Francisco Brum - francisco.brum(a)link.pt
>>> Link Consulting - http://www.link.pt/
>>> Tel.: 213 100 031
>>> Av. Duque D'Ávila, 23 4º Esq.
>>> 1000-138 Lisboa
>>>
>>> -----Original Message-----
>>> From: rules-users-bounces(a)lists.jboss.org
>>> [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Mark Proctor
>>> Sent: quinta-feira, 22 de Fevereiro de 2007 0:24
>>> To: Rules Users List
>>> Subject: Re: [rules-users] debugging with 3.1M1 IDE?
>>>
>>> Hey there Barry, great to hear from you.
>>>
>>> It's still drools too :) all the R&D project stuff is "drools". anything
>>> that is released and supported is jboss rules.
>>>
>>> I'm using 3.2.1 and it's fine, you need to turn on the caching stuff in
>>> the preferences, it uses that for debugging. You also need to run it as
>>> a drools debug session, not a standard java one. So you'll need to go
>>> into the launcher configuration to create new drools debug sessions.
>>>
>>> We'll start docs once towards the end, when everything has stabalised.
>>>
>>> Mark
>>> Barry Kaplan wrote:
>>>> I'm ready to get back into drools... whoops, I meant jboss rules. I
>>>> installed 3.1M1 into eclipse 3.2.1 and added the examples project. I
>>>> set a breakpoint in all RHS of an example and debugged the
>>>> corresponding java. I get no breaks hit and I get no updates in any of
>>>> the views.
>>>>
>>>> I couldn't find any help in the docs. Does the IDE still work in 3.1M1?
>>>>
>>>> -barry
>>>> _______________________________________________
>>>> 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
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>> _______________________________________________
>> 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
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
17 years, 9 months
RE: [rules-users] talking about new features...
by Anstis, Michael (M.)
Hi,
3.0.5 documentation states:-
You can access fields either by using the bean-name convention (so
"getType" can be accessed as "type"). For example, refering to our
Cheese class, the following : Cheese(type == ...) uses the getType()
method on the a cheese instance. You can also access non getter methods,
like "toString()" on the Object for instance (in which case, you do
Cheese(toString == ..) - you use the full name of the method with
correct capitalisation, but not brackets).
You're example Map(name == 'myName') only checked for the existence too.
Sorry if I misunderstood your requirement.
Cheers,
Mike
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Olenin,
Vladimir (MOH)
Sent: 22 February 2007 18:59
To: Rules Users List
Subject: RE: [rules-users] talking about new features...
This will just check if MyMapSubClass contains the entry (which
I think would not work anyways, since 'entrySet' does not comply to POJO
spec).
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Anstis,
Michael (M.)
Sent: 22 February 2007 12:14
To: Rules Users List
Subject: RE: [rules-users] talking about new features...
Can this not be achieved by using a Map's entrySet property?
$o : MyMapSubClass( entrySet contains 'myName' );
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Olenin,
Vladimir (MOH)
Sent: 22 February 2007 16:17
To: Rules Users List
Subject: [rules-users] talking about new features...
Hi,
Talking about new features to be included in the new
release, I think the most compelling might be the ability to use Maps as
facts (ie, from the point of view of a complete DROOLS newbie).
Technically POJO is a Map with some restricted functionality (can't
count properties, check for property existence, etc). Is it really a big
change? The rule formulation will remain the same from what I understand
and the LHS like
Map(name == 'myName')
Will simply mean any map object which has a key 'name'
and value for the key is 'myName'. The 'type matching' feature would be
kind of less useful in case Map fact is used, but this can probably
solved through introducing some default 'type' key which Map object
should have and in a very simplistic implementation just include 'type'
as a constraint.
Another alternative (which might probably be more
'backward compatible' with existing implementation) is to dynamically
generate POJOs from Map definition. 'type' or 'class' key will
correspond to a full qualified class name, all other keys found in the
map - POJOs properties. Or 'type' can stay 'anonymous' - might be useful
in some cases as well....
The 'weakly defined' fact objects might be quite useful
in some cases, eg when rules 'cross cut' business domain. Kind of
'dynamic rules' :-).
Vlad
17 years, 9 months
Adding DROOLS/JBoss Rules to classpath WITH LINE NUMBERS
by Francisco Brum
Hi everybody!
I have added the JBoss rules - drools 3.0.5 to an existing eclipse project.
I have already solved the problem of adding the source code of drools to the debugging of eclipse, using the first indication of Kris, witch is quoted in the end!
Now the problem it's being able to debugging using the source of drools, but having the line number, so that eclipse can follow the exact actions of the source.
Can anybody help me?!
Yes, the drools jars do not contain any source by default (to limit the size of
the jars).
There are two ways to use the source of these classes though:
* When you are trying to debug an application in eclipse, and you open the
debug dialog (right click your Java main class, select Debug As -> Debug ...),
there is a tab there you can use to add sources. If you download the sources
from svn and import these as Java projects in eclipse, you can just add those
projects to the source lookup path. I added a screenshot to help you out with
that.
* If you add the sources to the drools jars directly (in the same dir as the
corresponding class files, so not in a separate src dir or something like
that), those sources will be found automatically as well. So rebuilding those
jars and adding the sources should do the trick for all your projects at once.
Kris
Thanks in advance for the attention of this problem.
__________________________________
Francisco Brum - francisco.brum(a)link.pt <mailto:rui.arrenega@link.pt>
Link Consulting - http://www.link.pt/ <http://www.link.pt/>
Tel.: 213 100 031
Av. Duque D'Ávila, 23 4º Esq.
1000-138 Lisboa
17 years, 9 months