Skip to main content

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:

  1. Install test dependencies:

    python -m pip install -r requirements-test.txt
    python -m pip install pytest pytest-mock
    
  2. 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:

  1. Checks for pip-installed packages via nltk_data entry points
  2. 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.



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:

Metadata

Release files for nltk-extratokenizers 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nltk-extratokenizers 0.1.2
File Size Uploaded
nltk_extratokenizers-0.1.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nltk-extratokenizers 0.1.2
File Interpreter ABI Platform
nltk_extratokenizers-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / nltk_extratokenizers-0.1.2.tar.gz

Download URL nltk_extratokenizers-0.1.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b40516d68215be6d3d210fe4eef573ffcb536e7da06e7b11c01dd680ffa9044f
BLAKE2b-256 checksum
How to use checksums
4b7ac17cfee536e462f3ec83e848ae1e251183e238541eeaa82f2388369a89c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Release files / nltk_extratokenizers-0.1.2-py3-none-any.whl

Download URL nltk_extratokenizers-0.1.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78b0edd52a4267138757bb5ce41c63698675fa05b78bd901618bce53ff9d47de
BLAKE2b-256 checksum
How to use checksums
6a6044123c16859c95f6b443b4fab466947116ab9ec019485b0b2a452b9911e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page