Skip to content

Instantly share code, notes, and snippets.

@ispedals
Created May 20, 2013 21:43
Show Gist options
  • Select an option

  • Save ispedals/5615822 to your computer and use it in GitHub Desktop.

Select an option

Save ispedals/5615822 to your computer and use it in GitHub Desktop.
Find words with the same kanji and reading
# -*- coding: utf-8 -*-
import sqlite3
import re
#or another Rikaichan formatted dictionary file
d='.anki\\plugins\\yomichan_plugin\\languages\\japanese\\data\\dict.sqlite'
f=sqlite3.connect(d).cursor()
lookups=[(u'とく', u'徳')]
def findWordsWithSameKanjiandReading(kana, kanji):
f.execute(u'select * from dict where kana like "%%%s%%" and kanji like "%%%s%%" and entry like "%%(P)%%" limit 25'%(kana, kanji))
for kanji, kana, entry in f:
#if entry.find('(P)') == -1: continue
meanings = entry.split('/')
if not meanings[-1]:
items = map(unicode.strip, re.split('[\[\]]', meanings[0]))
if len(items) > 1:
kanji, kana, = items[0], items[1]
else:
kanji, kana = None, items[0]
del meanings[0], meanings[-1]
entry = u'; '.join(meanings)
expression = kanji or kana
reading = kana if kanji else None
print expression, reading, entry
for pair in lookups:
print '*' * 50
print '%s (%s)' % tuple(reversed(list(pair)))
findWordsWithSameKanjiandReading(pair[0],pair[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment