How to do it...

  1. Initialize the stemming process with a new Python file:
from nltk.stem.porter import PorterStemmer 
from nltk.stem.lancaster import LancasterStemmer 
from nltk.stem.snowball import SnowballStemmer 
  1. Let's describe some words to consider, as follows:
words = ['ability', 'baby', 'college', 'playing', 'is', 'dream', 'election', 'beaches', 'image', 'group', 'happy'] 
  1. Identify a group of stemmers to be used:
stemmers = ['PORTER', 'LANCASTER', 'SNOWBALL'] 
  1. Initialize the necessary tasks for the chosen stemmers:
stem_porter = PorterStemmer() 
stem_lancaster = LancasterStemmer() 
stem_snowball = SnowballStemmer('english') 
  1. Format a table to print the results:
formatted_row = '{:>16}' * (len(stemmers) + 1) print 'n', formatted_row.format('WORD', ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.