Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions autocorrect/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
https://github.com/foobarmus/autocorrect

"""
import re, os, tarfile
import re, os, zipfile
from contextlib import closing

PATH = os.path.abspath(os.path.dirname(__file__))
BZ2 = 'words.bz2'
ZIP = 'words.zip'
RE = '[A-Za-z]+'

def words_from_archive(filename, include_dups=False, map_case=False):
"""extract words from a text file in the archive"""
bz2 = os.path.join(PATH, BZ2)
tar_path = '{}/{}'.format('words', filename)
with closing(tarfile.open(bz2, 'r:bz2')) as t:
with closing(t.extractfile(tar_path)) as f:
zip = os.path.join(PATH, ZIP)
with closing(zipfile.ZipFile(zip)) as t:
with closing(t.open(filename)) as f:
words = re.findall(RE, f.read().decode(encoding='utf-8'))
if include_dups:
return words
Expand Down
Binary file removed autocorrect/words.bz2
Binary file not shown.
Binary file added autocorrect/words.zip
Binary file not shown.