Contractions

0.1.73 · active · verified Wed Apr 15

The `contractions` library is a Python package (v0.1.73) designed for natural language processing (NLP) to expand English contractions and common slang terms into their full forms. It handles contractions like `you're` to `you are` and slang like `yall` to `you all`, aiming to standardize text for further analysis. It processes text by replacing shortened words and can also be extended with custom contraction rules. The library's last release was in November 2022, and it maintains a relatively stable release cadence.

Warnings

Install

Imports

Quickstart

Expands common English contractions and slang in a given string. Demonstrates adding a custom contraction.

import contractions

text = "I'm happy now, and yall're doing great. We've gotta go!"
expanded_text = contractions.fix(text)
print(f"Original: {text}")
print(f"Expanded: {expanded_text}")

# You can also add custom contractions
contractions.add('mychange', 'my change')
custom_text = "This is mychange."
expanded_custom_text = contractions.fix(custom_text)
print(f"Custom: {expanded_custom_text}")

view raw JSON →