# Path: lingtools/util/datamanager.py
# def download(url, path=None):
# def unzip(filepath, destpath='.'):


import csv
    import doctest
from collections import defaultdict
from lingtools.util import datamanager
        self.context_counts = defaultdict(int)

        # Set up dict
        dict.__init__(self)

        # Fill it in
        try:
            subtlex = open(subtlex_path, 'rU')
        except IOError:
            raise IOError("Could not open SUBTLEX database at %s." % subtlex_path)

        # DictReader would be convenient, but given the size of the
        # file, efficiency is key. Using a standard reader appears to
        # be 30% faster. Fields: spelling, spelling1, freq, cd,
        # cdcount, separator, separatorfreq, separatorcd
        subtlex_reader = csv.reader(subtlex, delimiter='\t')
        # Skip header
        subtlex_reader.next()
        # Read the data
        for word1, word2, freq, cd, cdcount, _, _, _ in subtlex_reader:
            freq = int(freq)
            cd = float(cd)
            cdcount = int(cdcount)
            self[(word1, word2)] = \
                SubtlexUKBigram(word1, word2, freq, cd, cdcount)
            self.context_counts[word1] += freq


def download():
    """Download and unzip a current version of SUBTLEX to the working directory."""

# Path: lingtools/util/datamanager.py
# def download(url, path=None):
# def unzip(filepath, destpath='.'):


# Path: lingtools/corpus/subtlexreader.py
import csv
    import doctest
from collections import defaultdict
from lingtools.util import datamanager

        self.context_counts = defaultdict(int)

        # Set up dict
        dict.__init__(self)

        # Fill it in
        try:
            subtlex = open(subtlex_path, 'rU')
        except IOError:
            raise IOError("Could not open SUBTLEX database at %s." % subtlex_path)

        # DictReader would be convenient, but given the size of the
        # file, efficiency is key. Using a standard reader appears to
        # be 30% faster. Fields: spelling, spelling1, freq, cd,
        # cdcount, separator, separatorfreq, separatorcd
        subtlex_reader = csv.reader(subtlex, delimiter='\t')
        # Skip header
        subtlex_reader.next()
        # Read the data
        for word1, word2, freq, cd, cdcount, _, _, _ in subtlex_reader:
            freq = int(freq)
            cd = float(cd)
            cdcount = int(cdcount)
            self[(word1, word2)] = \
                SubtlexUKBigram(word1, word2, freq, cd, cdcount)
            self.context_counts[word1] += freq


def download():
    """Download and unzip a current version of SUBTLEX to the working directory."""

    path = datamanager.download(SUBTLEX_URL)