Created
November 15, 2016 17:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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