Coverage Report - orca.pronunciation_dict

ModuleCoverage %
orca.pronunciation_dict
43%
1
# Orca
2
#
3
# Copyright 2006 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 Library General Public
7
# License as published by the Free Software Foundation; either
8
# version 2 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
# Library General Public License for more details.
14
#
15
# You should have received a copy of the GNU Library General Public
16
# License along with this library; if not, write to the
17
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
# Boston, MA 02111-1307, USA.
19
20
"""Exposes a dictionary, pronunciation_dict, that maps words to what
21 1
they sound like."""
22
23 1
__id__        = "$Id: pronunciation_dict.py 2665 2007-08-17 15:08:50Z richb $"
24 1
__version__   = "$Revision: 2665 $"
25 1
__date__      = "$Date: 2007-08-17 11:08:50 -0400 (Fri, 17 Aug 2007) $"
26 1
__copyright__ = "Copyright (c) 2006 Sun Microsystems Inc."
27 1
__license__   = "LGPL"
28
29 1
from orca_i18n import _ # for gettext support
30
31 1
def getPronunciation(word, pronunciations=None):
32
    """Given a word, return a string that represents what this word
33
    sounds like.
34
35
    Arguments:
36
    - word: the word to get the "sounds like" representation for.
37
    - pronunciations: an optional dictionary used to get the pronunciation
38
      from.
39
40
    Returns a string that represents what this word sounds like, or 
41
    the word if there is no representation.
42
    """
43
44 0
    if isinstance(word, unicode):
45 0
        word = word.encode("UTF-8")
46
47 0
    try:
48 0
        lowerWord = word.decode("UTF-8").lower().encode("UTF-8")
49 0
        if pronunciations != None:
50 0
            return pronunciations[lowerWord][1]
51
        else:
52 0
            return pronunciation_dict[lowerWord][1]
53 0
    except:
54 0
        return word
55
56 1
def setPronunciation(word, replacementString, pronunciations=None):
57
    """Given an actual word, and a replacement string, set a key/value
58
    pair in a pronunciation dictionary.
59
60
    Arguments:
61
    - word: the word to be pronunced.
62
    - replacementString: the replacement string to use instead.
63
    - pronunciations: an optional dictionary used to set the pronunciation
64
      into.
65
    """
66
67 0
    key = word.decode("UTF-8").lower().encode("UTF-8")
68 0
    if pronunciations != None:
69 0
        pronunciations[key] = [ word, replacementString ]
70
    else:
71 0
        pronunciation_dict[key] = [ word, replacementString ]
72
73
# pronunciation_dict is a dictionary where the keys are words and the
74
# values represent word the pronunciation of that word (in other words,
75
# what the word sounds like).
76
#
77 1
pronunciation_dict = {}