Elffuss BraidHub

kikocis/company-english-helper public

master · 1.4 KiBRawPermalink
1from pystardict import Dictionary
2import os
3import sys
4import codecs
5
6if __name__ == "__main__":
7 if len(sys.argv) <= 1:
8 print("Usage: ./stardict.py start_dict_ifo_file_path")
9 else:
10 start_dictionary = Dictionary(sys.argv[1].split(".ifo")[0])
11
12 f = codecs.open("company-english-helper-data.el","w","utf-8")
13 f.write(";; -*- mode: fundamental; -*-\n")
14 f.write(";;\n")
15 f.write(";; This file is generate by stardict.py, please don't edit this file.\n")
16 f.write(";;\n\n")
17 f.write("(defconst english-helper-completions\n '(\n")
18
19 index = 0
20 for word in start_dictionary.keys():
21 is_english_word = all(ord(char) < 128 for char in word)
22 if is_english_word:
23 first_line_translation = start_dictionary.dict[word].split()[0]
24 no_phonetic_translation = first_line_translation.split(">")[-1]
25
26 candiate_word = word.lower().replace('\"', ' ')
27 candiate_translateion = no_phonetic_translation.strip().replace('\"', ' ')
28 f.write(' #(\"' + candiate_word + '\" ' + '0 1' + '\n' +
29 ' (:initials \"' + candiate_translateion + '\"))\n')
30
31 print(index, candiate_word, candiate_translateion)
32 index += 1
33
34 f.write(" ))\n\n")
35 f.write("(provide 'company-english-helper-data)\n")