Subversion Repositories LCARS

Rev

Rev 294 | Rev 297 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 294 Rev 296
Line 56... Line 56...
56
56
57
class VulcanDictionary(Dictionary):
57
class VulcanDictionary (Dictionary):
58
    def translate (self, phrase, search_prefix=True, search_plural=True):
58
    def translate (self, phrase, search_prefix=True, search_plural=True):
59
        dictionary = self
59
        dictionary = self
60
60
61
        translation = dictionary.get(phrase.lower(), None)
61
        translation = super().translate(phrase)
62
        if translation is not None:
62
        if translation is not None:
63
            translation['vuh'] = phrase
-
 
64
            return translation
63
            return translation
65
        else:
64
        else:
-
 
65
            expr_translation = dictionary.translate_expression(phrase)
-
 
66
            if expr_translation is not None:
-
 
67
                return expr_translation
-
 
68
66
            if search_prefix:
69
            if search_prefix:
67
                # find prefix
70
                # find prefix
68
                for preposition in prepositions:
71
                for preposition in prepositions:
69
                    prefix = match(escape(preposition), phrase)
72
                    prefix = match(escape(preposition), phrase)
70
                    if prefix is not None:
73
                    if prefix is not None:
Line 91... Line 94...
91
    if len(argv) < 2:
94
    if len(argv) < 2:
92
        print('Nothing to translate.', end='\n\n', file=stderr)
95
        print('Nothing to translate.', end='\n\n', file=stderr)
93
        cli_help()
96
        cli_help()
94
        exit(1)
97
        exit(1)
95
98
96
    text = argv[1]
99
    text = ' '.join(argv[1:])
97
100
98
    dictionary = VulcanDictionary(dictionary)
101
    dictionary = VulcanDictionary(dictionary)
99
    dictionary.load('vuh-gol-en.dict.zdb.txt', 'vuh')
102
    dictionary.load('vuh-gol-en.dict.zdb.txt', 'vuh')
100
    dictionary.clean()
103
    dictionary.clean()
101
104
Line 144... Line 147...
144
                if translation is None:
147
                if translation is None:
145
                    dmsg("phrase-translation:", translation, min_level=2)
148
                    dmsg("phrase-translation:", translation, min_level=2)
146
                    offset += 1
149
                    offset += 1
147
150
148
            dmsg("words-translation:", words, min_level=2)
151
            dmsg("words-translation:", words, min_level=2)
-
 
152
            dmsg("words-translation-reduced:",
-
 
153
                list(map(
-
 
154
                    lambda word:
-
 
155
                        word['en']
-
 
156
                        if (hasattr(word, "get") and word.get('en', None) is not None)
-
 
157
                        else word,
-
 
158
                    words)),
-
 
159
                min_level=2)
-
 
160
            # dmsg(dictionary._expressions)