1

Updating Kanji lookup, temporarily disabling fancy search

Former-commit-id: c6e298b51f4d5ae8596244fe97e227bc8fa2dc18
This commit is contained in:
Alex Yatskov 2013-11-14 09:22:20 -08:00
parent 4423e7efc0
commit 170484fa24
12 changed files with 30 additions and 71 deletions

View File

@ -1,9 +1,8 @@
#/bin/sh #/bin/sh
KANJIDIC=util/kanjidic KANJIDIC=util/kanjidic
KRADFILE=util/kradfile
EDICT=util/edict EDICT=util/edict
DICT=yomi_base/japanese/dictionary.db DICT=yomi_base/japanese/dictionary.db
rm $DICT rm $DICT
util/compile.py --kanjidic $KANJIDIC --kradfile $KRADFILE --edict $EDICT $DICT util/compile.py --kanjidic $KANJIDIC --edict $EDICT $DICT

View File

@ -222,6 +222,9 @@
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTextBrowser" name="textKanjiDefs"> <widget class="QTextBrowser" name="textKanjiDefs">
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="openLinks"> <property name="openLinks">
<bool>false</bool> <bool>false</bool>
</property> </property>

View File

@ -110,7 +110,7 @@ def parseKanjiDic(path):
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:]))
glossary = '; '.join(re.findall('\{([^\}]+)\}', line)) glossary = '; '.join(re.findall('\{([^\}]+)\}', line))
results.append((character, onyomi, kunyomi, glossary)) results.append((character, kunyomi, onyomi, glossary))
return results return results

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/about.ui' # Form implementation generated from reading ui file 'ui/about.ui'
# #
# Created: Thu Nov 14 08:32:50 2013 # Created: Thu Nov 14 09:02:10 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/preferences.ui' # Form implementation generated from reading ui file 'ui/preferences.ui'
# #
# Created: Thu Nov 14 08:32:50 2013 # Created: Thu Nov 14 09:02:10 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/reader.ui' # Form implementation generated from reading ui file 'ui/reader.ui'
# #
# Created: Thu Nov 14 08:32:50 2013 # Created: Thu Nov 14 09:02:10 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -122,6 +122,7 @@ class Ui_MainWindowReader(object):
self.verticalLayout_3 = QtGui.QVBoxLayout(self.dockWidgetContents_3) self.verticalLayout_3 = QtGui.QVBoxLayout(self.dockWidgetContents_3)
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.textKanjiDefs = QtGui.QTextBrowser(self.dockWidgetContents_3) self.textKanjiDefs = QtGui.QTextBrowser(self.dockWidgetContents_3)
self.textKanjiDefs.setAcceptDrops(False)
self.textKanjiDefs.setOpenLinks(False) self.textKanjiDefs.setOpenLinks(False)
self.textKanjiDefs.setObjectName(_fromUtf8("textKanjiDefs")) self.textKanjiDefs.setObjectName(_fromUtf8("textKanjiDefs"))
self.verticalLayout_3.addWidget(self.textKanjiDefs) self.verticalLayout_3.addWidget(self.textKanjiDefs)

View File

@ -2,7 +2,7 @@
# Resource object code # Resource object code
# #
# Created: Thu Nov 14 08:32:50 2013 # Created: Thu Nov 14 09:02:10 2013
# by: The Resource Compiler for PyQt (Qt v4.8.4) # by: The Resource Compiler for PyQt (Qt v4.8.4)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4718fcf7ca6fbb26611ba5246e75faed0a4d8ccb994e811724a5c5ca1b9e182a oid sha256:ee0729e4d5ea0664f655902ad56d64bc930689f251ab1e9efe28292f1dc7de13
size 20370432 size 20201472

View File

