[rules-users] Drools 5 - how create Logger for Template File based rules?

Wolfgang Laun wolfgang.laun at gmail.com
Sun Jul 5 13:37:21 EDT 2009


It does contain the essential steps I was suggesting. Please try it, and
if there are problems, we'll take a closer look...

-W

On 7/3/09, chris at twc <christopher.mcfarland at twc.state.tx.us> wrote:
>
>
> Wolfgang, is this correct? Thx
>
> <pre>
>    // populate working memory
>    ExternalSpreadsheetCompiler converter = new
> ExternalSpreadsheetCompiler();
>    InputStream spreadsheetStream = ...
>    InputStream templateFileStream = ...
>    String drl = converter.compile(spreadsheetStream, templateFileStream, 3,
> 3);
>    Resource drlResource = ResourceFactory.newReaderResource(new
> StringReader(drl));
>    KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>    kbuilder.add(drlResource, ResourceType.DRL);
>    KnowledgeBuilderErrors errors = kbuilder.getErrors();
>    if (errors.size() > 0) {
>        for (KnowledgeBuilderError error: errors) {
>            System.err.println(error);
>        }
>        throw new IllegalStateException("Could not parse knowledge from
> template example");
>    }
>    KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
>    knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
>    // create session
>    StatefulKnowledgeSession rulesSession =
> knowledgeBase.newStatefulKnowledgeSession();
>    KnowledgeRuntimeLogger rulesLogger =
> KnowledgeRuntimeLoggerFactory.newConsoleLogger(rulesSession);
> //&lt;&lt;CREATE LOGGER!
>    FactHandle factHandle = rulesSession.insert(myFact);
>    // fire the rules
>    rulesSession.fireAllRules();
> </pre>
>
>
> Wolfgang Laun-2 wrote:
> >
> > You can use a KnowledgeBuilder with template-derived DRL-resources and
> set
> > up your KnowledgeBase from its results the same way you do it with plain
> > .drl-files. Obtain a StatefulKnaowledgeSession and pass this to
> > the KnowledgeRuntimeLoggerFactory, as in your first code sample.
> > -W
> >
> >
> > On 6/30/09, chris at twc <christopher.mcfarland at twc.state.tx.us> wrote:
> >>
> >> 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: Drools 5 - how create Logger for Template
> >> File based
> >> rules?<
> http://www.nabble.com/Drools-5---how-create-Logger-for-Template-File-based-rules--tp24277191p24277191.html
> >
> >> Sent from the drools - user mailing list
> >> archive<http://www.nabble.com/drools---user-f11823.html>at Nabble.com.
> >>
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >>
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Drools-5---how-create-Logger-for-Template-File-based-rules--tp24277191p24327369.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090705/6ad57370/attachment.html 


More information about the rules-users mailing list