Core NLTK model/data files (punkt, tagger, stopwords, wordnet, etc.) packaged for pip installation
Project description
nltk-extratokenizers User Guide
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.
Quick Start
1. Clone and Install Patched NLTK
Open PowerShell and run:
git clone https://github.com/Julien-ser/nltk_Group1_ENGG4450.git
cd nltk_Group1_ENGG4450
python -m pip install --upgrade pip setuptools
python -m pip install -e .
2. Install the Data Package
python -m pip install nltk-extratokenizers
Running Tests
To validate your installation and run all tests:
-
Install test dependencies:
python -m pip install -r requirements-test.txt python -m pip install pytest pytest-mock
-
Run the test suite:
pytest nltk/test
Troubleshooting & Validation
Common Issues & Solutions
1. Missing regex Module
If you see ModuleNotFoundError: No module named 'regex':
python -m pip install regex
Or rely on the fallback to Python's re module (less feature-complete).
2. Missing pytest-mock Plugin
If you see fixture 'mocker' not found when running tests:
python -m pip install pytest-mock
3. SyntaxError in Test File
If you see a SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes, check for stray shell commands in your Python files and remove them.
4. RecursionError in Zip Pointer Test
If you see RecursionError: maximum recursion depth exceeded in test_find_zip_root_returns_zip_pointer, ensure all zipfile mocks are complete and stub classes are present.
Usage Examples
Once installed, you can use NLTK tokenizers and other resources without calling nltk.download():
Sentence Tokenizer
from nltk.tokenize import PunktSentenceTokenizer
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.']
Word Tokenizer
from nltk.tokenize import word_tokenize
tokens = word_tokenize("Natural language processing is fun!")
print(tokens)
# Output: ['Natural', 'language', 'processing', 'is', 'fun', '!']
Stopwords
from nltk.corpus import stopwords
english_stops = set(stopwords.words('english'))
print('the' in english_stops) # True
POS Tagger
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
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 Steps
1. Check Package Installation
python -m 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
...etc
3. Verify Data Loading from Pip Package
import nltk
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.")
What's Included
This package provides the following NLTK data resources:
- punkt (Sentence tokenizer models)
- averaged_perceptron_tagger (POS tagger)
- stopwords (Stopword lists)
- 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)
Requirements
- Python 3.8 or higher
- Patched NLTK 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:
- 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.
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
Publishing to PyPI
To publish this package to PyPI, follow these steps in PowerShell:
1. Build the Package
python -m pip install --upgrade build
python -m build
# This creates a 'dist/' folder with your package files
2. Upload to PyPI
python -m pip install --upgrade twine
python -m twine upload dist/*
# Enter your PyPI username and password when prompted
3. (Optional) Test Upload to TestPyPI
python -m twine upload --repository testpypi dist/*
# Visit https://test.pypi.org/project/nltk-extratokenizers/ to verify
Note:
- Make sure your
pyproject.tomland/orsetup.pyare correctly filled out with package metadata. - You must have a PyPI account. Register at https://pypi.org/account/register/
- For more details, see the official PyPI packaging guide.
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.2.tar.gz.
File metadata
- Download URL: nltk_extratokenizers-0.1.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b40516d68215be6d3d210fe4eef573ffcb536e7da06e7b11c01dd680ffa9044f
|
|
| MD5 |
359c3167005d2544ba265a53425269bf
|
|
| BLAKE2b-256 |
4b7ac17cfee536e462f3ec83e848ae1e251183e238541eeaa82f2388369a89c7
|
File details
Details for the file nltk_extratokenizers-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nltk_extratokenizers-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.7 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 |
78b0edd52a4267138757bb5ce41c63698675fa05b78bd901618bce53ff9d47de
|
|
| MD5 |
f7b738747b280e312be6dff2d1ede85e
|
|
| BLAKE2b-256 |
6a6044123c16859c95f6b443b4fab466947116ab9ec019485b0b2a452b9911e9
|