- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 Prolog 文件。条款及细则如下:
子句.pl
get(mary,milk).
go(sandra,kitchen,1).
get(john,football).
go(john,hallway,1).
go(mary,garden,1).
go(john,kitchen,2).
规则.pl
/* X = person Y=location T,T2= time
This rule finds last location of a person */
isAt(X,Y) :- go(X, Y, T), \+ (go(X,_,T2), T2 > T).
/* This rule finds the last location of an object */
whereIs(Q,R) :- findall(R,(get(P,Q,I),go(P,R,_)),L), last(L,R),!.
当我创建一个查询来通过以下方式查找 John 在 Java 中的位置时:
//include the prolog file with clauses to test
File clauseFile = new File ("clauses_qa2.pl");
File ruleFile = new File ("rules.pl");
String clausePath = clauseFile.getAbsolutePath();
String rulePath = ruleFile.getAbsolutePath();
System.out.println("Clause file path: " + clausePath);
System.out.println("Rule file path: " + rulePath);
String t1 = "consult('" + clausePath + "').";
String t2 = "consult('" + rulePath + "').";
jpl.JPL.init();
Query q1 = new Query(t1);
Query q2 = new Query(t2);
Variable X = new Variable("_");
Variable Y = new Variable();
Query q = new Query("isAt",new Term[]{new Atom("john"),X,Y});
while (q.hasMoreElements()) {
Hashtable binding = (Hashtable) q.nextElement();
Term t = (Term) binding.get(X);
System.out.println(t);
}
System.out.println(q.toString());
我收到以下错误:
Exception in thread "main" jpl.PrologException: PrologException: error(existence_error(procedure, /(isAt, 3)), context(:(system, /('$c_call_prolog', 0)), _1))
at jpl.Query.get1(Query.java:336)
at jpl.Query.hasMoreSolutions(Query.java:258)
at jpl.Query.hasMoreElements(Query.java:472)
但是,如果我删除 while 循环并简单地打印出查询,我会从 Prolog 得到以下响应:
Clause file path: G:\Natural Language Final Project\PrologTest\clauses_qa2.pl
Rule file path: G:\Natural Language Final Project\PrologTest\rules.pl
isAt( john, _, _0 )
所以我知道至少查询是从 Java 到 Prolog 的。关于可能导致错误的原因有什么想法吗?
注意:原来我的文件路径不正确。更改代码以创建查询,如下所示:
static void
test_1()
{
Variable X = new Variable();
Term args[] = {
new Atom( "john" ),
X
};
Query query =
new Query(
"isAt",
args );
System.out.println( "iSAt(john, X) = " + query.query() );
}
public static void main(String[] args) throws IOException {
//include the prolog file with clauses to test
File clauseFile = new File ("G:\\Natural Language Final Project\\PrologTest\\src\\clauses_qa2.pl");
File ruleFile = new File ("G:\\Natural Language Final Project\\PrologTest\\src\\rules.pl");
String clausePath = clauseFile.getAbsolutePath();
String rulePath = ruleFile.getAbsolutePath();
System.out.println("Clause file path: " + clausePath);
System.out.println("Rule file path: " + rulePath);
String t1 = "consult('" + "G:\\Natural Language Final Project\\PrologTest\\src\\clauses_qa2.pl"+"').";
String t2 = "consult('" + "G:\\Natural Language Final Project\\PrologTest\\src\\rules.pl"+"').";
/*Scanner scan = new Scanner(ruleFile);
while (scan.hasNextLine()){
System.out.println(scan.nextLine());
}*/
jpl.JPL.init();
Term consult_arg[] = {
new Atom( "G:\\Natural Language Final Project\\PrologTest\\src\\clauses_qa2.pl")
};
Query consult_query =
new Query(
"consult",
consult_arg );
Term consult_arg2[] = {
new Atom( "G:\\Natural Language Final Project\\PrologTest\\src\\rules.pl")
};
Query consult_query2 =
new Query(
"consult",
consult_arg2);
boolean consulted = consult_query.query()&& consult_query2.query();
if ( !consulted ){
System.err.println( "Consult failed" );
System.exit( 1 );
}
test_1();
Variable X = new Variable("_");
Variable Y = new Variable();
Query q = new Query("isAt",new Term[]{new Atom("john"),X});
while (q.hasMoreElements()) {
Hashtable binding = (Hashtable) q.nextElement();
Term t = (Term) binding.get(X);
System.out.println(t);
}
System.out.println(q.toString());
}
产生以下输出:
iSAt(john, X) = true
null
isAt( john, _ )
这比编译器错误更好,但答案应该是:
isAt(john,X)
X= kitchen
最佳答案
我没有足够的声誉,否则我会将此作为评论......
我怀疑问题在于 isAt() 的元数为 2,但查询使用的是元数为 3 的 isAt():isAt(john, X, Y)。
关于java - SWI Prolog Java jpl.PrologException 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38959798/
谁赋予了 SWI-Prolog 幽默感? Welcome to SWI-Prolog (threaded, 64 bits, version 7.3.35) SWI-Prolog comes with
简单的例子: ?- between(1,10,X). X = 1 ; X = 2 ; X = 3 ; X = 4 ; X = 5 ; X = 6 ; X = 7 ; X = 8 ; X = 9 ; X
我有这个字符串: B='Dogs cats birds and fish'. 我需要它以下面的格式出现: Dogs, cats, birds, and fish 有没有可能发生这种情况? 我试过 nl
我正在为 Prolog 查询编写一个部分评估器。我尝试使用 expand_goal/2 扩展查询,但它只是统一了 Input与 Output在这种情况下: :- initialization(main
在 SWI Prolog 终端中如何查看当前工作目录并更改当前工作目录? 我发现: 工作目录(CWD,CWD) 但我不认为这是我需要的 最佳答案 要获取当前工作目录,请使用 working_direc
如何关闭 swi-prolog 中的警告。 Clauses of XXX/AA are not together in the source-file 很烦人。 最佳答案 相反,您可以修复警告。 di
我正在尝试使用此处文档中所谓的内置谓词 split_string/4:http://www.swi-prolog.org/pldoc/man?predicate=split_string/4 但是,当
从https://stackoverflow.com/a/44524628?noredirect=1跟进 :-use_module(library(http/http_client)). :-use_
我在序言SWI与CHR(约束处理规则)创建多个谜题解决者 一切都很好,但是,我喜欢测试哪个求解器是最好的。 因此,我想搞清楚,这解算器使用回溯的最少。 是否有一种聪明的方法可以找出(或打印出)求解器解
我正在尝试开发有关使用 swi-prolog 的常见问题解答(faq)。我将 swi-prolog 用于桌面(AMD64,多线程,版本 8.2.3)。 常见问题解答中的问题和答案以土耳其的母语编写。当
我在 Prolog 中编写了一个快速谓词,尝试使用 CLP(FD) 及其求解方程组的能力。 problem(A, B) :- A-B #= 320, A #= 21*B. 当我在 SW
我对 prolog 很困惑,它与我曾经使用过的任何语言(多种语言)都不同,我如何从以下位置获取 argv[0]: current_prolog_flag(argv, Argv), write(Argv
我正在尝试使用SWI-prolog将规则动态添加到知识库中,其中该规则的主体事先未知。 所需的规则如下所示: rule(a) :- fact(1), fact(2). 通常,您只需声明 assert(
我正在使用 SWI-Prolog 并且我正在尝试打印一个列表,但是如果该列表有 9 个以上的项目 - 它看起来像这样 - [1, 15, 8, 22, 5, 19, 12, 25, 3|...] 有没
我将用户输入重定向到文件see('entradasaida.txt')。很好 虽然,当我尝试从该流输入文件读取时,swi给了我这个错误: ERROR: entradasaida.txt:3:0: Sy
在“序言中的专家系统”一书中,我遇到了一个障碍。书中定义了一个简单的shell如下: solve :- abolish(known, 3), define(known, 3), to
我正在尝试比较 prolog 中的两个 peano 数,但有些结果是错误的。 任何人都可以帮助我,这是我的代码: %Not Equal notequal(0,s(A),X). notequal(s(A
假设我有一个包含以下内容的文件 main.pl /* I tried these one at a time, not all at once... */ [externalFile]. ['exte
append/3是一个非常强大的谓词。假设我想要一个以相同方式工作的谓词,但对于 SWI-Prolog 的字符串。 我看到的最简单的方法是使用 string_codes/2 将这些字符串转换为列表。
我正在努力理解如何正确使用 discontiguous/1 (SWI) Prolog 中的谓词。 让 buumi.pl成为这个伪事实的小文件: discontiguous(buumi/1). buum
我是一名优秀的程序员,十分优秀!