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

6.2k Views Asked by At
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?

2

There are 2 best solutions below

1
On BEST ANSWER

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', ...}
0
On

after you install contractions by pip install contractions, you can use contractions_dict instead of CONTRACTION_MAP