【问题标题】:Java-Prolog: How to pass arguments to arity 2 query?Java-Prolog:如何将参数传递给 arity 2 查询?
【发布时间】:2015-02-23 14:03:54
【问题描述】:

我是 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());

结果:“Jill 是女性吗?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 运行查询

【问题讨论】:

    标签: java prolog ffi swi-prolog


    【解决方案1】:

    怎么样:

    new Query("parent", new Term[] {new Atom("Jill"),new Atom("John")});
    

    new Term[] 表示你初始化了一个数组,显然你可以用多个原子来调用它。

    请参阅查询数据库部分下的this documentation

    【讨论】:

    • 伊皮!多谢! ^^
    猜你喜欢
    • 2017-03-08
    • 2017-05-28
    • 2018-02-11
    • 1970-01-01
    • 2018-09-30
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多