예제 #1
0
def regenerateReadings(nids):
    global mecab
    mw.checkpoint("Bulk-add Readings")
    mw.progress.start()
    for nid in nids:
        note = mw.col.getNote(nid)
        # Amend notetypes.py to add your note types
        _noteName = note.model()['name'].lower()
        if not isActiveNoteType(_noteName):
            continue

        src = None
        for field in srcFields:
            if field in note:
                src = field
                break
        if not src:
            # no src field
            continue
        # dst is the destination field for the Readings
        dst = None
        for field in dstFields:
            if field in note:
                dst = field
                break
        if not dst:
            # no dst field
            continue
        if note[dst]:
            # already contains data, skip
            continue
        srcTxt = mw.col.media.strip(note[src])
        if not srcTxt.strip():
            continue
        try:
            note[dst] = mecab.reading(srcTxt)
        except Exception, e:
            mecab = None
            raise
        note.flush()
예제 #2
0
def regenerateReadings(nids):
    global mecab
    mw.checkpoint("Bulk-add Readings")
    mw.progress.start()
    for nid in nids:
        note = mw.col.getNote(nid)
        # Amend notetypes.py to add your note types
        _noteName = note.model()['name'].lower()
        if not isActiveNoteType(_noteName):
            continue

        src = None
        for field in srcFields:
            if field in note:
                src = field
                break
        if not src:
            # no src field
            continue
        # dst is the destination field for the Readings
        dst = None
        for field in dstFields:
            if field in note:
                dst = field
                break
        if not dst:
            # no dst field
            continue
        if note[dst]:
            # already contains data, skip
            continue
        srcTxt = mw.col.media.strip(note[src])
        if not srcTxt.strip():
            continue
        try:
            note[dst] = mecab.reading(srcTxt)
        except Exception, e:
            mecab = None
            raise
        note.flush()
예제 #3
0
    def genKanjiSets(self):
        self.kanjiSets = [set([]) for g in self.kanjiGrades]
        chars = set()
        for m in self.col.models.all():
            _noteName = m['name'].lower()
            if not isActiveNoteType(_noteName):
                continue

            idxs = []
            for c, name in enumerate(self.col.models.fieldNames(m)):
                for f in srcFields:
                    if name == f:
                        idxs.append(c)
            for row in self.col.db.execute("""
select flds from notes where id in (
select n.id from cards c, notes n
where c.nid = n.id and mid = ? and c.queue > 0
%s) """ % self.lim, m['id']):
                flds = splitFields(row[0])
                for idx in idxs:
                    chars.update(flds[idx])
        for c in chars:
            if isKanji(c):
                self.kanjiSets[self.kanjiGrade(c)].add(c)