java java中的前向链接和后向链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6091772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forward chaining and Backward chaining in java
提问by TeaCupApp
What will be the best approach to implement forward chaining and backward chaining for reasoning process in java?
在java中为推理过程实现前向链接和后向链接的最佳方法是什么?
We have been given Horn-form knowledge base which has set of statements.
我们已经获得了具有一组语句的 Horn 形式的知识库。
I have tried to search on internet but I was unable to find any description regarding how to implement these sort of Artificial Intelligence concept into coding.
我曾尝试在互联网上进行搜索,但找不到关于如何将此类人工智能概念实施到编码中的任何描述。
My understanding :
我的理解 :
I have thought so far that I will read each sentence(Horn-Form) and create an object of it. Each Sentence class object will have relationship variables and when I will ask knowledge bases for Backward or Forward chain, It will check array of those objects and constructs my desired chain.
到目前为止,我一直认为我会阅读每个句子(Horn-Form)并创建它的对象。每个 Sentence 类对象都有关系变量,当我向后向或向前链询问知识库时,它将检查这些对象的数组并构建我想要的链。
public class Sentence{
private String impliedBy;
private String implementedVar;
public Sentence(String sentence){
String[] relation = sentence.split("=>");
this.impliedBy = relation[0];
this.implementedVar = relation[1];
}
...
}
Calling above class by saying...
通过说...
Sentence s = new Sentence("a&b=>c");
Am I on right track of sorry I am noob for these sort of complicated programming and as per my prediction I might need lots of optimisation to run these sort of reasoning at very high level. But it seems like I need good understanding by someone thank you if some of you can help...
我是否在正确的轨道上抱歉我是这些复杂编程的菜鸟,根据我的预测,我可能需要大量优化才能在非常高的水平上运行这些推理。但是,如果你们中的一些人可以提供帮助,我似乎需要得到某人的充分理解,谢谢...
Thanks!
谢谢!
回答by duffymo
I'd use a rules engine like Droolsor JESSbefore I'd try writing this for myself.
在尝试为自己编写之前,我会使用像Drools或JESS这样的规则引擎。
Unless your purpose is to learn how to write a Rete rules engine, in which case I'll withdraw my answer. I'd go and look for Charles Forgy'spapers.
除非您的目的是学习如何编写 Rete 规则引擎,否则我将撤回我的答案。我会去找查尔斯·福吉的文件。
回答by bjornredemption
check these links - may be useful
http://snipplr.com/view/56296/ai-forward-chaining-implementation-for-propositional-logic-horn-form-knowledge-bases/
http://snipplr.com/view/56297/ai-backward-chaining-implementation-for-propositional-logic-horn-form-knowledge-bases/
检查这些链接 - 可能有用
http://snipplr.com/view/56296/ai-forward-chaining-implementation-for-propositional-logic-horn-form-knowledge-bases/
http://snipplr.com/view /56297/ai-backward-chaining-implementation-for-propositional-logic-horn-form-knowledge-bases/
回答by kutschkem
look herefor a description how to get forward chaining working in linear time in the number of variables (note how the implementation in the snippet loops through the clauses for every variable in the agenda). It comes without code, but Hornsat really isn't that hard to code.
看看这里的说明如何获得向前的变量的数目链接线性时间的工作(注意如何通过条款在议程的每个变量的代码段循环执行)。它没有代码,但 Hornsat 真的不难编码。
回答by Mostowski Collapse
Systems such as OPS5 have usually an inference component that uses forward chaining. Prolog on the other hand usually uses backward chaining.
OPS5 等系统通常有一个使用前向链接的推理组件。另一方面,Prolog 通常使用反向链接。
Both forward & backward chaining can be viewed as different strategies to deal with resolution. Whereas forward chaining corresponds to unit resolution, backward chaining will correspond to input resolution.
前向和后向链接都可以被视为处理分辨率的不同策略。而正向链接对应于单位分辨率,反向链接将对应于输入分辨率。
It is also possible to build systems that can include backward chaining inside forward chaining in a controlled way. One such system is Jekejeke Minlog.
还可以构建可以以受控方式在正向链接中包含反向链接的系统。Jekejeke Minlog就是这样一种系统。
A possible implementation à la Marvin Minsky would be to look at the HornClauses as a network. HornClauses that have a head X and HornClauses that have a X in the body would be connected.
Marvin Minsky 的一个可能实现是将 HornClauses 视为一个网络。头部为 X 的 HornClauses 和正文中具有 X 的 HornClauses 将被连接。
A <- D, X X <- G
| |
+------+
Now the body of a HornClause acts as a kind of AND gate, and since different HornClauses can have the same head there is also an OR gate involved. Now try to program something that propagates truth along these gates.
现在 HornClause 的主体充当一种 AND 门,并且由于不同的 HornClause 可以具有相同的头部,因此也涉及到 OR 门。现在尝试编写一些沿着这些门传播真相的东西。
Bye
再见
回答by msj121
Well what might also help is by using:
好吧,使用以下方法也可能有所帮助:
HashMap map = new HashMap(); map.put(impliedBy,impliedVar);
HashMap map = new HashMap(); map.put(impliedBy,impliedVar);
To get the var simply: String value = map.get(impliedBy).
简单地获取变量:String value = map.get(impliedBy)。