4

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!

TeaCupApp
  • 11,316
  • 18
  • 70
  • 150

4 Answers4

5

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.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I'd assume it's a homework. And checking if a simple Horn clause holds or not, really isn't especially hard. Even a HORNSAT really shouldn't be too hard to get right - but then we'd need to know what exactly should be implemented. – Voo May 23 '11 at 01:12
  • Thank you very much I have extended my understanding regarding these techniques...However I may have to research more to actually implement at higher level, so as Voo said my homework must be easier to solve but I thought if I am learning something why not to learn a right and efficient way, :) Thanks – TeaCupApp May 23 '11 at 03:10
  • @Voo , Yes mate you are right! It will be fairly easy to implement if my my above given thoughts(In question) are right on track. :) Thanks for help. – TeaCupApp May 23 '11 at 03:11
0

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.

kutschkem
  • 7,826
  • 3
  • 21
  • 56
0

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

0

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).

msj121
  • 2,812
  • 3
  • 28
  • 55