Created
May 20, 2013 21:54
-
-
Save ispedals/5615886 to your computer and use it in GitHub Desktop.
Anki addon for finding duplicates, with special criteria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aqt import mw | |
| from aqt.utils import showInfo | |
| from aqt.qt import * | |
| import re | |
| def strictDuplicate(): | |
| all_words=dict() | |
| for id in mw.col.findNotes("deck:Japanese::Vocabulary"): | |
| note=mw.col.getNote(id) | |
| word=note.fields[0] | |
| tags=note.tags | |
| if note.model()['name'] == 'Kore Words': | |
| tags.append(note['Tags']) | |
| tags=', '.join(tags) | |
| if word in all_words: | |
| all_words[word].append(tags) | |
| else: | |
| all_words[word]=[tags] | |
| all_words={word: all_words[word] for word in all_words if len(all_words[word]) > 1 and len(filter(lambda x: x.find('core')==-1, all_words[word])) > 0} | |
| out='' | |
| for word, tags in all_words.iteritems(): | |
| out+="%s\n\t%s\n" % (word,' '.join(tags)) | |
| showInfo(out) | |
| def readingDuplicate(): | |
| all_words=dict() | |
| KANA_RANGE=u'([\u30a0-\u30ff]|[\u3040-\u309f])' | |
| for id in mw.col.findNotes("deck:Japanese::Vocabulary"): | |
| note=mw.col.getNote(id) | |
| tags=note.tags | |
| if note.model()['name'] == 'Kore Words': | |
| tags.append(note['Tags']) | |
| word=note['VocabReading'] | |
| else: | |
| word=''.join(re.findall(KANA_RANGE, note['Reading'])) | |
| tags.append('|'+note['Expression']) | |
| tags=', '.join(tags) | |
| if word in all_words: | |
| all_words[word].append(tags) | |
| else: | |
| all_words[word]=[tags] | |
| all_words={word: all_words[word] for word in all_words if len(all_words[word]) > 1 and len(filter(lambda x: x.find('core')==-1, all_words[word])) > 0} | |
| out='' | |
| for word, tags in all_words.iteritems(): | |
| out+="%s\n\t%s\n" % (word,' '.join(tags)) | |
| showInfo(out) | |
| # create a new menu item, "strictDuplicate" | |
| action = QAction("Strict Duplicate", mw) | |
| # set it to call testFunction when it's clicked | |
| mw.connect(action, SIGNAL("triggered()"), strictDuplicate) | |
| # and add it to the tools menu | |
| mw.form.menuTools.addAction(action) | |
| action = QAction("Reading Duplicate", mw) | |
| # set it to call testFunction when it's clicked | |
| mw.connect(action, SIGNAL("triggered()"), readingDuplicate) | |
| # and add it to the tools menu | |
| mw.form.menuTools.addAction(action) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment