This has been talked about WAY too many times, and the consensus is always: its WAY too complicated to be handled through a simple regex. All of the solutions fail with these examples:
apples
carrots
process
processes
tennis
A solution is to use morpha:
git clone https://github.com/knowitall/morpha
cd morpha/
flex -i -Cfea -8 -omorpha.yy.c morpha.lex
gcc -o morpha morpha.yy.c
curl -s https://raw.githubusercontent.com/jhlau/predom_sense/master/lemmatiser_tools/morpha/verbstem.list > verbstem.list
now to test:
cat test.txt | ./morpha -c
apple
carrot
process
process
tennis
If you want a python solution, i suggest you go with nltk
.
virtualenv env-nltk
source env-nltk/bin/activate
pip install nltk
python -c "import nltk; nltk.download()" # <- just get the whole thing, click "all" and then "download" on the "collections" tab
Now that everything is downloaded, lets fire off python
and play with it.
>>> from nltk.stem.wordnet import WordNetLemmatizer
>>> lmtzr = WordNetLemmatizer()
>>> lmtzr.lemmatize('apples')
u'apple'
>>> lmtzr.lemmatize('tennis')
'tennis'
>>> lmtzr.lemmatize('process')
'process'
>>> lmtzr.lemmatize('processes')
u'process'