我使用JPL库连接Prolog和Java。在Prolog中,我可以执行查询:
?- meaning_forms([apple,is,fruit],X).
输出是:X = [is_a(x1, x2), objectx(x1, apple), objectx(x2, fruit)].
但是在Java中,我看不到此查询的输出。我在Java中尝试了一些代码:
Variable X = new Variable("X");
Query q4 = new Query("meaning_forms", new Term[]{new Atom("apple,is,fruit"),X});
while ( q4.hasMoreElements() ) {
java.util.Hashtable solution = (Hashtable) q4.nextElement();
System.out.println( "X = " + (Term) solution.get("X"));
}
Java中没有输出。对这种情况有任何解决方案吗?
Hashtable[] solutions = q4.allSolutions();
for (int i = 0 ; i < solutions.length; ++i) {
System.out.println("X = " + solutions[i].get(X));
}
另请参见http://www.swi-prolog.org/packages/jpl/java_api/getting_started.html