/* vim: set expandtab tabstop=4 shiftwidth=4 : */ 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) { 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("./data/synsets.txt", "./data/hypernyms.txt"); Outcast outcast = new Outcast(wordnet); 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)); } }