public WordNet(String synsetFileName, String hyponymFileName) { In synsetFile = new In(synsetFileName); In hyponymFile = new In(hyponymFileName); String[] currentLine; String[] splitNouns; while (!synsetFile.isEmpty()) { currentLine = synsetFile.readLine().split(","); map.put(Integer.parseInt(currentLine[0]), currentLine[1]); splitNouns = currentLine[1].split(" "); for (int i = 0; i < splitNouns.length; i += 1) { if (!nouns.contains(splitNouns[i])) { nouns.add(splitNouns[i]); } } } synsets = new Digraph(map.size()); while (!hyponymFile.isEmpty()) { currentLine = hyponymFile.readLine().split(","); for (int i = 1; i < currentLine.length; i++) { synsets.addEdge(Integer.parseInt(currentLine[0]), Integer.parseInt(currentLine[i])); } } }
// constructor takes a digraph (not necessarily a DAG) public SAP(Digraph G) { digraph = new Digraph(G.V()); for (int v = 0; v < G.V(); v++) { for (int w : G.adj(v)) { digraph.addEdge(v, w); } } }
// constructor takes the name of the two input files public WordNet(String synsets, String hypernyms) { ifNullThrowException(synsets); ifNullThrowException(hypernyms); st = new LinearProbingHashST<String, ArrayList<Integer>>(); In in = new In(synsets); int len = 0; int No; String[] words; ArrayList<String> tempKeys = new ArrayList<String>(); while (in.hasNextLine()) { String[] a = in.readLine().split(","); tempKeys.add(a[1]); No = Integer.parseInt(a[0]); words = a[1].split(" "); for (String word : words) { if (st.contains(word)) { st.get(word).add(No); } else { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(No); st.put(word, list); } } len++; } keys = new String[len]; tempKeys.toArray(keys); G = new Digraph(len); in = new In(hypernyms); while (in.hasNextLine()) { String temp = in.readLine(); String[] a = temp.split(","); int v = Integer.parseInt(a[0]); for (int i = 1; i < a.length; i++) { int w = Integer.parseInt(a[i]); G.addEdge(v, w); } } ifNotDagThrowException(G); sap = new SAP(G); }