[rules-users] PMML - Exception excuting consequence for rule xxx in yyy: java.lang.NullPointerException : using KnowledgeAgent

smilk sunghee.bae at meritz.co.kr
Wed Jul 17 05:27:55 EDT 2013


Hi. I'm trying to test pmml "decision trees"
(https://github.com/droolsjbpm/drools-chance/tree/master/drools-pmml)
on Drools 5.5.0.Final.

The two test environment's outcome are not same.

1) I got a test on Eclipse. The results are fine. Test source is as below.

public class PMMLTestFromLocal {
	
	public static final void main(String[] args) {
        try {
            KnowledgeBase kbase = readKnowledgeBase();
            StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
            KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "LocalPmmlTest");
            
            FactType CHK_YN_Type = kbase.getFactType(
"Meritz_ModelRule_01","CHK_YN" );
            CHK_YN_Type.newInstance();           
            
            ksession.getWorkingMemoryEntryPoint( "in_AC_CSE_TYP_RE"
).insert( "group0" );    
            ksession.getWorkingMemoryEntryPoint( "in_AC_TYP_RE" ).insert(
"Caution" );
            ksession.getWorkingMemoryEntryPoint( "in_COV_CD_RE" ).insert(
"group2" );
            ksession.getWorkingMemoryEntryPoint( "in_AC_STAT_CD_RE"
).insert( "group1" );
            ksession.getWorkingMemoryEntryPoint( "in_HDCAP_RATE_RE"
).insert( "0" );       
            ksession.getWorkingMemoryEntryPoint( "in_FDS_AC_YN" ).insert(
"0" );
            ksession.getWorkingMemoryEntryPoint( "in_AGE_GRD" ).insert(
"10대" );
            ksession.getWorkingMemoryEntryPoint( "in_AC_COT_DAY" ).insert(
0.0 );
            
            ksession.fireAllRules();
            logger.close();
        } catch (Throwable t) {
            t.printStackTrace(); 
        }
    }


    private static KnowledgeBase readKnowledgeBase() throws Exception {
        KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(ResourceFactory.newClassPathResource("pmml2.drl"),
ResourceType.DRL);
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error: errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse
knowledge.");
        }
        KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase("Meritz");
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        return kbase;
    }
}


2) The Second environment which is excuting Exception is Tomcat.
I got a test using same drools engine on Tomcat. But NullpointerException
occured.
Test source is as below.

public class PMMLTestFromServer {
	
	public static void main(String[] args) {

		StatefulKnowledgeSession kSession = getSKSession();
		KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(kSession, "ServerPmmlTest");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		
		kSession.getWorkingMemoryEntryPoint( "in_AC_CSE_TYP_RE" ).insert( "group0"
);    
		kSession.getWorkingMemoryEntryPoint( "in_AC_TYP_RE" ).insert( "Caution" );
		kSession.getWorkingMemoryEntryPoint( "in_COV_CD_RE" ).insert( "group2" );
		kSession.getWorkingMemoryEntryPoint( "in_AC_STAT_CD_RE" ).insert( "group1"
);
		kSession.getWorkingMemoryEntryPoint( "in_HDCAP_RATE_RE" ).insert( "0" );       
		kSession.getWorkingMemoryEntryPoint( "in_FDS_AC_YN" ).insert( "0" );
		kSession.getWorkingMemoryEntryPoint( "in_AGE_GRD" ).insert( "10대" );
		kSession.getWorkingMemoryEntryPoint( "in_AC_COT_DAY" ).insert( 0.0 );		
		

	        kSession.fireAllRules();

        
        logger.close();
	}

	public static StatefulKnowledgeSession getSKSession() {
		KnowledgeAgent agent =  KnowledgeAgentFactory.newKnowledgeAgent("Meritz");
	
agent.applyChangeSet(ResourceFactory.newClassPathResource("change-set_model.xml")); 				
		
		KnowledgeBase ruleBase = agent.getKnowledgeBase();
		
		System.out.println(ruleBase.getKnowledgePackages());
		
		
		return ruleBase.newStatefulKnowledgeSession();
	}
}

The differences in two test source is using KnowledgeAgent.

Exception stack trace follows - 

Exception executing consequence for rule
"outputFeature_CHK_YN_to_Probability_N_probability" in Meritz_ModelRule_01:
java.lang.NullPointerException
	at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
	at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
	at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
	at com.meritzfis.test.PMMLTestFromServer.main(PMMLTestFromServer.java:43)
Caused by: java.lang.NullPointerException
	at
org.drools.base.evaluators.BeforeEvaluatorDefinition$BeforeEvaluator.evaluateCachedRight(BeforeEvaluatorDefinition.java:318)
	at
org.drools.rule.constraint.EvaluatorConstraint.isAllowedCachedRight(EvaluatorConstraint.java:80)
	at
org.drools.common.DoubleBetaConstraints.isAllowedCachedRight(DoubleBetaConstraints.java:97)
	at org.drools.reteoo.JoinNode.propagateFromRight(JoinNode.java:156)
	at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:148)
	at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
	at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
	at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
	at org.drools.common.SimpleBeliefSystem.insert(SimpleBeliefSystem.java:38)
	at
org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:204)
	at
org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:176)
	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:231)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
	at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:245)
	at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:210)
	at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:205)
	at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fc.defaultConsequence(Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fc.java:14)
	at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fcDefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
	at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fcDefaultConsequenceInvoker.evaluate(Unknown
Source)
	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
	... 6 more


I'm attaching a drl file.



--
View this message in context: http://drools.46999.n3.nabble.com/PMML-Exception-excuting-consequence-for-rule-xxx-in-yyy-java-lang-NullPointerException-using-Knowledt-tp4024963.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list