def main(): # load existing all.db mw.progress.start(label='Loading existing all.db', immediate=True) t_0 = time.time() cur = util.allDb() if cfg1('loadAllDb') else None printf('Loaded all.db in %f sec' % (time.time() - t_0)) mw.progress.finish() # update all.db allDb = mkAllDb(cur) # merge in external.db mw.progress.start(label='Merging ext.db', immediate=True) ext = MorphDb(cfg1('path_ext'), ignoreErrors=True) allDb.merge(ext) mw.progress.finish() # update notes knownDb = updateNotes(allDb) # update stats and refresh display stats.updateStats(knownDb) mw.toolbar.draw() # set global allDb util._allDb = allDb
def main(): # load existing all.db mw.progress.start( label='Loading existing all.db', immediate=True ) t_0 = time.time() cur = util.allDb() if cfg1('loadAllDb') else None printf( 'Loaded all.db in %f sec' % ( time.time() - t_0 ) ) mw.progress.finish() # update all.db allDb = mkAllDb( cur ) # merge in external.db mw.progress.start( label='Merging ext.db', immediate=True ) ext = MorphDb( cfg1('path_ext'), ignoreErrors=True ) allDb.merge( ext ) mw.progress.finish() # update notes knownDb = updateNotes( allDb ) # update stats and refresh display stats.updateStats( knownDb ) mw.toolbar.draw() # set global allDb util._allDb = allDb
def highlight(txt, extra, fieldDict, field, mod_field): '''When a field is marked with the 'focusMorph' command, we format it by wrapping all the morphemes in <span>s with attributes set to its maturity''' # must avoid formatting a smaller morph that is contained in a bigger morph # => do largest subs first and don't sub anything already in <span> def nonSpanSub(sub, repl, string): return u''.join( re.sub(sub, repl, s) if not s.startswith('<span') else s for s in re.split('(<span.*?</span>)', string)) from morphemes import getMorphemes ms = getMorphemes(txt) for m in sorted(ms, key=lambda x: len(x.inflected), reverse=True): # largest subs first locs = allDb().db.get(m, set()) mat = max(loc.maturity for loc in locs) if locs else 0 if mat >= cfg1('threshold_mature'): mtype = 'mature' elif mat >= cfg1('threshold_known'): mtype = 'known' elif mat >= cfg1('threshold_seen'): mtype = 'seen' else: mtype = 'unknown' repl = u'<span class="morphHighlight" mtype="{mtype}" mat="{mat}">{morph}</span>'.format( morph=m.inflected, mtype=mtype, mat=mat) txt = nonSpanSub(m.inflected, repl, txt) return txt
def highlight( txt, extra, fieldDict, field, mod_field ): '''When a field is marked with the 'focusMorph' command, we format it by wrapping all the morphemes in <span>s with attributes set to its maturity''' from util import getFilterByTagsAndType from morphemizer import getMorphemizerByName from morphemes import getMorphemes # must avoid formatting a smaller morph that is contained in a bigger morph # => do largest subs first and don't sub anything already in <span> def nonSpanSub( sub, repl, string ): return u''.join( re.sub( sub, repl, s ) if not s.startswith('<span') else s for s in re.split( '(<span.*?</span>)', string ) ) # find morphemizer; because no note/card information is exposed through arguments, we have to find morphemizer based on tags alone #from aqt.qt import debug; debug() # #if mw.reviewer.card is None: return txt #note = mw.reviewer.card.note() #if not isNoteSame(note, fieldDict): return txt #from aqt.qt import debug; debug() tags = fieldDict['Tags'].split() filter = getFilterByTagsAndType(fieldDict['Type'], tags) if filter is None: return txt morphemizer = getMorphemizerByName(filter['Morphemizer']) if morphemizer is None: return txt ms = getMorphemes(morphemizer, txt, tags) for m in sorted( ms, key=lambda x: len(x.inflected), reverse=True ): # largest subs first locs = allDb().db.get( m, set() ) mat = max( loc.maturity for loc in locs ) if locs else 0 if mat >= cfg1( 'threshold_mature' ): mtype = 'mature' elif mat >= cfg1( 'threshold_known' ): mtype = 'known' elif mat >= cfg1( 'threshold_seen' ): mtype = 'seen' else: mtype = 'unknown' repl = u'<span class="morphHighlight" mtype="{mtype}" mat="{mat}">{morph}</span>'.format( morph = m.inflected, mtype = mtype, mat = mat ) txt = nonSpanSub( m.inflected, repl, txt ) return txt
def highlight( txt, extra, fieldDict, field, mod_field ): '''When a field is marked with the 'focusMorph' command, we format it by wrapping all the morphemes in <span>s with attributes set to its maturity''' # must avoid formatting a smaller morph that is contained in a bigger morph # => do largest subs first and don't sub anything already in <span> def nonSpanSub( sub, repl, string ): return u''.join( re.sub( sub, repl, s ) if not s.startswith('<span') else s for s in re.split( '(<span.*?</span>)', string ) ) from morphemes import getMorphemes ms = getMorphemes( txt ) for m in sorted( ms, key=lambda x: len(x.inflected), reverse=True ): # largest subs first locs = allDb().db.get( m, set() ) mat = max( loc.maturity for loc in locs ) if locs else 0 if mat >= cfg1( 'threshold_mature' ): mtype = 'mature' elif mat >= cfg1( 'threshold_known' ): mtype = 'known' elif mat >= cfg1( 'threshold_seen' ): mtype = 'seen' else: mtype = 'unknown' repl = u'<span class="morphHighlight" mtype="{mtype}" mat="{mat}">{morph}</span>'.format( morph = m.inflected, mtype = mtype, mat = mat ) txt = nonSpanSub( m.inflected, repl, txt ) return txt