Drools 5 - how create Logger for Template File based rules?
by chris@twc
I'm trying to figure out how I can create a Logger to log rule activations
for my Template File code. I followed the examples to successfully create a
Logger for DRL and Decision Table examples. Apparently, to create a Logger,
the KnowledgeRuntimeLoggerFactory methods take a
KnowledgeRuntimeEventManager type, which StatefulKnowledgeSession
implements. But, for the Template File examples, the StatefulSession from
the "unstable" drools-core *does not* implement this interface. SEE the code
examples below - how do I create a Logger for my Template File code?
//#### DRL FILE & EXCEL FILE EXAMPLE FOR CREATING A SESSION AND FIRING THE
RULES:
//#### CREATING A RULES LOGGER WORKS
// populate working memory
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(...[DRL or DTABLE resources]...);
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
// create session
StatefulKnowledgeSession rulesSession =
knowledgeBase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger rulesLogger =
KnowledgeRuntimeLoggerFactory.newConsoleLogger(rulesSession);
//<<CREATE LOGGER!
FactHandle factHandle = rulesSession.insert(myFact);
// fire the rules
rulesSession.fireAllRules();
//#### TEMPLATE FILE EXAMPLE FOR CREATING A SESSION AND FIRING THE RULES:
//#### CREATING A RULES LOGGER DOES NOT COMPILE!
// populate working memory
ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
InputStream spreadsheetStream = ...
InputStream templateFileStream = ...
String drl = converter.compile(spreadsheetStream, templateFileStream, 3, 3);
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(drl));
RuleBase templateRuleBase = RuleBaseFactory.newRuleBase();
templateRuleBase.addPackage(builder.getPackage());
// create session
StatefulSession rulesSession = templateRuleBase.newStatefulSession();
KnowledgeRuntimeLogger rulesLogger =
KnowledgeRuntimeLoggerFactory.newConsoleLogger(rulesSession);//<<DOESN'T
COMPILE!
FactHandle factHandle = rulesSession.insert(myFact);
// fire the rules
rulesSession.fireAllRules();
--
View this message in context: http://www.nabble.com/Drools-5---how-create-Logger-for-Template-File-base...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 5 months
[drools-solver] help for defining my drools model / moves
by Laurent Michenaud
Hi,
Here is my test :
I have an appointment to schedule on a customer availability.
I have a list of customer availabilities.
A customer availability is a period.
An appointment needs an exact number of persons.
A resource is composed of persons ( between 1 and n ) and has availabilities too.
The problem is to schedule the appointment : it has to choose the
right resource availabilities that matches one of the customer availabilities and
the total number of persons inside chosen resources must match exactly the
needed number of persons of the appointment.
My moves are for the moment :
- Change the customer availability.
- Add a resource to the list of chosen resources.
My init is :
- One of the customer availability is taken
- 0 resource taken.
First, i don't know if my model and my init are ok.
Secondly, the solver does the following :
- At the beginning, the score is bad because there is no resource.
So, it begins adding resource and the score is getting better
but when it changes the availability, the score gets very bad either because
the chosen resources don't match the new availability or it has no resource
inside. The solver doesnot seem to interest in the new chosen availibity with no
resource, but i wish it does.
Thanks for your remarks/help
Best regards
15 years, 6 months
stream mode and DroolsStreamUtils
by Jaroslaw Kijanowski
Hi,
I'm using sliding windows (hence stream mode).
Here's my rule:
declare Sensor
@role (event)
end
rule 'r'
when
Number( dv:doubleValue > 1 ) from accumulate(
Sensor( $v : value ) over window:length( 2 ),
average( $v ) )
then
System.out.println(dv);
end
Here's my class:
++++++++++++++++++++++++++++++++++++++++++++++
public class CEPTest {
public static void main(String[] args) throws Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("cep.drl"),
ResourceType.DRL);
if (kbuilder.getErrors().size() > 0) {
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBaseConfiguration kbaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseConfig.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeBase kbase2 = (KnowledgeBase)
DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(kbase), null);
final StatefulKnowledgeSession ksession =
kbase2.newStatefulKnowledgeSession();
System.out.println("T1");
ksession.insert(new Sensor(1.0));
ksession.fireAllRules();
System.out.println("T2");
ksession.insert(new Sensor(2.0));
ksession.fireAllRules();
System.out.println("T3");
ksession.insert(new Sensor(3.0));
ksession.fireAllRules();
ksession.dispose();
}
}
++++++++++++++++++++++++++++++++++++++++++++++
The output is (as expected):
+++++++++++++++
T1
T2
1.5
T3
2.5
+++++++++++++++
I'm wondering why I have to use DroolsStreamUtils to get a knowledge
base? When I use kbase (which didn't went through DroolsStreamUtils)
instead of kbase2 to create a new session, the output will be:
+++++++++++++++
T1
T2
2.0
T3
3.0
+++++++++++++++
Thanks,
Jarek
15 years, 6 months
Re: [rules-users] How to retrieve the Rule names in the drools rule file
by Amila Silva
Hi Laun,
Yes now it works fine thanks.
earlier case it was like
rule "Test Exists" enabled false
@Purpose (" WORD ")
when
after removing "enabled false" tag it works fine.
Amila Silva
--- @ WiseStamp Signature <http://www.wisestamp.com/email-install>. Get it
now <http://www.wisestamp.com/email-install>
On Tue, Jun 30, 2009 at 5:02 PM, Wolfgang Laun <wolfgang.laun(a)gmail.com>wrote:
> Notice that the metadata annotations must precede 'when', not 'then'.
>
> rule x
> @Purpose( "purpose of x" )
> when
> ...
> then
> ...
> end
>
> You may use more than one such metadata, e.g.,
>
> rule x
> @Purpose( "purpose of x" )
> @Rulename( "this rule is called 'x'" )
> when
> ...
>
> -W
>
>
>
> -W
>
>
> On 6/30/09, Amila Silva <amilac(a)hsenidmobile.com> wrote:
>>
>> hi Laun,
>> I tries with your solutions but i couldn't find the way to configure
>> the meta - data part in rule file to read.
>> I came across with following issues when trying to read it from a given
>> code.
>>
>> [12,2]: [ERR 102] Line 12:2 mismatched input 'AT' expecting 'then' in
>> rule "create new Instance"
>> Exception in thread "main" java.lang.IllegalArgumentException: Could
>> not parse knowledge.
>>
>> i think this might be a issue with a @ sign in the rule file but i think
>> i this kinda of annotations will help to specify the
>> main rule name. Or is there any way to identify or filter out the main
>> rule name from file.
>>
>> BTW your this solution help me a lot.
>> thanks
>>
>>
>>
>>
>>
>>
>> On Tue, Jun 30, 2009 at 2:44 PM, Wolfgang Laun <wolfgang.laun(a)gmail.com>wrote:
>>
>>> You might use the API to retrieve all rules in your KnowledgeBase
>>>
>>> KnowledgeBase kBase = ...;
>>>
>>> for( KnowledgePackage kp: kBase.getKnowledgePackages() ){
>>> for( Rule r: kp.getRules() ){
>>> String name = r.getName();
>>> String purpose = r.getMetaAttribute( "Purpose" ); // or
>>> similar - see below
>>> System.out.println( "Rule " + name + ", purpose: " + purpose
>>> );
>>> }
>>> }
>>>
>>> Rule names may not provide sufficient information. You could add
>>> arbitrary metadata to your rules, e.g.,
>>>
>>> rule "pqx"
>>> @Purpose( "locates very interesting facts" )
>>> when
>>> ...
>>> end
>>>
>>> -W
>>>
>>>
>>>
>>> 2009/6/30 Amila Silva <amilac(a)hsenidmobile.com>
>>>
>>>>
>>>> hi everyone,
>>>> I have requirement like to retrieve the RULE names in a given rule
>>>> files. and also is there a way to map a rule names from a multiple rule
>>>> files.
>>>> i want to load the or show the available rules and system user to
>>>> select the required rule for his program.
>>>> let me know the possible way of doing this.
>>>>
>>>>
>>>> --
>>>> Thanks,
>>>> Regrads,
>>>>
>>>> Amila Silva,
>>>> Associate Software Engineer
>>>>
>>>> hSenid Mobile Solutions
>>>>
>>>> Phone :
>>>> +94-77-9983894
>>>> Fax :
>>>> +94-11-2673 845
>>>>
>>>> Web:
>>>> http://www.hSenid.com <http://www.hsenid.com/>
>>>>
>>>> Make it Happen
>>>>
>>>>
>>>> http://www.hSenidMobile.com <http://www.hsenidmobile.com/>
>>>>
>>>> Enabling the Mobile World
>>>>
>>>>
>>>> Disclaimer: This email and any files transmitted with it are
>>>> confidential and intended solely for the use of the individual or entity to
>>>> which they are addressed. The content and opinions contained in this email
>>>> are not necessarily those of hSenid Software International. If you have
>>>> received this email in error please contact the sender.
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users(a)lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>> --
>>
>>
>
--
Thanks,
Regrads,
Amila Silva,
Associate Software Engineer
hSenid Mobile Solutions
Phone :
+94-77-9983894
Fax :
+94-11-2673 845
Web:
http://www.hSenid.com
Make it Happen
http://www.hSenidMobile.com
Enabling the Mobile World
Disclaimer: This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to which they
are addressed. The content and opinions contained in this email are not
necessarily those of hSenid Software International. If you have received
this email in error please contact the sender.
15 years, 6 months
RuleBase.newStatefulSession() and EventProcessingOption
by Julien Nicoulaud
Hi, I am trying to upgrade a system from Drools 4.0.7 to Drools 5.0.1 to
use Drools Fusion temporal operators.
With used to start our rule engine this way:
RuleBase ruleBase = RuleBaseFactory.newRuleBase(new
RuleBaseConfiguration(ourClassloader));
WorkingMemory workingMemory = ruleBase.newStatefulSession();
Now this seems deprecated reading the Drools fusion documentation...
Should I give up RuleBase for KnowledgeBase to be able to start the rule
engine in "Stream" event processing mode ?
Thanks for your help !
Julien Nicoulaud
OW2 Consortium
15 years, 6 months
How to retrieve the Rule names in the drools rule file
by Amila Silva
hi everyone,
I have requirement like to retrieve the RULE names in a given rule files.
and also is there a way to map a rule names from a multiple rule files.
i want to load the or show the available rules and system user to select
the required rule for his program.
let me know the possible way of doing this.
--
Thanks,
Regrads,
Amila Silva,
Associate Software Engineer
hSenid Mobile Solutions
Phone :
+94-77-9983894
Fax :
+94-11-2673 845
Web:
http://www.hSenid.com
Make it Happen
http://www.hSenidMobile.com
Enabling the Mobile World
Disclaimer: This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to which they
are addressed. The content and opinions contained in this email are not
necessarily those of hSenid Software International. If you have received
this email in error please contact the sender.
15 years, 6 months
How to import drl files to Guvnor
by kavuri
Hi,
I am new to guvnor web based application.we have lot of rule files(DRL)
developed in our project.until now we are just manually writing the code in
the drl files.as we have lots of rules it becomes hard to maintain.so we
trying to shift those drl files into guvnor for effctive management of
rules.
i got guvnor war file and deployed in the tomcat 6.0.it is working fine
.now i need to inport all my drl files into that system.i want to sink
guvnor with my project.
anyone please help me out ....
Thanks in advance....
regards,
Vamsi Krishna.Kavuri.
15 years, 6 months
MVEL 2.0 bug in 'with' block
by Dan Seaver
I think there may be a bug in MVEL 2.0. If I do the following, I get a
runtime exception:
with (actionCodeSecurity = new ActionCodeSecurity()) {
securityCategory = securityCategory,
actionCode = "AA",
visitTypeConstraint = 1,
visitTypeList = "IP, OP"
}
However, if I remove the comma between IP and OP it works:
visitTypeList = "IP OP"
Also, it works fine if I do all my assignments without the 'with' clause:
actionCodeSecurity = new ActionCodeSecurity()
actionCodeSecurity.securityCategory = securityCategory
actionCodeSecurity.actionCode = "AA"
actionCodeSecurity.visitTypeConstraint = 1
actionCodeSecurity.visitTypeList = "IP, OP"
I'm using the version of MVEL that shipped with Drools 5.0 Final build,
Eclipse Workbench, May 19, 2009.
--
View this message in context: http://www.nabble.com/MVEL-2.0-bug-in-%27with%27-block-tp24261697p2426169...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 6 months
Drolls 4.0.7 exception org.drools.RuntimeDroolsException: org.drools.base.mvel.MVELEvalExpression@1cf7491 while using matches operator
by Kumar, Ravendra
Hi All,
I am using Drools 4.0.7 and when I tried to use "matches" operator it is giving following exception
The rule logic is following
package com.logica.heca.lpr.rule;
import com.logica.heca.lpr.domain.*;
import com.logica.heca.lpr.domain.contact.*;
import com.logica.heca.lpr.domain.ruleengine.*;
import java.util.*;
rule "CPR_RULE_222222"
dialect "mvel"
when
INDUD : ContactVO();
eval(INDUD.districtCode matches "((UX)[ACMR][[A-Z0-9]]{3})|([A-Z0-9]++)")
then
System.out.println("hello");
End
Note: INDUD.districtCode returns String value.
While if I changed matches operator to java method this work fine
eval(INDUD.getDistrictCode().matches("((UX)[ACMR][[A-Z0-9]]{3})|([A-Z0-9]++)"));
any of your esteemed help will highly be appreciated
Thanks
Ravendra Kumar
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
org.drools.RuntimeDroolsException: org.drools.base.mvel.MVELEvalExpression@1cf7491 : java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:82)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:148)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:911)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
at org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:143)
at com.logica.heca.lpr.rule.RuleTester.main(RuleTester.java:44)
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:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at org.drools.base.mvel.MVELEvalExpression.evaluate(MVELEvalExpression.java:42)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:77)
... 18 more
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks and Regards,
Ravendra kumar
IT Consultant
__________________________________
Logica - Releasing your potential
Margrethepladsen 4, 8000 Århus C
Danmark
T: +45 2518 8864
E-mail: ravendra.kumar(a)logica.com <mailto:hans.knudsen@logica.com>
www.logica.dk <http://www.logica.dk/>
Please help Logica to respect the environment by not printing this email / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail / Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei die Umwelt zu schuetzen / Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
15 years, 6 months