[rules-dev] Prolog Style Backward Chaining - First Cut

Mark Proctor mproctor at codehaus.org
Sun Apr 17 02:44:22 EDT 2011


The geneology example, as here 
http://kti.mff.cuni.cz/~bartak/prolog/contents.html, now works :)
It's the latest test here:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/integrationtests/BackwardChainingTest.java

For the data:
         // grand parents
         ksession.insert( new Man("john") );
         ksession.insert( new Woman("janet") );

         // parent
         ksession.insert( new Man("adam") );
         ksession.insert(  new Parent( "john", "adam") );
         ksession.insert(  new Parent( "janet", "adam") );

         ksession.insert( new Man("stan") );
         ksession.insert(  new Parent( "john", "stan") );
         ksession.insert(  new Parent( "janet", "stan") );

         // grant parents
         ksession.insert( new Man("carl") );
         ksession.insert( new Woman("tina") );

         // parent
         ksession.insert( new Woman("eve") );
         ksession.insert(  new Parent( "carl", "eve") );
         ksession.insert(  new Parent( "tina", "eve") );


         // parent
         ksession.insert( new Woman("mary") );
         ksession.insert(  new Parent( "carl", "mary") );
         ksession.insert(  new Parent( "tina", "mary") );


         ksession.insert( new Man("peter") );
         ksession.insert( new Parent( "adam", "peter" ) );
         ksession.insert( new Parent( "eve", "peter" ) );


         ksession.insert( new Man("paul") );
         ksession.insert( new Parent( "adam", "paul" ) );
         ksession.insert( new Parent( "mary", "paul" ) );


         ksession.insert( new Woman("jill") );
         ksession.insert( new Parent( "adam", "jill" ) );
         ksession.insert( new Parent( "eve", "jill" ) );

it gives the output:
woman
   janet
   tina
   eve
   mary
   jill

man
   john
   adam
   stan
   carl
   peter
   paul

father
   father( carl, mary )
   father( carl, eve )
   father( adam, jill )
   father( adam, paul )
   father( adam, peter )
   father( john, stan )
   father( john, adam )

mother
   mother( mary, paul )
   mother( eve, jill )
   mother( eve, peter )
   mother( tina, mary )
   mother( tina, eve )
   mother( janet, stan )
   mother( janet, adam )

son
   son( paul, mary )
   son( paul, adam )
   son( peter, eve )
   son( peter, adam )
   son( stan, janet )
   son( stan, john )
   son( adam, janet )
   son( adam, john )

daughter
   daughter( jill, eve )
   daughter( jill, adam )
   daughter( mary, tina )
   daughter( mary, carl )
   daughter( eve, tina )
   daughter( eve, carl )

siblings
   sibling( jill, peter )
   sibling( jill, paul )
   sibling( jill, peter )
   sibling( paul, jill )
   sibling( paul, peter )
   sibling( peter, jill )
   sibling( peter, jill )
   sibling( peter, paul )
   sibling( mary, eve )
   sibling( mary, eve )
   sibling( eve, mary )
   sibling( eve, mary )
   sibling( stan, adam )
   sibling( stan, adam )
   sibling( adam, stan )
   sibling( adam, stan )

fullSiblings
   fullSiblings( jill, peter )
   fullSiblings( jill, peter )
   fullSiblings( peter, jill )
   fullSiblings( peter, jill )
   fullSiblings( mary, eve )
   fullSiblings( mary, eve )
   fullSiblings( eve, mary )
   fullSiblings( eve, mary )
   fullSiblings( stan, adam )
   fullSiblings( stan, adam )
   fullSiblings( adam, stan )
   fullSiblings( adam, stan )

fullSiblings2
   fullSiblings2( jill, peter )
   fullSiblings2( jill, peter )
   fullSiblings2( peter, jill )
   fullSiblings2( peter, jill )
   fullSiblings2( mary, eve )
   fullSiblings2( mary, eve )
   fullSiblings2( eve, mary )
   fullSiblings2( eve, mary )
   fullSiblings2( stan, adam )
   fullSiblings2( stan, adam )
   fullSiblings2( adam, stan )
   fullSiblings2( adam, stan )

uncle
   uncle( stan, jill )
   uncle( stan, paul )
   uncle( stan, peter )
   uncle( stan, jill )
   uncle( stan, paul )
   uncle( stan, peter )

aunt
   aunt( mary, jill )
   aunt( mary, peter )
   aunt( mary, jill )
   aunt( mary, peter )
   aunt( eve, paul )
   aunt( eve, paul )

grantParents
   grantParents( tina, paul )
   grantParents( carl, paul )
   grantParents( tina, jill )
   grantParents( tina, peter )
   grantParents( carl, jill )
   grantParents( carl, peter )
   grantParents( janet, jill )
   grantParents( janet, paul )
   grantParents( janet, peter )
   grantParents( john, jill )
   grantParents( john, paul )
   grantParents( john, peter )




More information about the rules-dev mailing list