I've tried PorterStemmer and Snowball but both don't work on all words, missing some very common ones.
My test words are: "cats running ran cactus cactuses cacti community communities", and both get less than half right.
See also:
I've tried PorterStemmer and Snowball but both don't work on all words, missing some very common ones.
My test words are: "cats running ran cactus cactuses cacti community communities", and both get less than half right.
See also:
Martin Porter wrote Snowball (a language for stemming algorithms) and rewrote the "English Stemmer" in Snowball. There are is an English Stemmer for C and Java.
He explicitly states that the Porter Stemmer has been reimplemented only for historical reasons, so testing stemming correctness against the Porter Stemmer will get you results that you (should) already know.
Dr. Porter suggests to use the English or Porter2 stemmers instead of the Porter stemmer. The English stemmer is what's actually used in the demo site as @StompChicken has answered earlier.
I highly recommend using Spacy (base text parsing & tagging) and Textacy (higher level text processing built on top of Spacy).
Lemmatized words are available by default in Spacy as a token's
.lemma_
attribute and text can be lemmatized while doing a lot of other text preprocessing with textacy. For example while creating a bag of terms or words or generally just before performing some processing that requires it.I'd encourage you to check out both before writing any code, as this may save you a lot of time!
Try this one here: http://www.twinword.com/lemmatizer.php
I entered your query in the demo
"cats running ran cactus cactuses cacti community communities"
and got["cat", "running", "run", "cactus", "cactus", "cactus", "community", "community"]
with the optional flagALL_TOKENS
.Sample Code
This is an API so you can connect to it from any environment. Here is what the PHP REST call may look like.
I use stanford nlp to perform lemmatization. I have been stuck up with a similar problem in the last few days. All thanks to stackoverflow to help me solve the issue .
It also might be a good idea to use stopwords to minimize output lemmas if it's used later in classificator. Please take a look at coreNlp extension written by John Conwell.
The top python packages (in no specific order) for lemmatization are:
spacy
,nltk
,gensim
,pattern
,CoreNLP
andTextBlob
. I prefer spaCy and gensim's implementation (based on pattern) because they identify the POS tag of the word and assigns the appropriate lemma automatically. The gives more relevant lemmas, keeping the meaning intact.If you plan to use nltk or TextBlob, you need to take care of finding the right POS tag manually and the find the right lemma.
Lemmatization Example with spaCy:
Lemmatization Example With Gensim:
The above examples were borrowed from in this lemmatization page.
You could use the Morpha stemmer. UW has uploaded morpha stemmer to Maven central if you plan to use it from a Java application. There's a wrapper that makes it much easier to use. You just need to add it as a dependency and use the
edu.washington.cs.knowitall.morpha.MorphaStemmer
class. Instances are threadsafe (the original JFlex had class fields for local variables unnecessarily). Instantiate a class and runmorpha
and the word you want to stem.