* @param path the path of the FST file to read
* @return the highest ID of all nodes
* @throws java.io.IOException
*/
private int createNodes(String path) throws IOException {
ExtendedStreamTokenizer tok = new ExtendedStreamTokenizer(path, true);
int maxNodeId = 0;
while (!tok.isEOF()) {
tok.skipwhite();
String token = tok.getString();
if (token == null) {
break;
} else if (token.equals("T")) {
tok.getInt("src id"); // toss source node
int id = tok.getInt("dest id"); // dest node numb
if (id > maxNodeId) {
maxNodeId = id;
}
String word1 = tok.getString(); // get word
if (word1 == null) {
continue;
}
String word2 = tok.getString(); // get word
tok.getString(); // toss probability
String nodeName = "G" + id;
GrammarNode node = nodes.get(nodeName);
if (node == null) {
if (word2.equals(",")) {
node = createGrammarNode(id, false);
} else {
node = createGrammarNode(id, word2.toLowerCase());
}
nodes.put(nodeName, node);
} else {
if (!word2.equals(",")) {
/*
* if (!word2.toLowerCase().equals(getWord(node))) {
* System.out.println(node + ": " + word2 + ' ' + getWord(node)); }
*/
assert (word2.toLowerCase().equals(getWord(node)));
}
}
}
}
tok.close();
return maxNodeId;
}