-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stemmer.java
49 lines (39 loc) · 1.17 KB
/
Stemmer.java
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
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import edu.mit.jwi.Dictionary;
import edu.mit.jwi.IDictionary;
import edu.mit.jwi.item.POS;
import edu.mit.jwi.morph.WordnetStemmer;
public class Stemmer {
private final String PATH = "/usr/local/WordNet-3.0" + File.separator + "dict";
private static final String VERB = "verb";
private static final String ADJECTIVE = "adjective";
private static final String ADVERB = "adverb";
private static final String NOUN = "noun";
private WordnetStemmer stemmer;
private URL url;
private IDictionary dict;
public Stemmer() throws IOException {
this.url = new URL ("file", null, PATH);
this.dict = new Dictionary (url);
dict.open();
this.stemmer = new WordnetStemmer (dict);
}
public List<String> getStems(String word, String pos) {
switch (pos) {
case VERB :
return stemmer.findStems(word, POS.VERB);
case ADJECTIVE :
return stemmer.findStems(word, POS.ADJECTIVE);
case ADVERB :
return stemmer.findStems(word, POS.ADVERB);
case NOUN :
return stemmer.findStems(word, POS.NOUN);
default :
return Collections.emptyList();
}
}
}