diff options
Diffstat (limited to 'Algorithms/Part-II/1-WordNet/Outcast.java')
-rw-r--r-- | Algorithms/Part-II/1-WordNet/Outcast.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/Algorithms/Part-II/1-WordNet/Outcast.java b/Algorithms/Part-II/1-WordNet/Outcast.java index 296fd79..af2b6f3 100644 --- a/Algorithms/Part-II/1-WordNet/Outcast.java +++ b/Algorithms/Part-II/1-WordNet/Outcast.java @@ -2,26 +2,50 @@ public class Outcast { + private WordNet wordNet; + // constructor takes a WordNet object public Outcast(WordNet wordnet) { + wordNet = wordnet; } // given an array of WordNet nouns, return an outcast public String outcast(String[] nouns) { - return ""; + int maxTotal = -1; + String outcast = null; + + for (int i = 0; i < nouns.length; i++) { + int total = 0; + for (int j = 0; j < nouns.length; j++) { + total = total + wordNet.distance(nouns[i], nouns[j]); + } + + if (total > maxTotal) { + maxTotal = total; + outcast = nouns[i]; + } + } + + return outcast; } // for unit testing of this class (such as the one below) public static void main(String[] args) { - WordNet wordnet = new WordNet(args[0], args[1]); + WordNet wordnet = new WordNet("./data/synsets.txt", "./data/hypernyms.txt"); Outcast outcast = new Outcast(wordnet); - for (int t = 2; t < args.length; t++) { - String[] nouns = In.readStrings(args[t]); - StdOut.println(args[t] + ": " + outcast.outcast(nouns)); - } + String[] nouns; + + nouns = new In("./data/outcast5.txt").readAllStrings(); + StdOut.println(outcast.outcast(nouns)); + + nouns = new In("./data/outcast8.txt").readAllStrings(); + StdOut.println(outcast.outcast(nouns)); + + nouns = new In("./data/outcast11.txt").readAllStrings(); + StdOut.println(outcast.outcast(nouns)); } } |