适当的jpl.jar库版本

时间:2015-06-28 12:34:42

标签: java eclipse swi-prolog jpl

import java.util.Hashtable;
import jpl.*;
import jpl.Query;

public class Family {
    public static void main( String argv[] ) {

      String t1 = "consult('C:/Users/Kostas/Desktop/family.pl')";
      Query  q1 = new Query(t1);

      System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed"));

     //---

      String t2 = "child_of(joe, ralf)";
      Query  q2 = new Query(t2);

      System.out.println(q2.hasSolution());

     //---

      String t3 = "descendent_of(X, ralf)";
      Query  q3 = new Query(t3);

      java.util.Hashtable[] s3 = q3.allSolutions();

      System.out.println("all solutions of " + t3);

      for (int i = 0; i < s3.length; i++) {
        System.out.println("X = " + s3[i].get("X"));
      }  
   }
}

输出:

consult('C:/Users/Kostas/Desktop/family.pl') succeeded
true
all solutions of descendent_of(X, ralf)   
X = null
X = null
X = null

%family.pl

child_of(joe, ralf).
child_of(mary, joe).
child_of(steve, joe).

descendent_of(X, Y) :-
   child_of(X, Y).
descendent_of(X, Y) :-
   child_of(Z, Y),
   descendent_of(X, Z).

您好,

我在Eclipse上运行上面的代码。通常它没关系,除非我使用变量。在上述情况下,它应该打印出来:

X = joe
X = mary
X = steve

而是打印'X = null'。

此前有人问过同样的问题: https://stackoverflow.com/questions/30495077/swi-prolog-returns-null-but-hassolutions-true-and-also-allsolutions-is-true

问这个问题的人说这是由于 jpl.jar文件。如果这是问题,我在哪里可以找到合适的jpl.jar版本来解决我的问题?请注意,最近我下载了最新版本的SWI-Prolog,其中可能还包含最新版本的jpl.jar库文件。这是我使用的版本。

感谢。

0 个答案:

没有答案