Skip to content

Instantly share code, notes, and snippets.

@LLCampos
Created November 15, 2016 17:13
Show Gist options
  • Save LLCampos/8536db8f90a98cafa46c2527d5db0f07 to your computer and use it in GitHub Desktop.
Save LLCampos/8536db8f90a98cafa46c2527d5db0f07 to your computer and use it in GitHub Desktop.
Singularize (change to the singular form) all the words in a piece of text
from pattern.en import singularize
from nltk import word_tokenize
def singularize_all_words(text):
tokenized_text = word_tokenize(text)
tokenized_singularized_text = map(singularize, tokenized_text)
singularized_text = ' '.join(tokenized_singularized_text)
return singularized_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment