本文整理汇总了Java中org.kie.internal.KnowledgeBase类的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBase类的具体用法?Java KnowledgeBase怎么用?Java KnowledgeBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KnowledgeBase类属于org.kie.internal包,在下文中一共展示了KnowledgeBase类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testFactHandleMarshall
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
@Test
public void testFactHandleMarshall() throws JAXBException {
JAXBContext jaxbContext = getJaxbContext();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
FactHandle fh1 = ksession.insert(new Person("darth", 105));
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(fh1, baos);
assertXMLEqual("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<fact-handle external-form=\"" + fh1.toExternalForm() + "\"/>",
new String(baos.toByteArray()));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
FactHandle fh2 = (FactHandle)unmarshaller.unmarshal(new StringReader(baos.toString()));
assertEquals(fh1, fh2);
}
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:22,代码来源:JaxbTest.java
示例2: testExecutionResults
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
@Test
public void testExecutionResults() throws JAXBException {
JAXBContext jaxbContext = getJaxbContext();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
List<Command> commands = new ArrayList<Command>();
commands.add(CommandFactory.newInsert(new Person("darth", 105), "p"));
commands.add(CommandFactory.newFireAllRules());
ExecutionResults res1 = ksession.execute(CommandFactory.newBatchExecution(commands));
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(res1, baos);
// note it's using xsi:type
logger.debug(new String(baos.toByteArray()));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
ExecutionResults res2 = (ExecutionResults)unmarshaller.unmarshal(new StringReader(baos.toString()));
}
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:25,代码来源:JaxbTest.java
示例3: getDistributeSimplifyKnowledgeBase
import org.kie.internal.KnowledgeBase; //导入依赖的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
示例4: getDistributeSimplify2KnowledgeBase
import org.kie.internal.KnowledgeBase; //导入依赖的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
示例5: testCompareInstances
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
@Test
public void testCompareInstances() throws Exception {
KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(config);
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
StatefulKnowledgeSession ksessionA = knowledgeBase.newStatefulKnowledgeSession(ksconf, null);
StatefulKnowledgeSession ksessionB = knowledgeBase.newStatefulKnowledgeSession(ksconf, null);
Assert.assertTrue(KieGimcrack.class.getSimpleName() + " is broken!", kieGimcrack.compareInstances(ksessionA, ksessionB));
}
开发者ID:mrietveld,项目名称:gimcrack,代码行数:16,代码来源:TestMarshallingUtilsTest.java
示例6: main
import org.kie.internal.KnowledgeBase; //导入依赖的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
示例7: initSession
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
public void initSession(){
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(this.kBuilder.getKnowledgePackages());
this.ksession = kbase.newStatefulKnowledgeSession();
}
开发者ID:eternnoir,项目名称:RulEST,代码行数:6,代码来源:KnowledgeManager.java
示例8: processDaqHg
import org.kie.internal.KnowledgeBase; //导入依赖的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
示例9: testCompareArrays
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
@Test
public void testCompareArrays() {
int[] testA = { 1, 3 };
int[] testB = { 1, 3 };
boolean same = kieGimcrack.compareInstances(testA, testA);
assertTrue(same);
printResult(same, testA, testB);
// setup for test
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBase[] testArrA = { kbase };
KnowledgeBase[] testArrB = { kbase, null };
same = kieGimcrack.compareInstances(testArrA, testArrB);
assertTrue(!same);
printResult(same, testArrA, testArrB);
Environment[] testEnvA = { EnvironmentFactory.newEnvironment(), EnvironmentFactory.newEnvironment() };
Environment[] testEnvB = { EnvironmentFactory.newEnvironment(), EnvironmentFactory.newEnvironment() };
testEnvA[0].set(DROOLS_PERSISTENCE_UNIT_NAME, DROOLS_PERSISTENCE_UNIT_NAME);
same = kieGimcrack.compareInstances(testEnvA, testEnvB);
assertTrue(!same);
printResult(same, testEnvA, testEnvB);
PriorityQueue<Short> priShortA = new PriorityQueue<Short>();
PriorityQueue<Short> priShortB = new PriorityQueue<Short>();
short[] shortList = { (short) 6, (short) 8, (short) 6, (short) 1, (short) 8, (short) 5, (short) 9 };
for (int i = 0; i < shortList.length; ++i) {
priShortA.add(shortList[i]);
priShortB.add(shortList[i]);
}
priShortB.add((short) 0);
assertFalse("Should be unequal", kieGimcrack.compareInstances(priShortA, priShortB));
assertEquals(new Short((short) 0), priShortB.poll());
assertTrue("Should be equal", kieGimcrack.compareInstances(priShortA, priShortB));
}
开发者ID:mrietveld,项目名称:gimcrack,代码行数:46,代码来源:TestMarshallingUtilsTest.java
示例10: createKnowledgeSessionFromKBase
import org.kie.internal.KnowledgeBase; //导入依赖的package包/类
public static StatefulKnowledgeSession createKnowledgeSessionFromKBase(KnowledgeBase kbase, HashMap<String, Object> context) {
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
StatefulKnowledgeSession knowledgeSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, ksconf, createEnvironment(context));
return knowledgeSession;
}
开发者ID:mrietveld,项目名称:gimcrack,代码行数:6,代码来源:PersistenceUtil.java
示例11: testSort
import org.kie.internal.KnowledgeBase; //导入依赖的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.KnowledgeBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论