Simple example showing how to build a KnowledgeBase from an XLS decision table resource.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration(); dtconf.setInputType( DecisionTableInputType.XLS ); dtconf.setWorksheetName( "Tables_2" ); kbuilder.add( ResourceFactory.newUrlResource( "file://IntegrationExampleTest.xls" ), ResourceType.DTABLE, dtconf ); assertFalse( kbuilder.hasErrors() ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Simple example showing how to build a KnowledgeBase from an DRF flow resource.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newUrlResource( "file://myflow.rf" ), ResourceType.DRF); assertFalse( kbuilder.hasErrors() ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
If there are errors a simple toString can print the errors
if ( kbuilder.hasErrors() ) { log.exception( kbuilder.getErrors().toString() ) }
The KnowledgeBuilder can also be built from a configuration using the XML change-set format and the ResourceType.CHANGE_SET value. While change-set supports add, remove, and modify as elements. KnowledgeBuilder will only process add. If the resource element provided points to a directory, all files found in that directory will be added. Currently the knowledge type is not derived from the file extension and must be explicitly set in the XML for the resource. It is expected that all resources in a directory given resource are of the specified type.
<change-set xmlns='http://drools.org/drools-5.0/change-set' xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' xs:schemaLocation='drools-change-set-5.0.xsd' > <add> <resource source='http:org/domain/myrules.drl' type='DRL' /> <resource source='classpath:data/IntegrationExampleTest.xls' type="DTABLE"> <decisiontable-conf input-type="XLS" worksheet-name="Tables_2" /> </resource> <resource source='file:org/drools/decisiontable/myflow.drf' type='DRF' /> </add> </change-set>
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent", // the name of the agent kaconf ); kagent.applyChangeSet( ResourceFactory.newUrlResource( url ) ); // resource to the change-set xml for the resources to add
|
|
|
|
|
|