Question

What will be the best approach to implement forward chaining and backward chaining for reasoning process in java?

We have been given Horn-form knowledge base which has set of statements.

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.

 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!

Était-ce utile?

La solution

I'd use a rules engine like Drools or JESS before I'd try writing this for myself.

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's papers.

Autres conseils

look here for 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.

Systems such as OPS5 have usually an inference component that uses forward chaining. Prolog on the other hand usually uses backward chaining.

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.

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.

  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.

Bye

Well what might also help is by using:

HashMap map = new HashMap(); map.put(impliedBy,impliedVar);

To get the var simply: String value = map.get(impliedBy).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top