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

Move nltk download to inside the gender augmentation function #93

Merged
merged 5 commits into from
Mar 2, 2024
Merged
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
17 changes: 8 additions & 9 deletions src/langcheck/augment/en/_gender/_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
from langcheck.augment.en._gender._gender_pronouns import (_PRONOUNS_DICT,
_BaseGenderPronouns)

try:
nltk.data.find('averaged_perceptron_tagger')
except LookupError:
nltk.download('averaged_perceptron_tagger')
try:
nltk.data.find('punkt')
except LookupError:
nltk.download('punkt')

# This dictionary is used to determine the form of the pronoun.
# Note that his and hers are not included in this dictionary because they can be
# either of two different forms depending on the context.
Expand Down Expand Up @@ -80,6 +71,14 @@ def _replace_gender_pronouns(
Returns:
str: Augmented text.
"""
try:
nltk.data.find('taggers/averaged_perceptron_tagger')
except LookupError:
nltk.download('averaged_perceptron_tagger')
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
nltk.download('punkt')
tagged_words = pos_tag(word_tokenize(text))
augmented_words = [
_replace_pronoun(word, tag, target_pronouns)
Expand Down
Loading