Subversion Repositories LCARS

Rev

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

Rev 294 Rev 296
Line 22... Line 22...
22
}
22
}
23
23
24
def cli_help():
24
def cli_help():
25
    print('Usage: {0} TEXT...'.format(basename(argv[0])))
25
    print('Usage: {0} TEXT...'.format(basename(argv[0])))
26
26
27
def get_sort_dict_alnum_vulcan_key():
27
def get_sort_dict_alnum_vulcan_key ():
28
    letters = list(map(str.lower, [
28
    letters = list(map(str.lower, [
29
        " ", 'S', 'T', 'P', 'K', 'R', 'L', 'A', 'Sh', 'O', 'U', 'D',
29
        " ", 'S', 'T', 'P', 'K', 'R', 'L', 'A', 'Sh', 'O', 'U', 'D',
30
        'V', 'Kh', 'E', 'H', 'G', 'Ch', 'I', 'N', 'Zh', 'M', 'Y', 'F', 'Z',
30
        'V', 'Kh', 'E', 'H', 'G', 'Ch', 'I', 'N', 'Zh', 'M', 'Y', 'F', 'Z',
31
        'Th', 'W', 'B', "'", '-']))
31
        'Th', 'W', 'B', "'", '-']))
32
    letter_values = dict(map(lambda x: (x[1], x[0]), enumerate(letters)))
32
    letter_values = dict(map(lambda x: (x[1], x[0]), enumerate(letters)))
Line 52... Line 52...
52
52
53
        return 1 if len(b) < len(a) else 0
53
        return 1 if len(b) < len(a) else 0
54
54
55
    return cmp_to_key(sort_dict_alnum_vulcan)
55
    return cmp_to_key(sort_dict_alnum_vulcan)
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)