def main(): filename,limit, output_format, wordtype, version= grabargs() #print "#--",filename,limit,display_format, wordtype; #exit(); try: fl = open(filename); except: print " Error :No such file or directory: %s" % filename sys.exit(0) #~ print "#",filename,limit, output_format, wordtype, version #~ sys.exit() #display_format="txt" line = fl.readline().decode("utf8"); text = u"" noun_table = []; nb_field = 2; while line : line = line.strip('\n')#.strip() if not line.startswith("#"): liste = line.split(Separator); if len(liste) >= nb_field: noun_table.append(liste); line = fl.readline().decode("utf8"); fl.close(); #print "#", (u'\t'.join(field_id.keys())).encode('utf8'); model = 0; if output_format == "sql": import sqldict mydict = sqldict.SqlDict(wordtype, version); elif output_format == "xml": import xmldict mydict = xmldict.XmlDict(wordtype, version); elif output_format == "stardict": import stardict mydict = stardict.StarDict(wordtype, version); elif output_format == "tags": import tagsdict mydict = tagsdict.TagsDict(wordtype, version); elif output_format == "spell": import spelldict mydict = spelldict.SpellDict(wordtype, version); else: import csvdict mydict = csvdict.CsvDict(wordtype, version) # create header h = mydict.add_header() if h: print h.encode('utf8') for tuple_noun in noun_table[:limit]: l = mydict.add_record(tuple_noun) if l: print l.encode('utf8') # create footer f = mydict.add_footer() if f: print f.encode('utf8')
def __init__ (self, filepath, threshold=0): self.dbname = "stardict.db" self.filepath = filepath self.sd = stardict.StarDict(self.dbname) self.lemma = stardict.LemmaDB() self.lemma.load('lemma.en.txt') self.worddict = OrderedDict() self.threshold = threshold self.find_uncapword_sent=False self.myvocab = [line.split("\t")[0] for line in open("myvocab.txt", 'r').read().split('\n') if not line.startswith("#")]
def Python_QueryWord(word): vim.command('redraw!') sqlitename = os.path.join(os.path.dirname(__file__), 'stardict.db') sd = stardict.StarDict(sqlitename, False) result = sd.query(word) if result is None: print("Can't find, %s !!!" % word) return print(result['word']) if len(result['definition']) > 0: print(result['definition']) if len(result['translation']) > 0: print(result['translation'])
def main(): filename, limit, output_format, version = grabargs() try: fl = open(filename) except: print " Error :No such file or directory: %s" % filename sys.exit(0) verb_field_number = 2 verb_cat_field_number = 3 line = fl.readline().decode("utf") text = u"" verb_table = [] nb_field = 12 if output_format == "sql": import sqldict mydict = sqldict.SqlDict(version) elif output_format == "xml": import xmldict mydict = xmldict.XmlDict(version) elif output_format == "stardict": import stardict mydict = stardict.StarDict(version) elif output_format == "spell": import spelldict elif output_format == "tags": import tagsdict mydict = tagsdict.TagsDict(version) else: import csvdict mydict = csvdict.CsvDict(version) while line: line = line.strip('\n').strip() if not line.startswith("#"): liste = line.split("\t") if len(liste) >= nb_field: verb_table.append(liste) line = fl.readline().decode("utf8") fl.close() # create header print mydict.add_header().encode('utf8') for tuple_verb in verb_table[:limit]: #~ verb_dict = decode_tuple_verb(tuple_verb); print mydict.add_record(tuple_verb).encode('utf8') # create footer print mydict.add_footer().encode('utf8')
def main(): if len(sys.argv) < 2: print("Usage: dictquery.py {word}") return sqlitename = os.path.join(os.path.dirname(__file__), 'stardict.db') sd = stardict.StarDict(sqlitename, False) result = sd.query(sys.argv[1]) if result is None: print("Can't find!!!") return print(result['word']) if len(result['definition']) > 0: print(result['definition']) if len(result['translation']) > 0: print(result['translation'])
def factory(output_format, version): import csvdict mydict = csvdict.CsvDict(version) if output_format == "sql": import sqldict mydict = sqldict.SqlDict(version) elif output_format == "xml": import xmldict mydict = xmldict.XmlDict(version) elif output_format == "stardict": import stardict mydict = stardict.StarDict(version) elif output_format == "spell": import spelldict elif output_format == "tags": import tagsdict mydict = tagsdict.TagsDict(version) elif output_format == "check": import checkdict mydict = checkdict.checkDict(version) else: import csvdict mydict = csvdict.CsvDict(version) return mydict
def main(): args = grabargs() filename = args.filename limit = args.limit output_format = args.outformat wordtype = args.wordtype version = args.version #print "#--",filename,limit,display_format, wordtype; #exit(); try: fl = open(filename, encoding='utf-8') except: print(" Error :No such file or directory: %s" % filename) sys.exit(0) #~ print "#",filename,limit, output_format, wordtype, version #~ sys.exit() #display_format="txt" line = fl.readline() text = u"" noun_table = [] nb_field = 2 while line: line = line.strip('\n') #.strip() if not line.startswith("#"): liste = line.split(Separator) if len(liste) >= nb_field: noun_table.append(liste) line = fl.readline() fl.close() #print "#", (u'\t'.join(field_id.keys())).encode('utf8'); model = 0 if output_format == "sql": import sqldict mydict = sqldict.SqlDict(wordtype, version) elif output_format == "xml": import xmldict mydict = xmldict.XmlDict(wordtype, version) elif output_format == "stardict": import stardict mydict = stardict.StarDict(wordtype, version) elif output_format == "tags": import tagsdict mydict = tagsdict.TagsDict(wordtype, version) elif output_format == "spell": import spelldict mydict = spelldict.SpellDict(wordtype, version) elif output_format == "check": import checkdict mydict = checkdict.checkDict(version) else: import csvdict mydict = csvdict.CsvDict(wordtype, version) # create header h = "" # mydict.add_header() if h: print(h) for tuple_noun in noun_table[:limit]: l = mydict.add_record(tuple_noun) if l: print(l) # create footer f = mydict.add_footer() if f: print(f)
def dictionary(self): if self._dict is None: db = ccinit.path_home('share/dict/dictionary.db') self._dict = stardict.StarDict(db) return self._dict