phatpiglet/autocorrect

Speller() cannot be created since the tarf.extractfile

dgl-prc opened this issue · 1 comments

I install the latest version, i.e., 2.3.0 on Unbuntu. When I run the code:
spell = Speller()
It reports the error as follows:

self.nlp_data = load_from_tar(lang) if nlp_data is None else nlp_data

File "/home/dgl/virtual_env/textR/lib/python3.5/site-packages/autocorrect/init.py", line 78, in load_from_tar
return json.load(file)
File "/usr/lib/python3.5/json/init.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.5/json/init.py", line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not 'bytes'

I managed to fix it by manually decompressing the file "en.tar.gz" and replace the following code:

    with closing(tarfile.open(archive_name, 'r:gz')) as tarf:
        with closing(tarf.extractfile(file_name)) as file:
            return json.load(file)

with:

   with open(os.path.join(PATH,"data/word_count.json"),"r") as f:
        return json.load(f)