1

Update to work with new dictionary format

This commit is contained in:
Alex Yatskov 2016-05-09 12:21:43 -07:00
parent d5dd702f71
commit 83fb78ba28

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import operator
import sqlite3
@ -26,39 +27,50 @@ class Dictionary:
def findTerm(self, word, wildcards=False):
self.requireIndex('Terms', 'expression')
self.requireIndex('Terms', 'reading')
self.requireIndex('Vocab', 'expression')
self.requireIndex('Vocab', 'reading')
self.requireIndex('VocabGloss', 'vocabId')
cursor = self.db.cursor()
cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if wildcards else '='), (word, word))
results = []
for expression, reading, glossary, tags in cursor.fetchall():
results.append({
definitions = []
cursor.execute('SELECT * FROM Vocab WHERE expression {0} ? OR reading=?'.format('LIKE' if wildcards else '='), (word, word))
for vocabId, expression, reading, tags in cursor:
cursor.execute('SELECT glossary From VocabGloss WHERE vocabId=?', (vocabId,))
glossary = map(operator.itemgetter(0), cursor)
definitions.append({
'expression': expression,
'glossary': glossary,
'reading': reading,
'tags': tags.split()
'tags': tags.split(),
'glossary': '; '.join(glossary)
})
return results
return definitions
def findCharacter(self, character):
assert len(character) == 1
self.requireIndex('Kanji', 'character')
self.requireIndex('KanjiGloss', 'kanjiId')
cursor = self.db.cursor()
cursor.execute('SELECT * FROM Kanji WHERE character=? LIMIT 1', character)
cursor.execute('SELECT * FROM Kanji WHERE character=? LIMIT 1', character)
query = cursor.fetchone()
if query is not None:
character, kunyomi, onyomi, glossary = query
if query is None:
return
kanjiId, character, kunyomi, onyomi = query
cursor.execute('SELECT glossary From KanjiGloss WHERE kanjiId=?', (kanjiId,))
glossary = map(operator.itemgetter(0), cursor)
return {
'character': character,
'glossary': glossary,
'kunyomi': kunyomi,
'onyomi': onyomi
'onyomi': onyomi,
'glossary': '; '.join(glossary),
}