Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lemmatization option for normalizing loaded documents #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pke/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def load_document(self, input, language=None, stoplist=None,
stoplist (list): custom list of stopwords, defaults to
pke.lang.stopwords[language].
normalization (str): word normalization method, defaults to
'stemming'. Other possible value is 'none'
'stemming'. Other possible values are 'lemmatization'
for using lemmas as stems and 'none'
for using word surface forms instead of stems/lemmas.
spacy_model (spacy.lang): preloaded spacy model when input is a
string.
Expand Down Expand Up @@ -119,6 +120,10 @@ def load_document(self, input, language=None, stoplist=None,
for i, sentence in enumerate(self.sentences):
self.sentences[i].stems = [stemmer.stem(w).lower() for w in sentence.words]

elif self.normalization == 'lemmatization':
for i, sentence in enumerate(self.sentences):
self.sentences[i].stems = sentence.meta['lemmas']

else:
for i, sentence in enumerate(self.sentences):
self.sentences[i].stems = [w.lower() for w in sentence.words]
Expand Down