blob: e9d791146e59d499d095cccafdef9b21d1aff8cb (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/* 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;
Stopwatch st = new Stopwatch();
double t0, t1 = 0;
nouns = new In("./data/outcast5.txt").readAllStrings();
t0 = st.elapsedTime();
StdOut.println(outcast.outcast(nouns)+" " + (t0 - t1));
t1 = t0;
nouns = new In("./data/outcast8.txt").readAllStrings();
t0 = st.elapsedTime();
StdOut.println(outcast.outcast(nouns)+" " + (t0 - t1));
t1 = t0;
nouns = new In("./data/outcast11.txt").readAllStrings();
t0 = st.elapsedTime();
StdOut.println(outcast.outcast(nouns)+" " + (t0 - t1));
t1 = t0;
nouns = new In("./data/outcast29.txt").readAllStrings();
t0 = st.elapsedTime();
StdOut.println(outcast.outcast(nouns)+" " + (t0 - t1));
t1 = t0;
}
}
|