def sentGloss(res, t): """ Fall back to reading-based Japanese lookup if headword lookup fails. Chinese lookup multi-pronged by default. """ if t == SGJ: from cjklib.dictionary import EDICT d = EDICT() dtrans = d.getForHeadword(res) elif t == SGC or t == SGCW: from cjklib.dictionary import CEDICT d = CEDICT() if res in cedict.all: dtrans = d.getFor(res) else: return '' entries = [] entry = '' for e in dtrans: for f in e._fields: if getattr(e, f) != None: entry = unicode(getattr(e, f)) + u'\t' entries.append(entry) if len(entries) == 0: for e in d.getForReading(res): for f in e._fields: if getattr(e, f) != None: entry = unicode(getattr(e, f)) + u'\t' entries.append(entry) return u'\t'.join(entries)
def search(text): # Takes text and runs tokenize() and then runs headword() output = [] jdict = EDICT() tokens = tokenize(text) for t in tokens: defs = jdict.getFor(t[0]) for line in defs: line = ''.join(line) output.append(line) return output