我是Prolog和Java的初学者 . 我试图将我的Prolog程序与Java链接 . 我找到了怎么做here . 但是我不知道如何用arity 2将参数传递给Prolog查询 . 这是我的prolog程序的一部分:
male(Jack).
male(John).
female(Jill).
couple(Jack,Jill).
parent(Jack,John).
parent(Jill,John).
这来自我的Java:
Query q1 = new Query("female", new Term[] {new Atom("Jill")});
System.out.println("Is Jill female? " + q1.hasSolution());
结果是:“是吉尔女性吗? true ”
Query q2 = new Query(new Compound("male", new Term[] {new Variable("X")}));
int i=0;
while(q2.hasMoreSolutions()){
i++;
System.out.print(i + ") " +q2.nextSolution().get("X"));
}
结果:“1)杰克2)约翰”
但我不知道如何使用arity 2运行查询
1 回答
关于什么:
new Term[]
意味着你初始化一个数组,显然,你可以用多个原子来调用它 .请参阅“查询数据库”部分下的this documentation .