3
# Copyright 2006-2008 Sun Microsystems Inc.
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Lesser General Public
7
# License as published by the Free Software Foundation; either
8
# version 2.1 of the License, or (at your option) any later version.
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public
16
# License along with this library; if not, write to the
17
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
18
# Boston MA 02110-1301 USA.
20
"""Exposes a dictionary, pronunciation_dict, that maps words to what
24
__version__ = "$Revision$"
26
__copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."
29
def getPronunciation(word, pronunciations=None):
30
"""Given a word, return a string that represents what this word
34
- word: the word to get the "sounds like" representation for.
35
- pronunciations: an optional dictionary used to get the pronunciation
38
Returns a string that represents what this word sounds like, or
39
the word if there is no representation.
42
if isinstance(word, unicode):
43
word = word.encode("UTF-8")
46
lowerWord = word.decode("UTF-8").lower().encode("UTF-8")
47
if pronunciations != None:
48
return pronunciations[lowerWord][1]
50
return pronunciation_dict[lowerWord][1]
52
# If you want a character name to be spoken, treat it as a
53
# punctuation character at LEVEL_NONE in puncutation_settings.py.
54
# See, for example, the left_arrow and right_arrow characters.
56
#return chnames.getCharacterName(word)
59
def setPronunciation(word, replacementString, pronunciations=None):
60
"""Given an actual word, and a replacement string, set a key/value
61
pair in a pronunciation dictionary.
64
- word: the word to be pronunced.
65
- replacementString: the replacement string to use instead.
66
- pronunciations: an optional dictionary used to set the pronunciation
70
key = word.decode("UTF-8").lower().encode("UTF-8")
71
if pronunciations != None:
72
pronunciations[key] = [ word, replacementString ]
74
pronunciation_dict[key] = [ word, replacementString ]
76
# pronunciation_dict is a dictionary where the keys are words and the
77
# values represent word the pronunciation of that word (in other words,
78
# what the word sounds like).
80
pronunciation_dict = {}