Skip to main content

A fast and efficient library for fixing contractions in text

Project description

Contraction Fix

PyPI version

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:

  1. Standard Contractions: Common English contractions like "can't", "won't", etc.
  2. Informal Contractions: Less formal contractions and patterns like "goin'", "doin'", etc.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contraction_fix-0.1.9.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contraction_fix-0.1.9-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file contraction_fix-0.1.9.tar.gz.

File metadata

  • Download URL: contraction_fix-0.1.9.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for contraction_fix-0.1.9.tar.gz
Algorithm Hash digest
SHA256 b597fa1a0b1d5918b6f5742f482c5d1af4777e18940ece12f491e187495e3703
MD5 9d960f8f3c3f9cd95b77ba897a906626
BLAKE2b-256 cc5edb3c13ee0bbc652f79419ff4d88596d401d6f55ba1a250adc4f3726ffdb5

See more details on using hashes here.

File details

Details for the file contraction_fix-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for contraction_fix-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b6826250e910fceec7998de312cfbe9ca37bc5ccffdfaaac988ec69adcb41441
MD5 0d5d45e0f50ba9250735a69779716e0f
BLAKE2b-256 222c544d16d71a2e387fbb997d79291ebcbdcc2d42feb3641bf2d6666c7bcf20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page