Core NLTK model/data files (punkt, tagger, stopwords, wordnet, etc.) packaged for pip installation
Project description
nltk-extratokenizers
Core NLTK model/data files packaged for pip installation
nltk-extratokenizers provides essential NLTK data files (tokenizers, taggers, corpora) as a pip-installable package, eliminating the need for nltk.download(). This package implements NLTK Issue #3413 by using Python entry points to make NLTK data available directly from pip.
Installation
pip install nltk-extratokenizers
Important: This package requires a patched version of NLTK that supports entry-point-based data loading. You'll need to use the modified NLTK from this repository:
git clone https://github.com/Julien-ser/nltk_Group1_ENGG4450.git
cd nltk_Group1_ENGG4450
pip install -e .
Then install the data package:
pip install nltk-extratokenizers
What's Included
This package provides the following NLTK data resources:
Tokenizers
- punkt - Sentence tokenizer models
Taggers
- averaged_perceptron_tagger - Part-of-speech tagger
Corpora & Lexical Resources
- stopwords - Stopword lists for multiple languages
- wordnet - WordNet lexical database
- omw-1.4 - Open Multilingual Wordnet
- snowball_data - Snowball stemmer data
- names - Name corpus
- brown - Brown corpus
- movie_reviews - Movie reviews corpus
Usage
Once installed, you can use NLTK tokenizers and other resources without calling nltk.download():
Example: Using Punkt Sentence Tokenizer
from nltk.tokenize import PunktSentenceTokenizer
# No nltk.download() needed!
tok = PunktSentenceTokenizer()
sentences = tok.tokenize("Hello world. This is a test. Another sentence here.")
print(sentences)
# Output: ['Hello world.', 'This is a test.', 'Another sentence here.']
Example: Using Word Tokenizer
from nltk.tokenize import word_tokenize
# Works without nltk.download()
tokens = word_tokenize("Natural language processing is fun!")
print(tokens)
# Output: ['Natural', 'language', 'processing', 'is', 'fun', '!']
Example: Using Stopwords
from nltk.corpus import stopwords
# No download required
english_stops = set(stopwords.words('english'))
print('the' in english_stops) # True
Example: Using POS Tagger
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
# Works without nltk.download()
text = "The quick brown fox jumps over the lazy dog"
tokens = word_tokenize(text)
tags = pos_tag(tokens)
print(tags)
# Output: [('The', 'DT'), ('quick', 'JJ'), ('brown', 'JJ'), ...]
Verification
To verify that the package is working correctly and data is being loaded from the pip package:
1. Check Package Installation
pip show nltk-extratokenizers
2. Verify Entry Points
import importlib.metadata as m
print("nltk_data entry points:")
for ep in m.entry_points(group="nltk_data"):
print(f" {ep.name} -> {ep.value}")
Expected output should include:
punkt -> nltk_punkt.data
averaged_perceptron_tagger -> nltk_punkt.data
stopwords -> nltk_punkt.data
wordnet -> nltk_punkt.data
...
3. Verify Data Loading from Pip Package
import nltk
# Check that punkt tokenizer is loaded from pip package
path = nltk.data.find("tokenizers/punkt/english.pickle")
print(f"Punkt tokenizer location: {path}")
# Should show a path containing 'nltk_punkt' or 'site-packages'
4. Test Tokenizer Functionality
from nltk.tokenize import PunktSentenceTokenizer
try:
tok = PunktSentenceTokenizer()
result = tok.tokenize("Test sentence. Another one!")
print("✓ Punkt tokenizer works correctly!")
print(f" Result: {result}")
except LookupError as e:
print(f"✗ Error: {e}")
print(" Make sure nltk-extratokenizers is installed and NLTK is patched.")
Requirements
- Python 3.8 or higher
- NLTK (patched version from this repository)
- setuptools >= 61.0
How It Works
This package uses Python's entry point system to register NLTK data resources. The patched NLTK's nltk.data.find() function:
- First checks for pip-installed packages via
nltk_dataentry points - Falls back to the standard NLTK data search paths if not found
This allows NLTK data to be distributed and installed via pip, making it easier to manage dependencies and deploy applications.
Troubleshooting
"LookupError: Resource not found"
If you get a LookupError when using NLTK resources:
-
Verify the package is installed:
pip show nltk-extratokenizers
-
Check that you're using the patched NLTK:
import nltk print(nltk.__file__) # Should point to your local NLTK clone, not site-packages
-
Verify entry points are registered:
import importlib.metadata as m eps = list(m.entry_points(group="nltk_data")) print(f"Found {len(eps)} entry points")
"Module not found: nltk_punkt"
If you see import errors, make sure:
- The package is installed:
pip install nltk-extratokenizers - You're using the correct Python environment
Contributing
Contributions are welcome! Please visit the GitHub repository to report issues or submit pull requests.
License
This package is distributed under the Apache License 2.0, same as NLTK.
Related Projects
- NLTK - Natural Language Toolkit
- NLTK GitHub - Official NLTK repository
Citation
If you use this package in your research, please cite:
Bird, Steven, Edward Loper and Ewan Klein (2009).
Natural Language Processing with Python. O'Reilly Media Inc.
Package Name: nltk-extratokenizers
Version: 0.1.0
Repository: https://github.com/Julien-ser/nltk_Group1_ENGG4450
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nltk_extratokenizers-0.1.1.tar.gz.
File metadata
- Download URL: nltk_extratokenizers-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cd2283781b2a2d9a166b57a1c18c8e3a1b56d378194a7dd6c9bc94af215069a
|
|
| MD5 |
3cce9c78e203c5a227b0a4699379dbc6
|
|
| BLAKE2b-256 |
1285337e5b545164419eba4398d3c34a13959b3480b93c5d11eae8b9989b3bf0
|
File details
Details for the file nltk_extratokenizers-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nltk_extratokenizers-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8754a0cd7d21c17e2745056ed9fb6920c3879ed6082eb1efd653f34b5cffc4b7
|
|
| MD5 |
299aa573d38ddf8dad01516eff8c0cbe
|
|
| BLAKE2b-256 |
0572dd18bb0d661a8713e293c55621d20db6eca8c7ff66b5518d7ef7d6460407
|