WordSub
Install
pip install word-sub
Build
python setup.py sdist
twine upload dist/*
Usage
from word_sub import WordMappings
# Init a WordMappings Class
# NLTK and gensim Stopwords are available by default
wm = WordMappings()
# Override this with
wm = WordMappings(stopwords=False)
# Token substitution is implemented via __call__
>>> wm('the dish ran away with the spoon'.split())
['dish', 'ran', 'away', 'spoon'] # Stopwords removed
# Add additional stopwords
>>> wm.add_pair(None, ['ran'])
>>> wm('the dish ran away with the spoon'.split())
['dish', 'away', 'spoon']
# Token substitution
>>> wm.add_pair('senior', ['sr', 'lead', 'head'])
>>> wm('lead manager'.split())
['senior', 'manager']
# Save and load via .save and .load