Create pronunciations of words with the possibility of ignoring punctuation and splitting on hyphens before lookup.
Project description
word-to-pronunciation
Python library to help with looking up words that contain punctuation and hyphens.
Installation
pip install word-to-pronunciation
Usage
>>> from collections import OrderedDict
>>> from pronunciation_dictionary import Pronunciations, Word
>>> from word_to_pronunciation import Options, get_cached_lookup, get_pronunciations_from_word
>>> def lookup(word: Word) -> Pronunciations:
... print(f"Trying to lookup: '{word}' ...")
... if word == "test":
... result = OrderedDict((
... (("T", "E0", "S", "T"), 0.7),
... (("T", "E1", "S", "T"), 0.3),
... ))
... print("Found pronunciations!")
... return result
... print("Found no pronunciations!")
... return OrderedDict()
>>> options = Options(
... trim_symbols="\".",
... split_on_hyphen=True,
... try_without_trimming=True,
... try_without_splitting=True,
... default_weight=1.0
... )
>>> cache = {}
>>> lookup_method = get_cached_lookup(lookup, cache)
>>> word = "\"test-test\"."
>>> result = get_pronunciations_from_word(word, lookup_method, options)
Trying to lookup: '"test-test".' ...
Found no pronunciations!
Trying to lookup: 'test-test' ...
Found no pronunciations!
Trying to lookup: 'test' ...
Found pronunciations!
>>> for pronunciation, weight in result.items():
... print(f"{word} => /{'|'.join(pronunciation)}/ {weight}")
"test-test". => /"|T|E0|S|T|-|T|E0|S|T|"|./ 0.48999999999999994
"test-test". => /"|T|E0|S|T|-|T|E1|S|T|"|./ 0.21
"test-test". => /"|T|E1|S|T|-|T|E0|S|T|"|./ 0.21
"test-test". => /"|T|E1|S|T|-|T|E1|S|T|"|./ 0.09
>>> print(cache)
{'"test-test".': OrderedDict(), 'test-test': OrderedDict(), 'test': OrderedDict([(('T', 'E0', 'S', 'T'), 0.7), (('T', 'E1', 'S', 'T'), 0.3)])}
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
File details
Details for the file word-to-pronunciation-0.0.1.tar.gz
.
File metadata
- Download URL: word-to-pronunciation-0.0.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd7dd0cea5dbec13e730f1c1a8a879e62b455197a1197d7e708a5c683d605198 |
|
MD5 | a15d125e2e9103d537973c9ac08290c5 |
|
BLAKE2b-256 | 32360b5386a7c94717c7acdbfe531cf68b71d4dc99c164a4fce93b4d52e49a16 |
File details
Details for the file word_to_pronunciation-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: word_to_pronunciation-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c38ac6553a908c00b98dddd283174218d5618b6964466e80cb7e113e148722ce |
|
MD5 | a517f893dec5d38c36146e623a50af05 |
|
BLAKE2b-256 | b38f5222f2ca7a642396f9609d4edd5adeae046b3a29c651a73dfa9bf2f2efb5 |