blob: af2b6f3e04dc6dd9429daee351507fab1f325839 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/* 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));
}
}
|