Advertisement
alvations

Stem2Word

Apr 25th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. >>> from nltk.corpus import wordnet as wn
  2. >>> from nltk.stem import PorterStemmer
  3. >>> from difflib import get_close_matches as gcm
  4. >>> from itertools import chain
  5. >>> dictionary = set(chain(*[i.lemma_names() for i in wn.all_synsets()]))
  6. >>> len(dictionary)
  7. 148730
  8. >>> porter = PorterStemmer()
  9. >>> stemmed = porter.stem('force')
  10. >>> gcm(stemmed, dictionary)
  11. [u'force', u'formic', u'forced']
  12. >>> gcm(stemmed, dictionary)[0]
  13. u'force'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement