I'm using tuProlog (http://tuprolog.alice.unibo.it/) to run some prolog clauses from inside java. I'm having some problems with Definite Clause Grammars, and I think Stackoverflow might be the right place.
Using the Definite Clause Grammar example from http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse29, we have
s --> np,vp .
np --> det,n.
vp --> v,np.
vp --> v.
det --> [the].
det --> [a].
n --> [woman].
n --> [man].
v --> [shoots].
I pull this into tuProlog with the following java code (which has been tested on other prolog examples)
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();
}
}
But unfortuantely I get the exception:
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)
Can anyone tell me the problem? I understand that tuprolog should support Definite Clause Grammars because their manual (http://tuprolog.sourceforge.net/doc/2p-guide.pdf) includes the quote:
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).
Ideas welcome....