gpt4 book ai didi

java - Prolog/tuprolog,一行返回 'The enitire [sic] string could not be read as one term'

转载 作者:行者123 更新时间:2023-12-01 23:20:01 25 4
gpt4 key购买 nike

tl:dr - 我有一行 prolog,在一个版本的 Prolog (SWI) 中工作正常,但在另一个版本 (TuProlog) 中则不行。

我正在将脚本从 SWI prolog 移植到 Tuprolog。 (TuProlog 最近做了一次大更新,我在两个版本上都得到了相同的行为)

当我使用下面的 java 设置将脚本放入 TuProlog 时,出现错误“整个字符串无法作为一个术语读取”。

所以我减少了脚本(有效地使用二分搜索),直到将脚本减少为:

iterm3(Term) --> "'", notquote(Cs), "'", { name(Term1,Cs), Term = q(Term1) }.

虽然滑动很好,但输出如下......

cobrakai:~ josephreddington$ swipl -s /Users/josephreddington/Documents/workspace/com.plancomps.prolog.helloworld/caml-light-dynamics/Tools/Prolog/temp.pl% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,992 bytes% /Users/josephreddington/Documents/workspace/com.plancomps.prolog.helloworld/caml-light-dynamics/Tools/Prolog/temp.pl compiled 0.00 sec, 1,720 bytes
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.5)
Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?-

但在 Tuprolog 中仍然返回“整个字符串无法被读取为一个术语” - 谁能告诉我为什么会发生这种情况?

附录:使用的代码:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import alice.tuprolog.NoMoreSolutionException;
import alice.tuprolog.NoSolutionException;
import alice.tuprolog.Prolog;
import alice.tuprolog.SolveInfo;
import alice.tuprolog.Theory;

public class EntireStringForStackOverflow {
public static void main(String[] args) throws Exception {
Prolog engine = new Prolog();
engine.loadLibrary("alice.tuprolog.lib.DCGLibrary");
engine.addTheory(new Theory(readFile("temp.pl")));
}

private static String readFile(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
return stringBuilder.toString();
}
}

最佳答案

我猜可能是 Tuprolog 中需要引用单引号。我会尝试

iterm3(Term) --> "\'", notquote(Cs), "\'", { name(Term1,Cs), Term = q(Term1) }.

编辑 现在我必须承认我不知道 tuProlog DCG 的文档在哪里,而且我也不能花太多时间搜索它(我可以阅读 实际上)。对你的语法的另一个修改,你可以在其中看到为什么我建议上面无用的修改:

iterm3(Term) --> ['\''], notquote(Cs), ['\''], { name(Term1,Cs), Term = q(Term1) }.

也就是说,通过 try-and-fail 来验证 tuProlog 中是否禁止使用双引号常量...

关于java - Prolog/tuprolog,一行返回 'The enitire [sic] string could not be read as one term',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17784581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com