Пример #1
0
def load_dictionary(filename):

    for encoding in ('utf-8', 'latin-1'):
        try:
            with resource_stream(filename, encoding=encoding) as fp:
                d = json.load(fp)
                break
        except UnicodeDecodeError:
            continue
    else:
        raise ValueError('\'%s\' encoding could not be determined' % (filename,))

    return StenoDictionary((normalize_steno(x[0]), x[1])
                           for x in iteritems(dict(d)))
Пример #2
0
def load_dictionary(filename):
    """Load an RTF/CRE dictionary."""
    with resource_stream(filename) as fp:
        s = fp.read().decode('cp1252')
    styles = load_stylesheet(s)
    d = {}
    converter = TranslationConverter(styles)
    for m in DICT_ENTRY_PATTERN.finditer(s):
        steno = normalize_steno(m.group('steno'))
        translation = m.group('translation')
        converted = converter(translation)
        if converted is not None:
            d[steno] = converted
    return StenoDictionary(d)
Пример #3
0
def load_dictionary(filename):
    """Load an RTF/CRE dictionary."""
    with resource_stream(filename) as fp:
        s = fp.read().decode('cp1252')
    styles = load_stylesheet(s)
    d = {}
    converter = TranslationConverter(styles)
    for m in DICT_ENTRY_PATTERN.finditer(s):
        steno = normalize_steno(m.group('steno'))
        translation = m.group('translation')
        converted = converter(translation)
        if converted is not None:
            d[steno] = converted
    return StenoDictionary(d)
Пример #4
0
def load_dictionary(filename):

    for encoding in ('utf-8', 'latin-1'):
        try:
            with resource_stream(filename, encoding=encoding) as fp:
                d = json.load(fp)
                break
        except UnicodeDecodeError:
            continue
    else:
        raise ValueError('\'%s\' encoding could not be determined' %
                         (filename, ))

    return StenoDictionary(
        (normalize_steno(x[0]), x[1]) for x in iteritems(dict(d)))