【发布时间】:2013-05-14 10:57:16
【问题描述】:
我正在使用 tuProlog (http://tuprolog.alice.unibo.it/) 从 java 内部运行一些 prolog 子句。我在使用定句语法时遇到了一些问题,我认为 Stackoverflow 可能是正确的地方。
使用来自http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse29 的定句语法示例,我们有
s --> np,vp .
np --> det,n.
vp --> v,np.
vp --> v.
det --> [the].
det --> [a].
n --> [woman].
n --> [man].
v --> [shoots].
我用下面的 java 代码把它引入 tuProlog(已经在其他 prolog 示例中测试过)
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 TestDefinateClauseGrammar {
public static void main(String[] args) throws Exception {
Prolog engine = new Prolog();
engine.addTheory(new Theory(readFile("/Users/josephreddington/Documents/workspace/com.plancomps.prolog.helloworld/grammar.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();
}
}
但不幸的是我得到了例外:
Exception in thread "main" alice.tuprolog.InvalidTheoryException: The term 's' is not ended with a period.
at alice.tuprolog.TheoryManager.consult(TheoryManager.java:193)
at alice.tuprolog.Prolog.addTheory(Prolog.java:242)
at TestDefinateClauseGrammar.main(TestDefinateClauseGrammar.java:13)
谁能告诉我这个问题?我知道 tuprolog 应该支持定句语法,因为他们的手册 (http://tuprolog.sourceforge.net/doc/2p-guide.pdf) 包含以下引用:
5.2 ISOLibrary
Library Dependencies: BasicLibrary.
This library contains almost1 all the built-in predicates and functors that
are part of the ISO standard and that are not part directly of the tuProlog
core engine or other core libraries. Moreover, some features are added, not
currently ISO, such as the support for definite clause grammars (DCGs).
欢迎提出想法....
【问题讨论】:
-
可能是序言列表第一行结束句点之前的空格?