1# Orca 2# 3# Copyright 2006-2008 Sun Microsystems Inc. 4# 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. 9# 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. 14# 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. 19 20"""Exposes a dictionary, pronunciation_dict, that maps words to what 21they sound like.""" 22 23__id__ = "$Id$" 24__version__ = "$Revision$" 25__date__ = "$Date$" 26__copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc." 27__license__ = "LGPL" 28 29def getPronunciation(word, pronunciations=None): 30 """Given a word, return a string that represents what this word 31 sounds like. Note: This code does not handle the pronunciation 32 of character names. If you want a character name to be spoken, 33 treat it as a punctuation character at LEVEL_NONE in 34 punctuation_settings.py. See, for example, the left_arrow and 35 right_arrow characters. 36 37 Arguments: 38 - word: the word to get the "sounds like" representation for. 39 - pronunciations: an optional dictionary used to get the pronunciation 40 from. 41 42 Returns a string that represents what this word sounds like, or 43 the word if there is no representation. 44 """ 45 46 lowerWord = word.lower() 47 dictionary = pronunciations or pronunciation_dict 48 entry = dictionary.get(lowerWord, [word, word]) 49 50 return entry[1] 51 52def setPronunciation(word, replacementString, pronunciations=None): 53 """Given an actual word, and a replacement string, set a key/value 54 pair in a pronunciation dictionary. 55 56 Arguments: 57 - word: the word to be pronunced. 58 - replacementString: the replacement string to use instead. 59 - pronunciations: an optional dictionary used to set the pronunciation 60 into. 61 """ 62 63 key = word.lower() 64 if pronunciations is not None: 65 pronunciations[key] = [ word, replacementString ] 66 else: 67 pronunciation_dict[key] = [ word, replacementString ] 68 69# pronunciation_dict is a dictionary where the keys are words and the 70# values represent word the pronunciation of that word (in other words, 71# what the word sounds like). 72# 73pronunciation_dict = {} 74