A versioned python wrapper package for The CMU Pronouncing Dictionary data files.
Project description
CMUdict is a versioned python wrapper package for The CMU Pronouncing Dictionary data files, and takes a similar approach to data bundling as Certifi does with Mozilla’s Root Certificates.
Installation
cmudict is available on PyPI. Simply install it with pip:
$ pip install cmudict
You can also install it from source:
$ git clone https://github.com/prosegrinder/python-cmudict.git Cloning into 'python-cmudict'... ... $ cd python-cmudict $ git submodule update --init --recursive Submodule 'cmudict/data' (https://github.com/cmusphinx/cmudict.git) registered for path 'cmudict/data'... ... $ python setup.py install ...
Usage
To find the location of installed cmudict data files, you can use the built-in functions:
>>> import cmudict >>> cmudict.where() '/usr/local/lib/python2.7/site-packages/cmudict/data/cmudict.dict' >>> cmudict.where_license() '/usr/local/lib/python2.7/site-packages/cmudict/data/LICENSE' >>> cmudict.where_phones() '/usr/local/lib/python2.7/site-packages/cmudict/data/cmudict.phones' >>> cmudict.where_symbols() '/usr/local/lib/python2.7/site-packages/cmudict/data/cmudict.symbols' >>> cmudict.where_vp() '/usr/local/lib/python2.7/site-packages/cmudict/data/cmudict.vp'
Data in the files can also be accessed directly as streams (pkg_resources.resource_stream). Note the stream is returned in binary mode, hence the addition of `.decode('utf-8')`:
>>> import cmudict >>> s = cmudict.stream() >>> for line in s: >>> print(line.decode('utf-8')) ... >>> s = cmudict.stream_license() >>> for line in s: >>> print(line.decode('utf-8')) ... >>> s = cmudict.stream_phones() >>> for line in s: >>> print(line.decode('utf-8')) ... >>> s = cmudict.stream_symbols() >>> for line in s: >>> print(line.decode('utf-8')) ... >>> s = cmudict.stream_vp() >>> for line in s: >>> print(line.decode('utf-8')) ...
And finally, cmudict has a set of functions compatible with nltk.corpus.reader.cmudict:
>>> import cmudict >>> d = cmudict.dict() ... >>> e = cmudict.entries() ... >>> r = cmudict.raw() ... >>> w = cmudict.words() ...
Credits
Built on or modeled after the following open source projects:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cmudict-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f29927315e7c20ebd624cb5eb1dd325e4059f9be25b7191adb70cc3c5171a202 |
|
MD5 | f38cfcf7f8e4461be14769172ffc0464 |
|
BLAKE2b-256 | b00b3be4c14d8d6c4c2fdcd5aa2fbce3aee90e3d60259be115c7988f1cfa8631 |