A fast and efficient library for fixing contractions in text
Project description
Contraction Fix
A fast and efficient library for fixing contractions in text. This package provides tools to expand contractions in English text while maintaining high performance and accuracy.
Features
- Fast text processing using precompiled regex patterns
- Support for standard contractions, informal contractions, and internet slang
- Configurable dictionary usage
- Caching for improved performance
- Preview functionality to see contractions before fixing
- Easy addition and removal of custom contractions
Installation
pip install contraction-fix
Usage
Basic Usage
from contraction_fix import fix
text = "I can't believe it's not butter!"
fixed_text = fix(text)
print(fixed_text) # "I cannot believe it is not butter!"
Contractions vs. Possessives
The package intelligently differentiates between contractions and possessive forms:
from contraction_fix import fix
text = "I can't find Sarah's keys, and she won't be at her brother's house until it's dark."
fixed_text = fix(text)
print(fixed_text) # "I cannot find Sarah's keys, and she will not be at her brother's house until it is dark."
Notice how the package:
- Expands contractions: "can't" → "cannot", "won't" → "will not", "it's" → "it is"
- Preserves possessives: "Sarah's" and "brother's" remain unchanged
Advanced Usage
from contraction_fix import ContractionFixer
# Create a custom fixer instance
fixer = ContractionFixer(use_informal=True, use_slang=False)
# Fix text
text = "I'd like to see y'all tomorrow"
fixed_text = fixer.fix(text)
print(fixed_text) # "I would like to see you all tomorrow"
# Preview contractions
matches = fixer.preview(text, context_size=5)
for match in matches:
print(f"Found '{match['match']}' at position {match['start']}")
print(f"Context: '{match['context']}'")
print(f"Will be replaced with: '{match['replacement']}'")
# Add custom contraction
fixer.add_contraction("gonna", "going to")
# Remove contraction
fixer.remove_contraction("won't")
Dictionary Types
The package uses three types of dictionaries:
- Standard Contractions: Common English contractions like "can't", "won't", etc.
- Informal Contractions: Less formal contractions and patterns like "goin'", "doin'", etc.
- Internet Slang: Modern internet slang and abbreviations like "lol", "btw", etc.
Performance
The package is optimized for speed through:
- Precompiled regex patterns
- LRU caching of results
- Efficient dictionary lookups
- Minimal memory usage
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 contraction_fix-0.1.7.tar.gz.
File metadata
- Download URL: contraction_fix-0.1.7.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df18332d6fa5370b97b6808b93ce2b7543ed48347a48f83f07873320046e4952
|
|
| MD5 |
e8f48bdc175f7b4f58f4a6221600eaf6
|
|
| BLAKE2b-256 |
93324ef99355257cab0e2b20266a15d507dd2942158f6060a6ede0bb9a75da8a
|
File details
Details for the file contraction_fix-0.1.7-py3-none-any.whl.
File metadata
- Download URL: contraction_fix-0.1.7-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c5144f072a6b7921758e258b039b27116d9bba8aed98b064db35fcff7fa56d
|
|
| MD5 |
00cea37b30d9c32dc6f23386843a6ebc
|
|
| BLAKE2b-256 |
6c334525a742ae2e87ccb6b785555fdba02cf83ccf2a1d304b0152783ef92e0b
|