Update to work with new dictionary format
This commit is contained in:
parent
d5dd702f71
commit
83fb78ba28
@ -16,6 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
import operator
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
@ -26,40 +27,51 @@ class Dictionary:
|
|||||||
|
|
||||||
|
|
||||||
def findTerm(self, word, wildcards=False):
|
def findTerm(self, word, wildcards=False):
|
||||||
self.requireIndex('Terms', 'expression')
|
self.requireIndex('Vocab', 'expression')
|
||||||
self.requireIndex('Terms', 'reading')
|
self.requireIndex('Vocab', 'reading')
|
||||||
|
self.requireIndex('VocabGloss', 'vocabId')
|
||||||
|
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if wildcards else '='), (word, word))
|
|
||||||
|
|
||||||
results = []
|
definitions = []
|
||||||
for expression, reading, glossary, tags in cursor.fetchall():
|
cursor.execute('SELECT * FROM Vocab WHERE expression {0} ? OR reading=?'.format('LIKE' if wildcards else '='), (word, word))
|
||||||
results.append({
|
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,
|
'expression': expression,
|
||||||
'glossary': glossary,
|
|
||||||
'reading': reading,
|
'reading': reading,
|
||||||
'tags': tags.split()
|
'tags': tags.split(),
|
||||||
|
'glossary': '; '.join(glossary)
|
||||||
})
|
})
|
||||||
|
|
||||||
return results
|
return definitions
|
||||||
|
|
||||||
|
|
||||||
def findCharacter(self, character):
|
def findCharacter(self, character):
|
||||||
assert len(character) == 1
|
assert len(character) == 1
|
||||||
|
|
||||||
self.requireIndex('Kanji', 'character')
|
self.requireIndex('Kanji', 'character')
|
||||||
|
self.requireIndex('KanjiGloss', 'kanjiId')
|
||||||
|
|
||||||
cursor = self.db.cursor()
|
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()
|
query = cursor.fetchone()
|
||||||
if query is not None:
|
if query is None:
|
||||||
character, kunyomi, onyomi, glossary = query
|
return
|
||||||
return {
|
|
||||||
'character': character,
|
kanjiId, character, kunyomi, onyomi = query
|
||||||
'glossary': glossary,
|
cursor.execute('SELECT glossary From KanjiGloss WHERE kanjiId=?', (kanjiId,))
|
||||||
'kunyomi': kunyomi,
|
glossary = map(operator.itemgetter(0), cursor)
|
||||||
'onyomi': onyomi
|
|
||||||
}
|
return {
|
||||||
|
'character': character,
|
||||||
|
'kunyomi': kunyomi,
|
||||||
|
'onyomi': onyomi,
|
||||||
|
'glossary': '; '.join(glossary),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def requireIndex(self, table, column):
|
def requireIndex(self, table, column):
|
||||||
|
Loading…
Reference in New Issue
Block a user