1

Fixing bugs in database generation

This commit is contained in:
Alex Yatskov 2013-11-08 11:24:37 -08:00
parent ea90c4ceb0
commit 8fa4adf71a

View File

@ -86,12 +86,12 @@ def loadDefinitions(path):
def parseKanjiDic(path): def parseKanjiDic(path):
results = list() results = list()
for line in loadDefinitions('kanjidic'): for line in loadDefinitions(path):
segments = line.split() segments = line.split()
character = segments[0] character = segments[0]
kunYomi = ','.join(filter(lambda x: filter(isHiragana, x), segments[1:])), kunYomi = ', '.join(filter(lambda x: filter(isHiragana, x), segments[1:]))
onYomi = ','.join(filter(lambda x: filter(isKatakana, x), segments[1:])), onYomi = ', '.join(filter(lambda x: filter(isKatakana, x), segments[1:]))
meanings = ','.join(re.findall('\{([^\}]+)\}', line)) meanings = '; '.join(re.findall('\{([^\}]+)\}', line))
results.append((character, onYomi, kunYomi, meanings)) results.append((character, onYomi, kunYomi, meanings))
return results return results
@ -99,8 +99,8 @@ def parseKanjiDic(path):
def writeKanjiDic(cursor, values): def writeKanjiDic(cursor, values):
cursor.execute('DROP TABLE IF EXISTS Kanji') cursor.execute('DROP TABLE IF EXISTS Kanji')
cursor.execute('CREATE TABLE Radicals(character TEXT, kunYomi TEXT, onYomi TEXT, meanings TEXT)') cursor.execute('CREATE TABLE Kanji(character TEXT, kunYomi TEXT, onYomi TEXT, meanings TEXT)')
cursor.executemany('INSERT INTO Radicals VALUES(?, ?, ?, ?)', values) cursor.executemany('INSERT INTO Kanji VALUES(?, ?, ?, ?)', values)
def parseKradFile(path): def parseKradFile(path):