-->

Getting word stems with JWI and Wordnet

2019-04-09 14:48发布

问题:

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.

回答1:

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".



回答2:

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



回答3:

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") );


标签: java wordnet jwi