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


Java KnowledgeBaseFactory.newKnowledgeBase方法代码示例

本文整理汇总了Java中org.drools.KnowledgeBaseFactory.newKnowledgeBase方法的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBaseFactory.newKnowledgeBase方法的具体用法?Java KnowledgeBaseFactory.newKnowledgeBase怎么用?Java KnowledgeBaseFactory.newKnowledgeBase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.drools.KnowledgeBaseFactory的用法示例。


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

示例1: readKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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: createKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
private void createKnowledgeBase() {
	String rulesFile;
	rulesFile = System.getProperty("robot.reglas", RulesChecker.RULES_FILE);
	
	DEBUG.message("Creating knowledge base");
    kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    
	DEBUG.message("Load rules from "+rulesFile);
    kbuilder.add(ResourceFactory.newClassPathResource(rulesFile, RulesChecker.class), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        System.err.println(kbuilder.getErrors().toString());
    }

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

    DEBUG.message("Creating Session");
    ksession = kbase.newStatefulKnowledgeSession();
}
 
开发者ID:goujonpa,项目名称:robodrools,代码行数:20,代码来源:RulesChecker.java

示例3: createKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
private void createKnowledgeBase() {
    String rulesFile = System.getProperty("robot.rules", BaguetteSOLO.RULES_FILE);

    DEBUG.message("Creating knowledge base");
    kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    
    DEBUG.message("Loading rules since "+rulesFile);
    kbuilder.add(ResourceFactory.newClassPathResource(rulesFile, BaguetteSOLO.class), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        System.err.println(kbuilder.getErrors().toString());
    }

    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    
    DEBUG.message("Creating session)");
    ksession = kbase.newStatefulKnowledgeSession();
}
 
开发者ID:goujonpa,项目名称:robodrools,代码行数:19,代码来源:BaguetteSOLO.java

示例4: createKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
private void createKnowledgeBase() {
    String rulesFile = System.getProperty("robot.rules", BaguetteTeamIndividual.RULES_FILE);

    DEBUG.message("Creating knowledge base");
    kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    
    DEBUG.message("Loading rules since "+rulesFile);
    kbuilder.add(ResourceFactory.newClassPathResource(rulesFile, BaguetteTeamIndividual.class), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        System.err.println(kbuilder.getErrors().toString());
    }

    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    
    DEBUG.message("Creating session)");
    ksession = kbase.newStatefulKnowledgeSession();
}
 
开发者ID:goujonpa,项目名称:robodrools,代码行数:19,代码来源:BaguetteTeamIndividual.java

示例5: initializeRules

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
public void initializeRules() {
	Resource ruleSet = null;
	if(ruleString != null) {
		ruleSet = ResourceFactory.newReaderResource(new StringReader(ruleString));
	} else {
		ruleSet = ResourceFactory.newFileResource(ruleFilePath);
	}
	kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	kbuilder.add(ruleSet, ResourceType.DRL);
	
	if(kbuilder.hasErrors()) {
		System.out.println(kbuilder.getErrors().toString());
		throw new RuntimeException("Failed to compile drl");
	}
	
	Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
	
	kbase = KnowledgeBaseFactory.newKnowledgeBase();
	// Cache the knowledge base as its creation is intensive
	kbase.addKnowledgePackages(pkgs);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:22,代码来源:RulesData.java

示例6: createKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
/**
     * Method for initializing Drools KnowledgeBase.
     * @return KnowledgeBase that can be used in reasoning.
     */
    private KnowledgeBase createKnowledgeBase() {
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        Resource res = ResourceFactory.newFileResource(tmpDRLFile);
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        knowledgeBuilder.add(res, ResourceType.DRL);
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        if ( knowledgeBuilder.hasErrors() ) {
            LOGGER.error(knowledgeBuilder.getErrors().toString());
            List<ModelElement> conflictingElements = new ArrayList<ModelElement>();
            conflictingElements.add(rModel.getProject());
            Message errorMsg = new Message("Unable to translate Project:\n" + knowledgeBuilder.getErrors().toString(),
                conflictingElements, Status.ERROR);
            result.addMessage(errorMsg);
        }
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
//        Statistic.addTimestamp(reasoningID, System.currentTimeMillis());
        return knowledgeBase;  
    }
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:28,代码来源:DroolsEngine.java

示例7: getKnowlegeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例8: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例9: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例10: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例11: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例12: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例13: beforeClass

import org.drools.KnowledgeBaseFactory; //导入方法依赖的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

示例14: readKnowledgeBase

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
private static KnowledgeBase readKnowledgeBase(String drlFileName) {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    String configDir = CarbonUtils.getCarbonConfigDirPath();
    String droolsDir = configDir + File.separator + StratosConstants.DROOLS_DIR_NAME;
    Resource resource = ResourceFactory.newFileResource(droolsDir + File.separator + drlFileName);
    kbuilder.add(resource, ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            log.error(error.getMessage());
        }
        throw new IllegalArgumentException("Could not parse knowledge");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}
 
开发者ID:apache,项目名称:stratos,代码行数:18,代码来源:AutoscalerRuleEvaluator.java

示例15: setUp

import org.drools.KnowledgeBaseFactory; //导入方法依赖的package包/类
@Before
public void setUp() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Resource resource = ResourceFactory.newFileResource(droolsFilePath);
    kbuilder.add(resource, ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (KnowledgeBuilderError error : errors) {
            sb.append(error.getMessage());
        }
        if (sb.length() > 0) {
            log.error(sb.toString());
        }
        throw new IllegalArgumentException(String.format("Could not parse drools file: %s", droolsFilePath));
    }

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

    conf = ConfUtil.getInstance("src/test/resources/autoscaler.xml").getConfiguration();
}
 
开发者ID:apache,项目名称:stratos,代码行数:23,代码来源:TestMinimumRule.java


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