Is there a java implementation of Porter2 stemmer

bikashg picture bikashg · Dec 9, 2010 · Viewed 14.3k times · Source

Do you know any java implementation of the Porter2 stemmer(or any better stemmer written in java)? I know that there is a java version of Porter(not Porter2) here :

http://tartarus.org/~martin/PorterStemmer/java.txt

but on http://tartarus.org/~martin/PorterStemmer/ the author mentions that the Porter is bit outdated and recommends to use Porter2, available at

http://snowball.tartarus.org/algorithms/english/stemmer.html

However, the problem with me is that this Porter2 is written in snowball(I never heard of it before, so don't know anything about it). What I am exactly looking for is a java version of it.

Thanks. Your help will he highly appreciated.

Answer

Joel picture Joel · Dec 9, 2010

The Snowball algo is available as a Java download

And from snowball.tartarus.org:

Feb 2002 - Java support Richard has modified the snowball code generator to produce Java output as well as ANSI C output. This means that pure Java systems can now use the snowball stemmers.

This is what you want, right?

You can create an instance of it like so:

  Class stemClass = Class.forName("org.tartarus.snowball.ext." + lang + "Stemmer");
  stemmer = (SnowballProgram) stemClass.newInstance();
  stemmer.setCurrent("your_word");
  stemmer.stem();
  String your_stemmed_word = stemmer.getCurrent();