[rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

Pritham infinity2heaven at gmail.com
Tue Jan 26 14:07:29 EST 2010


I have a folder in classpath:

dsl/global.dsl
rules/section-A.dslr
rules/section-A/page-1.dslr

I create a knowledge base like this:

public KnowledgeBase createKnowledgeBase() throws DroolsParserException,
IOException {

    KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory
            .newKnowledgeBuilder();

        knowledgeBuilder.add(ResourceFactory
                .newClassPathResource("dsl/global.dsl"),
                ResourceType.DSL);
        knowledgeBuilder.add(ResourceFactory
                .newClassPathResource("rules/section-A.dslr"),
                ResourceType.DSLR);
        knowledgeBuilder.add(ResourceFactory
                .newClassPathResource("rules/section-A/page-1.dslr"),
                ResourceType.DSLR);   

    if (knowledgeBuilder.hasErrors()) {
        throw new RuntimeException(knowledgeBuilder.getErrors().toString());
    }

    KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
   
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());

    return knowledgeBase;
}

// code
knowledgeBase = createKnowledgeBase();
session = knowledgeBase.newStatefulKnowledgeSession();
// insert facts
session.fireAllRules();
session.dispose();	

The above code works and I can get a unit test to work that processes rules
accordingly. I can see my dslr converting to a drl using the "drl viewer"
correctly (provided I temporarily place the dsl file in the same location
since expander doesn't accept a relative path).

The problem, however is when I use a change-set.xml and a KnowledgeAgent,
things don't work 

code for loading via knowledgeAgent

public static KnowledgeBase loadKnowledgeBase() throws
DroolsParserException, IOException {
    agent = KnowledgeAgentFactory.newKnowledgeAgent("msll agent");
   
agent.applyChangeSet(ResourceFactory.newClassPathResource("change-set.xml"));

    return agent.getKnowledgeBase();
}	


<change-set xmlns='http://drools.org/drools-5.0/change-set'
             xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
             xs:schemaLocation='http://drools.org/drools-5.0/change-set.xsd'
>
   <add>
       <resource source='classpath:dsl/' type='DSL' />  
       <resource source='classpath:rules/' type='DSLR' />    
       <resource source='classpath:rules/section-A/' type='DSLR' />
    </add>
</change-set>


I get the following generic drools errors:
ERR 103] Line 4:0 rule 'rule_key' failed predicate:
{(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,0]: [ERR 101]
Line 7:0 no viable alternative at input 'import' in rule Con in rule
attribute
...
...

The rules are same, folder location is the same. I believe that drools has a
problem resolving path (expander global.dsl) from the dslr file when using a
KnowlegeAgent since in the earlier strategy, one could build a dsl into the
knowledgeBuilder directly from the classpath.

Pl suggest.
-- 
View this message in context: http://n3.nabble.com/KnowledgeAgent-doesn-t-load-dsl-files-and-dslr-file-from-a-change-set-correctly-tp139702p139702.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list