def sens(sens, kanjs, rdngs, nsens): KW = jdb.KW dial = ['dial=' + KW.DIAL[x.kw].kw for x in getattr(sens, '_dial', [])] misc = [KW.MISC[x.kw].kw for x in getattr(sens, '_misc', [])] pos = [KW.POS[x.kw].kw for x in getattr(sens, '_pos', [])] fld = ['fld=' + KW.FLD[x.kw].kw for x in getattr(sens, '_fld', [])] stagk = fmt.restrtxts(getattr(sens, '_stagk', []), kanjs, '_stagk') stagr = fmt.restrtxts(getattr(sens, '_stagr', []), rdngs, '_stagr') _lsrc = [lsrc(x) for x in getattr(sens, '_lsrc', [])] _xref = [ '[' + xref(x) + ']' for x in getattr(sens, '_xref', []) if getattr(x, 'SEQ', None) is not False and getattr(x, '_xsens', None) != [] ] _xrslv = ['[' + xrslv(x) + ']' for x in getattr(sens, '_xrslv', [])] kwds = iif(pos, '[' + ','.join(pos) + ']', '') kwds += iif(misc, '[' + ','.join(misc) + ']', '') kwds += iif(fld, '[' + ','.join(fld) + ']', '') dial = iif(dial, '[' + ','.join(dial) + ']', '') restr = stagk + stagr # Join restrs with "," if they are alone, but with # ";" if in a list prefixed with "restr=". restr = iif(restr, '[restr=' + '; '.join(qtxt(x) for x in restr) + ']', '') _lsrc = iif(_lsrc, '[' + ','.join(_lsrc) + ']', '') note = '' if getattr(sens, 'notes', None): note = '[note=' + qtxt(sens.notes) + ']' lastginf = -1 gloss = [] gtxt = [] for n, g in enumerate(getattr(sens, '_gloss', [])): kws = [] if g.ginf != KW.GINF['equ'].id: kws.append(KW.GINF[g.ginf].kw) if g.lang != KW.LANG['eng'].id: if g.lang == KW.LANG['lit'].id: # Lithuanian language tag needs an explicit "lang=" # tag to disabiguate from a ginf lit ("literal") tag. kws.append("lang=" + KW.LANG[g.lang].kw) else: kws.append(KW.LANG[g.lang].kw) nl = '' if n == 0 else '\n ' kwstr = ('%s[%s] ' % (nl, ','.join(kws))) if kws else '' gtxt.append('%s%s' % (kwstr, escgloss(g.txt))) gloss = ['; '.join(gtxt)] lines = [] lines.append("[%d]%s%s" % (nsens, kwds, dial)) if restr: lines.append(restr) if _lsrc: lines.append(_lsrc) if note: lines.append(note) lines.extend(gloss) lines.extend(_xref) lines.extend(_xrslv) txt = '\n '.join(lines) return txt
def add_stag_summary(entries): # This adds a STAG attribute to each sense that has any # stagr or stagk restrictions. .STAG is set to a single # list that contains the kana or kanji texts strings that # are allowed for the sense under the restrictions. for e in entries: for s in getattr(e, '_sens', []): rt = [] if getattr(s, '_stagr', None): rt.extend(fmt.restrtxts(s._stagr, e._rdng, '_stagr')) if getattr(s, '_stagk', None): rt.extend(fmt.restrtxts(s._stagk, e._kanj, '_stagk')) if rt: s._STAG = rt
def rdng(rdng, kanjs): KW = jdb.KW txt = rdng.txt restrtxt = fmt.restrtxts(getattr(rdng, '_restr', []), kanjs, '_restr', qtxt) # Join restrs with "," if they are alone, but with # ";" if in a list prefixed with "restr=". if restrtxt: txt += '[' + ','.join(restrtxt) + ']' inf = [KW.RINF[x.kw].kw for x in getattr(rdng, '_inf', [])] inf.sort() freq = jdb.freq2txts(getattr(rdng, '_freq', [])) if inf or freq: txt += '[' + ','.join(inf + freq) + ']' return txt
def add_restr_summary(entries): # This adds an _RESTR attribute to each reading of each entry # that has a restr list. The ._RESTR attribute value is a list # of text strings giving the kanji that *are* allowed with the # reading. Recall that the database (and entry object created # therefrom) stores the *disallowed* reading/kanji combinations # but one generally wants to display the *allowed* combinations. # # Also add a HAS_RESTR boolean flag to the entry if there are # _restr items on any reading. for e in entries: if not hasattr(e, '_rdng') or not hasattr(e, '_kanj'): continue for r in e._rdng: if not hasattr(r, '_restr'): continue rt = fmt.restrtxts(r._restr, e._kanj, '_restr') if rt: r._RESTR = rt e.HAS_RESTR = 1