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


Java KnowledgeBase.addKnowledgePackages方法代码示例

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


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

示例1: readKnowledgeBase

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

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

示例3: createKnowledgeBase

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

示例4: getKnowlegeBase

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

示例5: readKnowledgeBase

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

示例6: createKnowledgeBase

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
private KnowledgeBase createKnowledgeBase() {
    log().debug("createKnowledgeBase: Creating Drools KnowledgeBase");
    final Properties props = new Properties();
    props.setProperty("drools.dialect.java.compiler.lnglevel", "1.6");

    final PackageBuilderConfiguration conf = new PackageBuilderConfiguration(props);
    KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
    
    // Use the rules file defined in the configuration file
    // We will not throw an exception if the rules failed to be parsed
    builder.add(ResourceFactory.newFileResource(m_configDao.getRulesFile()), ResourceType.DRL);
    if( builder.hasErrors() ) {
        log().error("Failed to create Drools KnowledgeBase: " + builder.getErrors().toString());
        return null;
    }
    
    KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
    knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
    return knowledgeBase;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:21,代码来源:DroolsTicketerServiceLayer.java

示例7: readKnowledgeBase

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
/**
 * 
 * @return
 * @throws Exception
 */
private static KnowledgeBase readKnowledgeBase(String path) throws Exception {
    if(path != null) {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     kbuilder.add(ResourceFactory.newClassPathResource(path), 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();
     kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
     return kbase;
    } else { return null; }
}
 
开发者ID:xladde,项目名称:hsw,代码行数:22,代码来源:DroolsTools.java

示例8: crearSesionConConfiguracionStandard

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public void crearSesionConConfiguracionStandard(KnowledgeBuilder kbuilder){
     KnowledgeBaseConfiguration kbaseconfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
//          kbaseconfiguration.setProperty(AssertBehaviorOption.PROPERTY_NAME, "equality");
          
          System.out.println("\n\n\n\n");
          System.out.println("\nLISTADO DE LAS PROPIEDADES UTILIZADAS PARA LA CONFIGURACION DEL MOTOR DEL AGENTE " + this.agent.getIdentAgente() + "......\n");
          System.out.println("----------------------------------------------------------------");
          
          System.out.println("AssertBehaviorOption->" + kbaseconfiguration.getProperty(org.drools.conf.AssertBehaviorOption.PROPERTY_NAME));              
          System.out.println("EventProcessingOption->" + kbaseconfiguration.getProperty(org.drools.conf.EventProcessingOption.PROPERTY_NAME));              
          System.out.println("IndexLeftBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexLeftBetaMemoryOption.PROPERTY_NAME));
          System.out.println("IndexRightBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexRightBetaMemoryOption.PROPERTY_NAME));
          System.out.println("LogicalOverrideOption->" + kbaseconfiguration.getProperty(org.drools.conf.LogicalOverrideOption.PROPERTY_NAME));              
          System.out.println("MaintainTMSOption->" + kbaseconfiguration.getProperty(org.drools.conf.MaintainTMSOption.PROPERTY_NAME));              
          System.out.println("MBeansOption->" + kbaseconfiguration.getProperty(org.drools.conf.MBeansOption.PROPERTY_NAME));              
          System.out.println("MultithreadEvaluationOption->" + kbaseconfiguration.getProperty(org.drools.conf.MultithreadEvaluationOption.PROPERTY_NAME));              
          System.out.println("RemoveIdentitiesOption->" + kbaseconfiguration.getProperty(org.drools.conf.RemoveIdentitiesOption.PROPERTY_NAME));
          System.out.println("SequentialAgendaOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialAgendaOption.PROPERTY_NAME));
          System.out.println("SequentialOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialOption.PROPERTY_NAME));
          System.out.println("ShareAlphaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareAlphaNodesOption.PROPERTY_NAME));
          System.out.println("ShareBetaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareBetaNodesOption.PROPERTY_NAME));
          System.out.println("----------------------------------------------------------------\n\n\n\n");                                                            
          KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseconfiguration);
          kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
          if(kSesion != null)kSesion.dispose();
          kSesion = kbase.newStatefulKnowledgeSession();
          entrypoint = kSesion.getWorkingMemoryEntryPoint("DEFAULT");
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:29,代码来源:MotorDeReglasDroolsImp5.java

示例9: createStatefulKnowledgeSession

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
/**
 * Creates the stateful knowledge session.
 *
 * @return the stateful knowledge session
 */
StatefulKnowledgeSession createStatefulKnowledgeSession() {
    StatefulKnowledgeSession session = null;
    try {
        final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                .newKnowledgeBuilder();

        final String casRules = guvnorService
                .getVersionedRulesFromPackage();

        kbuilder.add(
                ResourceFactory.newByteArrayResource(casRules.getBytes()),
                ResourceType.DRL);

        final KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if (errors.size() > 0) {
            for (final KnowledgeBuilderError error : errors) {
                logger.error(error.toString());
            }
        }

        final KnowledgeBase knowledgeBase = KnowledgeBaseFactory
                .newKnowledgeBase();
        knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

        session = knowledgeBase.newStatefulKnowledgeSession();
        session.setGlobal("ruleExecutionContainer",
                new RuleExecutionContainer());
    } catch (final Exception e) {
        logger.error(e.toString(), e);
    }
    return session;
}
 
开发者ID:bhits,项目名称:dss-api,代码行数:38,代码来源:RuleExecutionServiceImpl.java

示例10: readKnowledgeBase

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
private static KnowledgeBase readKnowledgeBase() throws Exception {
	
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("Sample.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();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}
 
开发者ID:liuyuping459,项目名称:FuzzyReasoningDemo,代码行数:16,代码来源:DroolsService.java

示例11: readKnowledgeBase

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("Questions.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("Knowledge.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();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}
 
开发者ID:mescam,项目名称:carMechanic,代码行数:16,代码来源:DroolsTest.java

示例12: testDroolsFrameLoader

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
@Test
@Ignore
public void testDroolsFrameLoader() throws Exception {
	// build the knowledge base
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	kbuilder.add( ResourceFactory.newClassPathResource( "/gov/va/cpe/vpr/frames/HelloWorldAlert.drl", getClass()), ResourceType.DRL );
	if ( kbuilder.hasErrors() ) {
		fail(kbuilder.getErrors().toString());
	}
	KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
	kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
	
	// add it to the frame registry
	FrameRegistry.DroolsFrameLoader loader = new DroolsFrameLoader(kbase);
	List<IFrame> frames = loader.load();
	assertEquals(1, frames.size());
	assertTrue(frames.get(0) instanceof DroolsFrameAdapter);
	DroolsFrameAdapter frame = (DroolsFrameAdapter) frames.get(0);
	
	// create the patient, modify the name
       PatientDemographics p = POMUtils.newInstance(PatientDemographics.class, PatientDemographicsImporter.class.getResourceAsStream("patient.json"));
	p.setData("givenNames", "FOO");
	p.setData("familyName", "BAR");
	
	FrameRegistry registry = new FrameRegistry(loader);
	FrameRunner runner = new FrameRunner(registry);
	FrameJob job = runner.exec(new ArrayList<IFrameEvent<?>>(p.getEvents()));
	assertEquals(2, job.getActions().size());
	FrameAction action = job.getActions().get(1);
	System.out.println(job.getActions());
	assertTrue(action instanceof PatientAlert);
	PatientAlert aa = (PatientAlert) action;
	assertEquals("drools alert", aa.getTitle());
	assertEquals(p.getSsn(), aa.getDescription());
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:36,代码来源:FrameRegistryTests.java

示例13: buildKnowledgeSession

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public final void buildKnowledgeSession() {
	if (ksession == null) {
		LOG.debug("Building Drools Knowledge Session");
		// initialise the rules
        final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                .newKnowledgeBuilder();

        // pickup the rules file from the classpath
        // this will parse and compile in one step
        LOG.info("Loading rules file " + rulesFileName);
        kbuilder.add( ResourceFactory.newClassPathResource( rulesFileName, QaRecommendationServiceImpl.class ),
                      ResourceType.DRL );

        // Check the builder for errors
        if ( kbuilder.hasErrors() ) {
        	LOG.error(kbuilder.getErrors().toString());
            throw new RuntimeException( "Unable to compile \"" + rulesFileName + "\"." );
        }

        // add the packages to a knowledgebase (deploy the knowledge packages).
        final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();      
		kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
		
		// set the knowledge session
		ksession = kbase.newStatefulKnowledgeSession();
		
		// set the configured message formats and advice
		ksession.setGlobal("globals", globals);
	}
	
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:32,代码来源:QaRecommendationServiceImpl.java

示例14: readKnowledgeBase

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

        // Print out model by Holger
//        try {
//            LineNumberReader lnir = new LineNumberReader(new FileReader(new File(path)));
//            String line;
//            do {
//                line = lnir.readLine();
//                if (null != line) {
//                    System.out.println(line);
//                }
//            } while (null != line);
//            lnir.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        
        
        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,代码行数:40,代码来源:DroolsEngine.java

示例15: createStatefulKnowledgeSession

import org.drools.KnowledgeBase; //导入方法依赖的package包/类
/**
 * Creates the stateful knowledge session.
 * 
 * @return the stateful knowledge session
 */
private StatefulKnowledgeSession createStatefulKnowledgeSession() {
	StatefulKnowledgeSession session = null;
	try {
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
				.newKnowledgeBuilder();

		String casRules = guvnorService.getVersionedRulesFromPackage();

		kbuilder.add(
				ResourceFactory.newByteArrayResource(casRules.getBytes()),
				ResourceType.DRL);

		KnowledgeBuilderErrors errors = kbuilder.getErrors();
		if (errors.size() > 0) {
			for (KnowledgeBuilderError error : errors) {
				LOGGER.error(error.toString());
			}
		}

		KnowledgeBase knowledgeBase = KnowledgeBaseFactory
				.newKnowledgeBase();
		knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

		session = knowledgeBase.newStatefulKnowledgeSession();
		session.setGlobal("ruleExecutionContainer",
				new RuleExecutionContainer());
	} catch (Exception e) {
		LOGGER.error(e.toString(), e);
	}
	return session;
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:37,代码来源:RuleExecutionServiceImpl.java


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