当前位置: 首页>>代码示例>>Java>>正文


Java KnowledgeBuilder类代码示例

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


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

示例1: readKnowledgeBase

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
public static KnowledgeBase readKnowledgeBase(List<RuleResource> resources) {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	for (RuleResource res: resources) {
		try {
			kbuilder.add(ResourceFactory.newClassPathResource(res.getRuleResourceFile()), res.getResType());
		} catch (Exception ex) {
			kbuilder.add(ResourceFactory.newFileResource(res.getRuleResourceFile()), res.getResType());
		}
	}
	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();
	kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
	return kbase;
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:21,代码来源:KnowledgeBaseHelper.java

示例2: deploy

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
public void deploy(DeploymentEntity deployment) {
  KnowledgeBuilder knowledgeBuilder = null;

  DeploymentCache deploymentCache = Context
    .getProcessEngineConfiguration()
    .getDeploymentCache();
  
  Map<String, ResourceEntity> resources = deployment.getResources();
  for (String resourceName : resources.keySet()) {
    log.info("Processing resource " + resourceName);
    if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType)
      if (knowledgeBuilder==null) {
        knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      }
      ResourceEntity resourceEntity = resources.get(resourceName);
      byte[] resourceBytes = resourceEntity.getBytes();
      Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes);
      knowledgeBuilder.add(droolsResource, ResourceType.DRL);
    }
  }
  
  if (knowledgeBuilder!=null) {
    KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase();
    deploymentCache.addKnowledgeBase(deployment.getId(), knowledgeBase);
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:27,代码来源:RulesDeployer.java

示例3: readKnowledgeBase

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
/**
 * A private method for rule parsing.
 * 
 * @param path
 *            of the .drl file.
 * @return KnowledgeBase.
 * @throws Exception
 *             Exception.
 */
private static KnowledgeBase readKnowledgeBase(String path) throws Exception {

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    FileInputStream fis = new FileInputStream(path);
    kbuilder.add(ResourceFactory.newInputStreamResource(fis), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            System.err.println(error + " @line " + error.getLines());
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:27,代码来源:DroolsEvaluation.java

示例4: addKnowledgePackages

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
private void addKnowledgePackages(KnowledgeBaseWrapper knowledgeBaseWrapper, DroolsRuleAddEvent droolsRuleAddEvent, String ruleName) {
	String resourceType = droolsRuleAddEvent.getOriginalResourceType();
	
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(new PackageBuilderConfiguration(properties));
       kbuilder.add(ResourceFactory.newByteArrayResource(droolsRuleAddEvent.getRuleBytes()), ResourceType.getResourceType(resourceType));

       if(kbuilder.hasErrors()) {
           for(KnowledgeBuilderError error : kbuilder.getErrors()) {
               log.error(error.getMessage() + " on lines " + Arrays.toString(error.getLines()));
           }
           throw new IllegalArgumentException("Could not parse Rule: " + ruleName + " type: " + resourceType);
       }
	
	knowledgeBaseWrapper.getKnowledgeBase().addKnowledgePackages(kbuilder.getKnowledgePackages());
       knowledgeBaseWrapper.setTotalRules(knowledgeBaseWrapper.getTotalRules() + 1);
}
 
开发者ID:Gigaspaces,项目名称:xap-drools-integration,代码行数:17,代码来源:DroolsRuleAddEventListener.java

示例5: getKnowlegeBase

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
private static KnowledgeBase getKnowlegeBase(List<EntityRuleDO> rules) {
	if (rules == null || rules.size() == 0) {
		return null;
	}

	StringBuilder sb = new StringBuilder();

	for (EntityRuleDO entityRuleDO : rules) {
		sb.append(entityRuleDO.getRule()).append("\n");
	}

	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));
	config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newByteArrayResource(sb.toString().getBytes()), ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		throw new ServiceException("Problem building cross field validation rules: " + kbuilder.getErrors());
	}

	KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
	kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
	return kbase;
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:27,代码来源:RuleServiceImpl.java

示例6: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with.drl"), ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		throw new ServiceException("Problem building cross field validation rules: " + kbuilder.getErrors());
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:TestEndsWithOperator.java

示例7: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with-map-reference.drl"),
			ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		throw new ServiceException("Problem building cross field validation rules.");
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:TestStartsWithMapReferenceOperator.java

示例8: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with-map.drl"), ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		kbuilder.getErrors();
		throw new ServiceException("Problem building cross field validation rules.");
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:TestStartsWithMapOperator.java

示例9: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with-map.drl"), ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		KnowledgeBuilderErrors errors = kbuilder.getErrors();
		throw new ServiceException("Problem building cross field validation rules: " + errors);
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:TestEndsWithMapOperator.java

示例10: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with.drl"), ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		throw new ServiceException("Problem building cross field validation rules.");
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:TestStartsWithOperator.java

示例11: beforeClass

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
	KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
	config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
	kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with-map-reference.drl"),
			ResourceType.DRL);

	if (kbuilder.hasErrors()) {
		kbuilder.getErrors();
		throw new ServiceException("Problem building cross field validation rules.");
	}

	knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:18,代码来源:TestEndsWithMapReferenceOperator.java

