我正在使用tuProlog (http://tuprolog.alice.unibo.it/)从java内部运行一些prolog子句。我在Definite子句语法方面遇到了一些问题,我认为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代码(已经在其他prolog示例中测试过)将其放入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 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).欢迎有想法..。
发布于 2013-05-21 16:47:34
必须显式加载DCG库,因为默认情况下不会加载该库。
您可以通过两种方式完成此操作:
在理论中使用装载库指令,如::-load_library('alice.tuprolog.lib.DCGLibrary').
请参考这里的Google Code存储库(https://code.google.com/p/tuprolog/),在那里您可以找到引擎和手册的最新版本。
干杯
白酒
发布于 2013-05-20 21:25:02
所以我通过电子邮件得到了这个问题的答案(可能对其他人有用...)
在java中,你不能很好地理解发生了什么。有没有可能你想写这样的东西: s:-np,vp?
https://stackoverflow.com/questions/16541383
复制相似问题