从工作记忆中检索特定类型的事实 [英] Retrieving facts of a specific type from working memory

查看:76
本文介绍了从工作记忆中检索特定类型的事实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要检索所有事实,而是需要从工作记忆中检索特定类型的事实。

Instead of retrieving all facts i need to retrieve specific type of facts from working memory.

我了解到可以从工作记忆中检索所有事实,如下所示。

i learnt that i can retrieve all the facts from working memory as below.

drools.getWorkingMemory().getWorkingMemoryEntryPoint("Stream").getObjects();

请提供一些指针,以从工作内存中检索特定类型的对象。

Please provide some pointers to retrieve specific type of objects from working memory.

推荐答案

可以使用查询代替使用getObjects()方法。查询就像没有RHS的规则:

Instead of using the getObjects() method you could use a query. Queries are like rules without RHS:

query "getObjectsOfClassA"
    $result: ClassA()
end

您可以在查询中使用DRL语言的所有功能来创建真正复杂的匹配模式。您甚至还可以将参数传递给查询: http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e7632

You can use all the power of DRL language inside your queries to create really complex matching patterns. You can even pass arguments to queries too: http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e7632

然后,在Java代码中,您可以使用以下代码调用查询:

Then, in your java code, you can invoke your query using:

QueryResults results = ksession.getQueryResults( "getObjectsOfClassA" ); 
for ( QueryResultsRow row : results ) {
    ClassA classA = ( ClassA ) row.get( "$result" ); //you can retrieve all the bounded variables here
    //do whatever you want with classA
}

如果需要所有ClassA的集合,则可以在查询中使用一个累加函数。

If you need the set of all ClassA you can use an accumulate function in your query.

希望它会有所帮助,

这篇关于从工作记忆中检索特定类型的事实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