• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java KnowledgeBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.kie.internal.builder.KnowledgeBuilder的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBuilder类的具体用法?Java KnowledgeBuilder怎么用?Java KnowledgeBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KnowledgeBuilder类属于org.kie.internal.builder包,在下文中一共展示了KnowledgeBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadDrools

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void loadDrools() {
	try {
		logger.info("Initializing Drools rule engine");
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		addDrls(kbuilder);

		KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
		config.setOption(ClockTypeOption.get("pseudo"));

		logger.debug("Compiling rules");
		kSession = kbuilder.newKieBase().newKieSession(config, null);
		homeioSessionClock = new HomeioSessionClock(kSession.getSessionClock());

		initGlobals();

		droolsInitialized = true;

		logger.debug("Successfully initialized Drools rule engine");

	} catch (Exception e) {
		logger.error("Exiting because of an exception during the Drools initialization ", e);
		new RuntimeException("Exiting because of an exception during the Drools initialization");
	}
}
 
开发者ID:IncQueryLabs,项目名称:smarthome-cep-demonstrator,代码行数:26,代码来源:DroolsEventBusClient.java


示例2: loadDrools

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void loadDrools() {
	try {
		logger.info("Initializing Drools rule engine");
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		addDrls(kbuilder);

		logger.debug("Compiling rules");
		kSession = kbuilder.newKieBase().newKieSession();
		initGlobals();

		droolsInitialized = true;

		logger.info("Successfully initialized Drools rule engine");

	} catch (Exception e) {
		logger.error("Exiting because of an exception during the Drools initialization ", e);
		new RuntimeException("Exiting because of an exception during the Drools initialization");
	}
}
 
开发者ID:IncQueryLabs,项目名称:smarthome-cep-demonstrator,代码行数:21,代码来源:DroolsEventBusClient.java


示例3: addRule

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * 单一规则上线
 *
 * @param packageName
 * @param ruleName
 */
public void addRule(String packageName, String ruleName) {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + ruleName + ".drl"), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        logger.error("Unable to compile drl. " + packageName + ruleName + ".drl");
        return;
    } else {
        if (kbase.getRule(packageName, ruleName) != null) {
            logger.info("update rule: " + packageName + "." + ruleName);
        } else {
            logger.info("add rule: " + packageName + "." + ruleName);
        }
    }

    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    kieSession = kbase.newStatelessKieSession();
    setGlobal();
    printRules();
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:26,代码来源:KieService.java


示例4: testCallService

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:BPMServiceTests.java


示例5: runFaultBoundaryProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:BPMServiceTests.java


示例6: testCallService

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:23,代码来源:BPMServiceTests.java


示例7: runFaultBoundaryProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:24,代码来源:BPMServiceTests.java


示例8: addPackage

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * 规则集上线
 *
 * @param packageName
 */
