Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'CONTRACTION_MAP' from 'contractions'

ImportError                               Traceback (most recent call last)
<ipython-input-13-74c9bc9e3e4a> in <module>
      8 from nltk.tokenize.toktok import ToktokTokenizer
      9 #import contractions
---> 10 from contractions import CONTRACTION_MAP
     11 import unicodedata
     12 

ImportError: cannot import name 'CONTRACTION_MAP' from 'contractions' (c:\users\nikita\appdata\local\programs\python\python37-32\lib\site-packages\contractions\__init__.py)

One question is: is the CONTRACTION_MAP variable deprecated from the contractions package?

like image 467
Nikita Bachani Avatar asked Nov 25 '25 05:11

Nikita Bachani


1 Answers

I believe you have mistaken the contractions package available on PyPI with the contractions module from a textbook called "Text Analytics with Python" (source code).

The CONTRACTIONS_MAP variable is defined in the latter and is not part of the contractions package API (documented in the GitHub Readme.md).

From the documentation, the package can be used to fix contractions like:

import contractions
contractions.fix("you're happy now")
# "you are happy now"

If you want access to the map of contraction to expanded version, this can be imported using:

from contractions import contractions_dict

This contractions_dict contains entries like:

{..., 'you’ll': 'you will', ...}
like image 148
dspencer Avatar answered Nov 27 '25 18:11

dspencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!