4

How do I correctly use the stemmer method implemented in MIT's JWI (Java API for WordNet) in order to get the stem of a word? I'm not sure how to initialize a stemmer and use the findStems method.

demongolem
  • 9,474
  • 36
  • 90
  • 105
user573382
  • 343
  • 3
  • 10
  • 22

3 Answers3

6

You don't need an additional library, but you do need a dictionary. You can download one from Princeton: https://wordnet.princeton.edu/wordnet/download/current-version/

I recommend downloading only the dictionary from the section "WordNet 3.1 DATABASE FILES ONLY" Extract the archive. Supposing that PATH/dict is the location of the output you can use this code:

Dictionary dict = new Dictionary(new File("PATH/dict"));
dict.open();
WordnetStemmer stemmer = new WordnetStemmer(dict);

List<String> test = stemmer.findStems("feet", POS.NOUN);
for (int i = 0; i < test.size(); i++) {
    System.out.println(test.get(i));
}

The output for this example is "foot".

nelly
  • 417
  • 3
  • 9
1

This is meant as a comment to sakthi's answer: you actually have to precise which POS you're looking for (noun, adjective, verb, etc.) when calling the findStems method (JWI v2.2.3): http://projects.csail.mit.edu/jwi/api/edu/mit/jwi/morph/IStemmer.html

Vincent Labatut
  • 1,788
  • 1
  • 25
  • 38
0

jar files used are edu.mit.jwi_2.1.4.jar and edu.sussex.nlp.jws.beta.11.jar

JWS ws = new JWS("C:/Program Files/WordNet","2.1");  
WordnetStemmer stem =  new WordnetStemmer(ws.getDictionary());
System.out.println("test" + stem.findStems("reading") );
sakthi
  • 29
  • 1
  • 3