public void addPackage(String packageName) {
    try {
        File path = new File(this.getClass().getClassLoader().getResource(packageName).toURI().getPath());
        if (path.isDirectory()) {
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            File[] files = path.listFiles();
            for (File file : files) {
                if (file.getName().endsWith(".drl")) {
                    kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + file.getName()), ResourceType.DRL);
                    if (kbuilder.hasErrors()) {
                        logger.error("Unable to compile drl. " + packageName + file.getName());
                        return;
                    } else {
                        String ruleName = file.getName().replace(".drl", "");
                        if (kbase.getRule(packageName, ruleName) != null) {
                            logger.info("update rule: " + packageName + "." + ruleName);
                        } else {
                            logger.info("add rule: " + packageName + "." + ruleName);
                        }
                    }
                }
            }

            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
            kieSession = kbase.newStatelessKieSession();
            setGlobal();
            printRules();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:38,代码来源:KieService.java


示例9: runFaultResultProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultResult");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:29,代码来源:BPMServiceTests.java


示例10: runFaultEventProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:29,代码来源:BPMServiceTests.java


示例11: getDistributeSimplifyKnowledgeBase

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 * 
 * @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 */
public static KnowledgeBase getDistributeSimplifyKnowledgeBase()
{
	if( distributeSimplifyKnowledgeBase == null )
	{
		OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
		
		KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		
		// Load in the reng support as a separate cross-cutting concern.
		builder.add( ResourceFactory.newClassPathResource( "reng.drl" )  , 
				ResourceType.DRL );
		
		builder.add( ResourceFactory.newClassPathResource( "distributeSimplify.drl" )  , 
				ResourceType.DRL );
		
		if( LoggingConfiguration.LOGGING_ON )
		{
			builder.add( ResourceFactory.newClassPathResource( "logging.drl" )  , 
					ResourceType.DRL );
		}
		
		if( builder.hasErrors() )
		{
			throw( new RuntimeException( builder.getErrors().toString() ) );
		}
		distributeSimplifyKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
		distributeSimplifyKnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	}
	
	return( distributeSimplifyKnowledgeBase );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:37,代码来源:Elem.java


示例12: getDistributeSimplify2KnowledgeBase

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 * 
 * @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 */
public static KnowledgeBase getDistributeSimplify2KnowledgeBase()
{
	if( distributeSimplify2KnowledgeBase == null )
	{
		OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
		
		KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		
		// Load in the reng support as a separate cross-cutting concern.
		builder.add( ResourceFactory.newClassPathResource( "reng.drl" )  , 
				ResourceType.DRL );
		
		builder.add( ResourceFactory.newClassPathResource( "distributeSimplify2.drl" )  , 
				ResourceType.DRL );
		
		if( LoggingConfiguration.LOGGING_ON )
		{
			builder.add( ResourceFactory.newClassPathResource( "logging.drl" )  , 
					ResourceType.DRL );
		}
		
		if( builder.hasErrors() )
		{
			throw( new RuntimeException( builder.getErrors().toString() ) );
		}
		distributeSimplify2KnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
		distributeSimplify2KnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	}
	
	return( distributeSimplify2KnowledgeBase );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:37,代码来源:Elem.java


示例13: runFaultResultProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultResult");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:29,代码来源:BPMServiceTests.java


示例14: runFaultEventProcess

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:29,代码来源:BPMServiceTests.java


示例15: main

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
public static void main(String[] args) {
	//rule,rule2可以放在数据库中,有个唯一code和他们对于,代码要执行规则的时候,根据code从数据库获取出来就OK了,这样自己开发的规则管理系统那边对数据库里的规则进行维护就行了
	String rule = "package com.neo.drools\r\n";
	rule += "import com.neo.drools.model.Message;\r\n";
	rule += "rule \"rule1\"\r\n";
	rule += "\twhen\r\n";
	rule += "Message( status == 1, myMessage : msg )";
	rule += "\tthen\r\n";
	rule += "\t\tSystem.out.println( 1+\":\"+myMessage );\r\n";
	rule += "end\r\n";


	String rule2 = "package com.neo.drools\r\n";
	rule += "import com.neo.drools.model.Message;\r\n";

	rule += "rule \"rule2\"\r\n";
	rule += "\twhen\r\n";
	rule += "Message( status == 2, myMessage : msg )";
	rule += "\tthen\r\n";
	rule += "\t\tSystem.out.println( 2+\":\"+myMessage );\r\n";
	rule += "end\r\n";


	StatefulKnowledgeSession kSession = null;
	try {


		KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
		//装入规则,可以装入多个
		kb.add(ResourceFactory.newByteArrayResource(rule.getBytes("utf-8")), ResourceType.DRL);
		kb.add(ResourceFactory.newByteArrayResource(rule2.getBytes("utf-8")), ResourceType.DRL);

		KnowledgeBuilderErrors errors = kb.getErrors();
		for (KnowledgeBuilderError error : errors) {
			System.out.println(error);
		}
		KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
		kBase.addKnowledgePackages(kb.getKnowledgePackages());

		kSession = kBase.newStatefulKnowledgeSession();


		Message message1 = new Message();
		message1.setStatus(1);
		message1.setMsg("hello world!");

		Message message2 = new Message();
		message2.setStatus(2);
		message2.setMsg("hi world!");

		kSession.insert(message1);
		kSession.insert(message2);
		kSession.fireAllRules();

	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	} finally {
		if (kSession != null)
			kSession.dispose();
	}

}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:63,代码来源:DdLoadTest.java


示例16: loadKnowledgePackages

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private final Collection<KnowledgePackage> loadKnowledgePackages(EnumSet<ExtraEvaluators> extraEvaluators, File... kbFiles) throws RuntimeException, IOException
{
	HashMap<Resource, ResourceType> resources = new HashMap<Resource, ResourceType>();
	for (File f : kbFiles)
	{
		resources.put(ResourceFactory.newFileResource(f), ResourceType.DRL);
	}
	Properties props = new Properties();
	if (drools_dialect_java_compiler != null)
	{
		props.setProperty("drools.dialect.java.compiler", drools_dialect_java_compiler);
	}
	KnowledgeBuilderConfiguration builderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props, (ClassLoader) null);

	if (extraEvaluators.contains(ExtraEvaluators.IS_KIND_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsKindOfEvaluatorDefinition.IS_KIND_OF.getOperatorString(), new IsKindOfEvaluatorDefinition()));
	}
	if (extraEvaluators.contains(ExtraEvaluators.SAFISFIES_CONSTRAINT))
	{
		builderConfig.setOption(EvaluatorOption.get(SatisfiesConstraintEvaluatorDefinition.SATISFIES_CONSTRAINT.getOperatorString(),
				new SatisfiesConstraintEvaluatorDefinition()));
	}
	if (extraEvaluators.contains(ExtraEvaluators.IS_MEMBER_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsMemberOfEvaluatorDefinition.IS_MEMBER_OF.getOperatorString(), new IsMemberOfEvaluatorDefinition()));
	}
	if (extraEvaluators.contains(ExtraEvaluators.IS_MEMBER_OF_WITH_TYPE))
	{
		builderConfig.setOption(EvaluatorOption.get(IsMemberOfWithTypeEvaluatorDefinition.IS_MEMBER_OF_WITH_TYPE.getOperatorString(),
				new IsMemberOfWithTypeEvaluatorDefinition()));
	}
	if (extraEvaluators.contains(ExtraEvaluators.IS_PARENT_MEMBER_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsParentMemberOfEvaluatorDefinition.IS_PARENT_MEMBER_OF.getOperatorString(),
				new IsParentMemberOfEvaluatorDefinition()));
	}
	if (extraEvaluators.contains(ExtraEvaluators.IS_MISSING_DESC_FOR))
	{
		builderConfig.setOption(EvaluatorOption.get(IsMissingDescForDialectEvaluatorDefinition.IS_MISSING_DESC_FOR.getOperatorString(),
				new IsMissingDescForDialectEvaluatorDefinition()));
	}

	if (extraEvaluators.contains(ExtraEvaluators.IS_GB_MEMBER_TYPE_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsGbMemberTypeOfEvaluatorDefinition.IS_GB_MEMBER_TYPE_OF.getOperatorString(),
				new IsGbMemberTypeOfEvaluatorDefinition()));
	}

	if (extraEvaluators.contains(ExtraEvaluators.IS_US_MEMBER_TYPE_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsUsMemberTypeOfEvaluatorDefinition.IS_US_MEMBER_TYPE_OF.getOperatorString(),
				new IsUsMemberTypeOfEvaluatorDefinition()));
	}

	if (extraEvaluators.contains(ExtraEvaluators.IS_SYNONYM_MEMBER_TYPE_OF))
	{
		builderConfig.setOption(EvaluatorOption.get(IsSynonymMemberTypeOfEvaluatorDefinition.IS_SYNONYM_MEMBER_TYPE_OF.getOperatorString(),
				new IsSynonymMemberTypeOfEvaluatorDefinition()));
	}

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbase_, builderConfig);
	for (Resource resource : resources.keySet())
	{
		synchronized (this)
		{
			kbuilder.add(resource, resources.get(resource));
		}
	}
	if (kbuilder.hasErrors())
	{
		throw new RuntimeException(kbuilder.getErrors().toString());
	}

	return kbuilder.getKnowledgePackages();
}
 
