我使用tuProlog(http://tuprolog.alice.unibo.it/)從java內部運行一些prolog子句。我在定義語句語法中遇到了一些問題,我認爲Stackoverflow可能是正確的地方。tuprolog和確定子句語法
使用從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].
我拉到這個tuProlog與下面的Java代碼(已在其他序言實例測試)
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-14 11:25:28