@ -31,7 +31,7 @@ class Dictionary:
self.requireIndex('Terms', 'reading') self.requireIndex('Terms', 'reading')
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if partial else '='), (word, word)) cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=? LIMIT 100'.format('LIKE' if partial else '='), (word, word))
results = list() results = list()
for expression, reading, glossary, tags in cursor.fetchall(): for expression, reading, glossary, tags in cursor.fetchall():
@ -63,48 +63,6 @@ class Dictionary:
} }
def findCharacterVisually(self, characters):
radicals = dict()
for character in characters:
for radical in self.findRadicalsByCharacter(character) or list():
radicals[radical] = radicals.get(radical, 0) + 1
characters = dict()
for radical, count in radicals.items():
for character in self.findCharactersByRadical(radical) or list():
characters[character] = characters.get(character, 0) + count
results = list()
for character, score in sorted(characters.items(), key=operator.itemgetter(1), reverse=True):
result = self.findCharacter(character)
if result is not None:
results.append(result)
return results
def findRadicalsByCharacter(self, character):
cursor = self.db.cursor()
cursor.execute('SELECT radicals FROM Radicals WHERE character=? LIMIT 1', character)
columns = cursor.fetchone()
if columns is None:
return None
return columns[0].split()
def findCharactersByRadical(self, radical):
cursor = self.db.cursor()
cursor.execute('SELECT character FROM Radicals WHERE radicals LIKE ?', (u'%{0}%'.format(radical),))
columns = cursor.fetchall()
if columns is None:
return None
return map(operator.itemgetter(0), columns)
def requireIndex(self, table, column): def requireIndex(self, table, column):
name = 'index_{0}_{1}'.format(table, column) name = 'index_{0}_{1}'.format(table, column)
if not self.hasIndex(name): if not self.hasIndex(name):

View File

@ -50,13 +50,13 @@ class Translator:
return results, length return results, length
def findCharacter(self, text): def findCharacters(self, text):
assert len(text) == 1 results = dict()
return self.dictionary.findCharacter(text) for c in text:
if c not in results:
results[c] = self.dictionary.findCharacter(c)
return filter(operator.truth, results.values())
def findCharacterVisually(self, text):
return self.dictionary.findCharacterVisually(text)
def processTerm(self, groups, source, rules=list(), root=str(), partial=False): def processTerm(self, groups, source, rules=list(), root=str(), partial=False):

View File

@ -265,12 +265,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
def onKanjiDefSearchReturn(self): def onKanjiDefSearchReturn(self):
text = unicode(self.textKanjiSearch.text()) text = unicode(self.textKanjiSearch.text())
if len(text) == 1: self.state.kanjiDefs = self.language.findCharacters(text)
result = self.language.findCharacter(text)
self.state.kanjiDefs = list() if result is None else [result]
else:
self.state.kanjiDefs = self.language.findCharacterVisually(text)
self.updateKanjiDefs() self.updateKanjiDefs()

View File

@ -162,7 +162,7 @@ def buildVocabDef(definition, index, query):
rules = '<span class = "rules">&lt;{0}&gt;<br/></span>'.format(rules) rules = '<span class = "rules">&lt;{0}&gt;<br/></span>'.format(rules)
links = '<a href = "copyVocabDef:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(index) links = '<a href = "copyVocabDef:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(index)
if query: if query is not None:
if query('vocab', markupVocabExp(definition)): if query('vocab', markupVocabExp(definition)):
links += '<a href = "addVocabExp:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index) links += '<a href = "addVocabExp:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index)
if query('vocab', markupVocabReading(definition)): if query('vocab', markupVocabReading(definition)):
@ -170,7 +170,8 @@ def buildVocabDef(definition, index, query):
html = u""" html = u"""
<span class = "links">{0}</span> <span class = "links">{0}</span>
<span class = "expression">{1}&nbsp;{2}<br/></span> <span class = "expression">{1}<br/></span>
<span class = "reading">{2}<br/></span>
<span class = "glossary">{3}<br/></span> <span class = "glossary">{3}<br/></span>
<span class = "rules">{4}</span> <span class = "rules">{4}</span>
<br clear = "all"/>""".format(links, definition['expression'], reading, definition['glossary'], rules) <br clear = "all"/>""".format(links, definition['expression'], reading, definition['glossary'], rules)
@ -194,14 +195,16 @@ def buildVocabDefs(definitions, query):
def buildKanjiDef(definition, index, query): def buildKanjiDef(definition, index, query):
links = '<a href = "copyKanjiDef:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(index) links = '<a href = "copyKanjiDef:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(index)
if query and query('kanji', markupKanji(definition)): if query is not None and query('kanji', markupKanji(definition)):
links += '<a href = "addKanji:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index) links += '<a href = "addKanji:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index)
readings = ', '.join([definition['kunyomi'], definition['onyomi']])
html = u""" html = u"""
<span class = "links">{0}</span> <span class = "links">{0}</span>
<span class = "character">{1}<br/></span> <span class = "expression">{1}<br/></span>
<span class = "glossary">{2}<br/></span> <span class = "reading">[{2}]<br/></span>
<br clear = "all"/>""".format(links, definition['character'], definition['glossary']) <span class = "glossary">{3}</span>
<br clear = "all"/>""".format(links, definition['character'], readings, definition['glossary'])
return html return html