开发者ID:Apelon-VA,项目名称:ISAAC,代码行数:77,代码来源:DroolsExecutor.java


示例17: processDaqHg

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * Executes a DaqHg (Drools As a Query language for HyperGraphDB) query.
 * 
 * @param drlPath The path to the Drools query description.
 * @param context The context for the query execution.
 * @param resultHandler The handler for the query results.
 */
public void processDaqHg( String drlPath , 
		DaqHgContext<T> context , DaqHgResultHandler<T> resultHandler )
{
	OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
	
	KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	
	builder.add( ResourceFactory.newClassPathResource( drlPath )  , 
			ResourceType.DRL );
	
	KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	
	StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
	
	context.setResultHandler( resultHandler );
	
	session.insert( context );
			
	session.fireAllRules();

	session.dispose();
	
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:32,代码来源:DaqHg.java


示例18: setUp

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    ksession = kbuilder.newKnowledgeBase().newStatefulKnowledgeSession();
    initializeTemplate(ksession);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:7,代码来源:JaxbInsertTest.java


示例19: buildProcessDefinition

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
private List<BpmnProcessDataEventListener> buildProcessDefinition(String bpmn2Content,
                                                                  ClassLoader moduleClassLoader) throws IllegalArgumentException {
    if (StringUtils.isEmpty(bpmn2Content)) {
        return Collections.<BpmnProcessDataEventListener>emptyList();
    }

    // Set class loader
    KnowledgeBuilder kbuilder = null;
    if (moduleClassLoader != null) {
        KnowledgeBuilderConfigurationImpl pconf = new KnowledgeBuilderConfigurationImpl(moduleClassLoader);
        kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
    } else {
        kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    }

    // Build
    kbuilder.add(new ByteArrayResource(bpmn2Content.getBytes()),
                 ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            logger.error("Error: {}",
                         error.getMessage());
        }
        logger.debug("Process Cannot be Parsed! \n {} \n",
                     bpmn2Content);
        return Collections.<BpmnProcessDataEventListener>emptyList();
    }

    // Retrieve ProcessInfoHolder
    List<BpmnProcessDataEventListener> processDataList = new ArrayList<>();
    kbuilder.getKnowledgePackages().forEach(
            pkg ->
                    pkg.getProcesses().forEach(
                            p -> {
                                BpmnProcessDataEventListener processData
                                        = (BpmnProcessDataEventListener) p.getMetaData().get(BpmnProcessDataEventListener.NAME);
                                processDataList.add(processData);
                            })
    );
    return processDataList;
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:42,代码来源:BpmnFileIndexer.java


示例20: testSort

import org.kie.internal.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * Verifies that Drools ( <A href="http://drools.org">http://drools.org</A> ) constructs a sorting algorithm from a set of heuristics.
 * Note: this is only intended to be notional, and one should use something different when efficient execution is desired.
 */
public void testSort()
{
	
	OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
	
	KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	
	builder.add( ResourceFactory.newClassPathResource( "test_simplealgebra/sort_test/sort.drl" )  , 
			ResourceType.DRL );
	
	KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	
	StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
	
	session.insert( new DroolsSession( session ) );
	
	final Random rand = new Random( 65432 );
	
	SortNode<DoubleElem> currentSort = null;
	
	for( int count = 0 ; count < 10 ; count++ )
	{
		SortNode<DoubleElem> node = new SortNode<DoubleElem>( new DoubleElem( rand.nextDouble() ) , currentSort );
		currentSort = node;
		session.insert( node );
		session.insert( node.sortValue );
	}
	
	SortPlaceholder<DoubleElem> placeholder = new SortPlaceholder<DoubleElem>( currentSort );
	
	session.insert( placeholder );
			
	session.fireAllRules();

	session.dispose();
	
	SortNode<DoubleElem> prev = null;
	SortNode<DoubleElem> nxt = placeholder.getElem();
	
	while( nxt != null )
	{
		prev = nxt;
		nxt = prev.next;
		
		if( ( prev != null ) && ( nxt != null ) )
		{
			Assert.assertTrue( nxt.sortValue.compareTo( prev.sortValue ) >= 0 );
		}
		
	}
	
	
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:59,代码来源:TestSort.java



注:本文中的org.kie.internal.builder.KnowledgeBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PDFParserConfig类代码示例发布时间:2022-05-22
下一篇:
Java PathImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap