Files
gf-core/src/runtime/java/Test.java
kr.angelov 9bc5349e62 change in the API for literals
The API in the C runtime as well as in the Haskell, Python and Java binding
is changed. Now instead of adding the literal callbacks to the concrete syntax
you need to supply them every time when you need to parse. The main reason is:

- referentially transparent API for Haskell
- when we start using memory mapped files we will not be allowed to change
  anything in the grammar data structures. At that point the old API would
  be impossible to use.
2014-12-16 10:21:26 +00:00

35 lines
1.0 KiB
Java

import java.io.*;
import java.util.*;
import org.grammaticalframework.pgf.*;
public class Test {
public static void main(String[] args) throws IOException {
PGF gr = null;
try {
gr = PGF.readPGF("/home/krasimir/www.grammaticalframework.org/examples/phrasebook/Phrasebook.pgf");
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
} catch (PGFError e) {
e.printStackTrace();
return;
}
Type typ = gr.getFunctionType("Bulgarian");
System.out.println(typ.getCategory());
System.out.println(gr.getAbstractName());
for (Map.Entry<String,Concr> entry : gr.getLanguages().entrySet()) {
System.out.println(entry.getKey()+" "+entry.getValue()+" "+entry.getValue().getName());
}
Concr eng = gr.getLanguages().get("SimpleEng");
try {
for (ExprProb ep : eng.parse(gr.getStartCat(), "persons who work with Malmö")) {
System.out.println("["+ep.getProb()+"] "+ep.getExpr());
}
} catch (ParseError e) {
System.out.println("Parsing failed at token \""+e.getToken()+"\"");
}
}
}