get word base

Daniel Yoo dyoo at hkn.eecs.berkeley.edu
Fri Jun 28 17:02:17 EDT 2002


John Hunter <jdhunter at nitace.bsd.uchicago.edu> wrote:

: I would like to be able to get the root/base of a word by stripping
: off plurals, gerund endings, participle endings etc...

Hi John,


PyWordNet has a function in it called wntools.morphy() which tries to
take the morphological root of a word.  For example:

###
>>> import wntools
>>> words = ['hello', 'taxes', 'thoughts', 'walked', 'rakes']
>>> for w in words: print wntools.morphy(w)
... 
hello
tax
thought
None
rake
###

morphy() doesn't quite work out of the box, but just because it
doesn't guess the part of speech --- morphy() assumes that we want the
noun root by default.  But then, we can do something like this:

###
>>> def root(w):
...     return wntools.morphy(w, "noun") or wntools.morphy(w, "verb")
... 
>>> root("walked")
'walk'
>>> root("sent")
'send'
>>> root("woke")
'wake'
###

So PyWordNet is a really useful tool if you're doing this sort of
stuff.  PyWordNet and Wordnet can be found here:

    http://pywordnet.sourceforge.net/
    http://www.cogsci.princeton.edu/~wn/

Best of wishes to you!



More information about the Python-list mailing list