-
Notifications
You must be signed in to change notification settings - Fork 827
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
added post_install in setup.py file #3883
Open
christinestraub
wants to merge
15
commits into
main
Choose a base branch
from
Spike--Add-auto-download-for-NLTK
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
340faf8
added post_install in setup.py file
christinestraub eccddc5
upgraded requirements
christinestraub 9d40c40
upgrade requirement versions
christinestraub c3671f1
Merge branch 'main' into Spike--Add-auto-download-for-NLTK
christinestraub d73c0bb
changed contourpy version
christinestraub 0eebd86
Resolve lib version issue
christinestraub 22de886
Fix lint issue
christinestraub de9a5d2
compile requirements using pythn 3.9
christinestraub 31f5c63
Merge branch 'main' into Spike--Add-auto-download-for-NLTK
christinestraub f1f953d
Added download function in tokenize.py
christinestraub b482ad3
Merge branch 'main' into Spike--Add-auto-download-for-NLTK
christinestraub 9f4df12
Fixed import issue
christinestraub df23943
Fixed recurssion issue
christinestraub 26edd0b
Merge branch 'main' into Spike--Add-auto-download-for-NLTK
christinestraub d40220b
modfied change log
christinestraub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,6 @@ | |
CACHE_MAX_SIZE: Final[int] = 128 | ||
|
||
|
||
def download_nltk_packages(): | ||
nltk.download("averaged_perceptron_tagger_eng", quiet=True) | ||
nltk.download("punkt_tab", quiet=True) | ||
|
||
|
||
def check_for_nltk_package(package_name: str, package_category: str) -> bool: | ||
"""Checks to see if the specified NLTK package exists on the image.""" | ||
paths: list[str] = [] | ||
|
@@ -32,6 +27,30 @@ def check_for_nltk_package(package_name: str, package_category: str) -> bool: | |
return False | ||
|
||
|
||
# We cache this because we do not want to attempt | ||
# downloading the packages multiple times | ||
@lru_cache() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the logic below we don't need cache. Further more (this is kind of pathological edge case but...) caching means we could ignore situations where between checks the nltk data is removed. |
||
def download_nltk_packages(): | ||
"""If required NLTK packages are not available, download them.""" | ||
|
||
tagger_available = check_for_nltk_package( | ||
package_category="taggers", | ||
package_name="averaged_perceptron_tagger_eng", | ||
) | ||
tokenizer_available = check_for_nltk_package( | ||
package_category="tokenizers", package_name="punkt_tab" | ||
) | ||
|
||
if (not tokenizer_available) or (not tagger_available): | ||
nltk.download("averaged_perceptron_tagger_eng", quiet=True) | ||
nltk.download("punkt_tab", quiet=True) | ||
|
||
|
||
# auto download nltk packages if the environment variable is set | ||
if os.getenv("AUTO_DOWNLOAD_NLTK", "True").lower() == "true": | ||
download_nltk_packages() | ||
|
||
|
||
@lru_cache(maxsize=CACHE_MAX_SIZE) | ||
def sent_tokenize(text: str) -> List[str]: | ||
"""A wrapper around the NLTK sentence tokenizer with LRU caching enabled.""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra newline