Пример #1
0
    def test_make_mixed_list(self):
        """make a list of spoken forms if the numbers are there
        """
        n = self.numbers
        L = [1, 2, 4, 5, 6]
        got = n.getMixedList(L)
        expected = ['on\xe9', 'two', 'too', 'four', 'for', 'five', 'six']
        self.assert_equal(expected, n.getMixedList(L),
                          "numbers: spoken forms list not as expected")

        # non existing language:
        print '\nexpect messages from spokenforms.ini, as language is unknown'
        m = spokenforms.SpokenForms('othertest', DNSVersion=DNSVersion)

        got = n.getMixedList(L)
        expected = ['1', '2', '4', '5', '6']
        self.assert_equal(expected, n.getMixedList(L),
                          "numbers: spoken forms list not as expected")

        # back to previous:
        n = spokenforms.SpokenForms('test', DNSVersion=DNSVersion)
        got = n.getMixedList(L)
        expected = ['on\xe9', 'two', 'too', 'four', 'for', 'five', 'six']

        self.assert_equal(expected, n.getMixedList(L),
                          "numbers: spoken forms list not as expected")
        print '----end of these expected messages'
Пример #2
0
    def test_switching_language(self):
        n = self.numbers
        self.assert_equal(expected_s2n, n.s2n,
                          "numbers, spoken2numbers is not as expected")

        self.assert_equal(expected_n2s, n.n2s,
                          "numbers, numbers2spoken is not as expected")

        # next instance non existing language:
        print '\nexpect messages from spokenforms, as it is switched to a non existing language'
        m = spokenforms.SpokenForms('othertest', DNSVersion=DNSVersion)
        expected_othertest = {}
        self.assert_equal(
            expected_othertest, m.s2n,
            "numbers, other language (no entries) spoken2numbers is not as expected"
        )

        self.assert_equal(
            expected_othertest, m.n2s,
            "numbers, other language (no entries) numbers2spoken is not as expected"
        )

        # back to language 'test'
        n = spokenforms.SpokenForms('test', DNSVersion=DNSVersion)
        self.assert_equal(expected_s2n, n.s2n,
                          "numbers again, spoken2numbers is not as expected")

        self.assert_equal(expected_n2s, n.n2s,
                          "numbers again, numbers2spoken is not as expected")
        print '-----end of these expected messages\n'
Пример #3
0
 def gotResults_checkalphabet(self, words, fullResults):
     """check the exact spoken versions of the alphabet in spokenforms
     """
     import spokenforms
     version = natqh.getDNSVersion()
     spok = spokenforms.SpokenForms(self.language, version)
     alph = 'alphabet'
     ini = spokenforms.ini
     for letter in string.ascii_lowercase:
         spoken = ini.get(alph, letter, '')
         if not spoken:
             print 'fill in in "%s_spokenform.ini", [alphabet] spoken for: "%s"' % (
                 self.language, letter)
             continue
         if version < 11:
             normalform = '%s\\%s' % (letter.upper(), spoken)
         else:
             normalform = '%s\\letter\\%s' % (letter.upper(), spoken)
         try:
             natlink.recognitionMimic([normalform])
         except natlink.MimicFailed:
             print 'invalid spoken form "%s" for "%s"' % (spoken, letter)
             if spoken == spoken.lower():
                 spoken = spoken.capitalize()
                 trying = 'try capitalized variant'
             elif spoken == spoken.capitalize():
                 spoken = spoken.lower()
                 trying = 'try lowercase variant'
             else:
                 continue
             if version < 11:
                 normalform = '%s\\%s' % (letter.upper(), spoken)
             else:
                 normalform = '%s\\letter\\%s' % (letter.upper(), spoken)
             try:
                 natlink.recognitionMimic([normalform])
             except natlink.MimicFailed:
                 print '%s fails also: "%s" for "%s"' % (trying, spoken,
                                                         letter)
             else:
                 print 'alphabet section is corrected with: "%s = %s"' % (
                     letter, spoken)
                 ini.set(alph, letter, spoken)
     ini.writeIfChanged()
Пример #4
0
    def test_basic_dicts(self):
        n = self.numbers

        self.assert_equal(expected_s2n, n.s2n, "numbers, spoken2numbers is not as expected")
        
        self.assert_equal(expected_n2s, n.n2s, "numbers, numbers2spoken is not as expected")

        # alphabet:
        self.assert_equal(expected_char2spoken, n.char2spoken, "alphabet, first instance char2spoken is not as expected")
        self.assert_equal(expected_spoken2char, n.spoken2char, "alphabet, first instance spoken2char is not as expected")

        # abbrevs:
        self.assert_equal(expected_abbrev2spoken, n.abbrev2spoken, "abbrevs, first instance abbrev2spoken is not as expected")
        self.assert_equal(expected_spoken2abbrev, n.spoken2abbrev, "abbrevs, first instance spoken2abbrev is not as expected")

        # extensions:
        self.assert_equal(expected_ext2spoken, n.ext2spoken, "abbrevs, first instance ext2spoken is not as expected")
        self.assert_equal(expected_spoken2ext, n.spoken2ext, "abbrevs, first instance spoken2ext is not as expected")
        
        # punctuation:
        self.assert_equal(expected_punct2spoken, n.punct2spoken, "abbrevs, first instance punct2spoken is not as expected")
        self.assert_equal(expected_spoken2punct, n.spoken2punct, "abbrevs, first instance spoken2punct is not as expected")
        
        # next instance:
        m = spokenforms.SpokenForms('test', DNSVersion=DNSVersion)
        self.assert_equal(expected_s2n, m.s2n, "numbers, second instance spoken2numbers is not as expected")
        
        
        self.assert_equal(expected_n2s, m.n2s, "numbers, second instance numbers2spoken is not as expected")

        self.assert_equal(expected_char2spoken, m.char2spoken, "alphabet, second instance char2spoken is not as expected")
        self.assert_equal(expected_spoken2char, m.spoken2char, "alphabet, second instance spoken2char is not as expected")

        # abbrevs second:
        self.assert_equal(expected_abbrev2spoken, m.abbrev2spoken, "abbrevs, second instance abbrev2spoken is not as expected")
        self.assert_equal(expected_spoken2abbrev, m.spoken2abbrev, "abbrevs, second instance spoken2abbrev is not as expected")
Пример #5
0
 def setUp(self):
     spokenforms.resetSpokenformsGlobals()
     self.numbers = spokenforms.SpokenForms('test', DNSVersion=DNSVersion)