00001 import java.util.Hashtable;
00002 import jpl.*;
00003 import jpl.Query;
00004
00005 public class Family
00006 {
00007 public static void
00008 main( String argv[] )
00009 {
00010
00011 String t1 = "consult('family.pl')";
00012 Query q1 = new Query(t1);
00013
00014 System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed") );
00015
00016
00017
00018 String t2 = "child_of(joe, ralf)";
00019 Query q2 = new Query(t2);
00020
00021 System.out.println( t2 + " is " + (q2.hasSolution() ? "provable" : "not provable") );
00022
00023
00024
00025 String t3 = "descendent_of(steve, ralf)";
00026 Query q3 = new Query(t3);
00027
00028 System.out.println( t3 + " is " +(q3.hasSolution() ? "provable" : "not provable") );
00029
00030
00031
00032 String t4 = "descendent_of(X, ralf)";
00033 Query q4 = new Query(t4);
00034
00035 System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X"));
00036
00037
00038
00039 java.util.Hashtable[] ss4 = q4.allSolutions();
00040
00041 System.out.println( "all solutions of " + t4);
00042 for ( int i=0 ; i<ss4.length ; i++ ) {
00043 System.out.println( "X = " + ss4[i].get("X"));
00044 }
00045
00046
00047
00048 System.out.println( "each solution of " + t4);
00049 while ( q4.hasMoreSolutions() ){
00050 java.util.Hashtable s4 = q4.nextSolution();
00051 System.out.println( "X = " + s4.get("X"));
00052 }
00053
00054
00055
00056 String t5 = "descendent_of(X,Y)";
00057 Query q5 = new Query(t5);
00058
00059 System.out.println( "each solution of " + t5 );
00060 while ( q5.hasMoreSolutions() ){
00061 java.util.Hashtable s5 = q5.nextSolution();
00062 System.out.println( "X = " + s5.get("X") + ", Y = " + s5.get("Y"));
00063 }
00064
00065
00066 }
00067
00068 }
00069
00070