示例12: getKnowledgeBuilder

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
private static KnowledgeBuilder getKnowledgeBuilder(String rulePackagePath,
		String droolsEngineName) {

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
			.newKnowledgeBuilder();

	changesetPath = "./";

	createChangeSetInfo(rulePackagePath, droolsEngineName, true);
	engineResource = ResourceFactory.newFileResource(changesetPath
			+ droolsEngineName + ".xml");
	kbuilder.add(engineResource, ResourceType.CHANGE_SET);

	if (kbuilder.hasErrors()) {
		startUpError = true;
		Iterator<KnowledgeBuilderError> ite = kbuilder.getErrors()
				.iterator();
		while (ite.hasNext()) {
			logger.error(ite.next().getMessage());
		}
		return null;
	} else {
		return kbuilder;
	}
}
 
开发者ID:MusesProject,项目名称:MusesServer,代码行数:26,代码来源:TemporalDroolsEngineServiceImpl.java

示例13: AbstractDroolsEngine

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
public AbstractDroolsEngine(KnowledgeBuilder kbuilder, Object[] globals,
		Environment env, KnowledgeBaseConfiguration config,
		SessionConfiguration sessionConf, String changesetPath,
		Boolean hasKnowledgeAgent) {

	KnowledgeBase kbase = createKBase(kbuilder, config);

	if (hasKnowledgeAgent) {
		createKnowledgeAgent(kbase, "MyKAgent");
		wm = (ReteooStatefulSession) ((KnowledgeBaseImpl) kagent
				.getKnowledgeBase()).ruleBase.newStatefulSession(
				(SessionConfiguration) sessionConf, env);
		ksession = new StatefulKnowledgeSessionImpl(wm, kagent
				.getKnowledgeBase());
	} else {
		ksession = kbase.newStatefulKnowledgeSession(sessionConf, env);
	}

	for (Object global : globals) {
		ksession.setGlobal(global.getClass().getSimpleName(), global);
	}
}
 
开发者ID:MusesProject,项目名称:MusesServer,代码行数:23,代码来源:AbstractDroolsEngine.java

示例14: getKnowledgeBuilder

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
private static KnowledgeBuilder getKnowledgeBuilder(String rulePackagePath,
		String droolsEngineName) {

	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
			.newKnowledgeBuilder();

	changesetPath = "var/";

	createChangeSetInfo(rulePackagePath, droolsEngineName, true);
	engineResource = ResourceFactory.newFileResource(changesetPath
			+ droolsEngineName + ".xml");
	kbuilder.add(engineResource, ResourceType.CHANGE_SET);

	if (kbuilder.hasErrors()) {
		Iterator<KnowledgeBuilderError> ite = kbuilder.getErrors()
				.iterator();
		while (ite.hasNext()) {
			log.error(ite.next().getMessage());
		}
		return null;
	} else {
		return kbuilder;
	}
}
 
开发者ID:MusesProject,项目名称:MusesServer,代码行数:25,代码来源:DroolsEngineServiceImpl.java

示例15: initSession

import org.drools.builder.KnowledgeBuilder; //导入依赖的package包/类
@Produces
@Named("node1")
public GridNode initSession() {
    log.info("Creating drools kbase");
    GridNode node = new GridNodeImpl();

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("testRule.drl"), ResourceType.DRL);

    if (kbuilder.hasErrors()) {
        if (kbuilder.getErrors().size() > 0) {
            for (KnowledgeBuilderError kerror : kbuilder.getErrors()) {
                log.error(kerror.getMessage());
            }
            throw new RuntimeException(kbuilder.getErrors().toString());
        }
    }
    node.set("ksession1", kbuilder.newKnowledgeBase().newStatelessKnowledgeSession());

    return node;
}
 
开发者ID:gtudan,项目名称:camel-cdi-drools-test,代码行数:22,代码来源:DroolsComponentProducer.java


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