Updating Kanji lookup, temporarily disabling fancy search
Former-commit-id: c6e298b51f4d5ae8596244fe97e227bc8fa2dc18
This commit is contained in:
parent
4423e7efc0
commit
170484fa24
@ -1,9 +1,8 @@
|
||||
#/bin/sh
|
||||
|
||||
KANJIDIC=util/kanjidic
|
||||
KRADFILE=util/kradfile
|
||||
EDICT=util/edict
|
||||
DICT=yomi_base/japanese/dictionary.db
|
||||
|
||||
rm $DICT
|
||||
util/compile.py --kanjidic $KANJIDIC --kradfile $KRADFILE --edict $EDICT $DICT
|
||||
util/compile.py --kanjidic $KANJIDIC --edict $EDICT $DICT
|
||||
|
@ -222,6 +222,9 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textKanjiDefs">
|
||||
<property name="acceptDrops">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
@ -110,7 +110,7 @@ def parseKanjiDic(path):
|
||||
kunyomi = ', '.join(filter(lambda x: filter(isHiragana, x), segments[1:]))
|
||||
onyomi = ', '.join(filter(lambda x: filter(isKatakana, x), segments[1:]))
|
||||
glossary = '; '.join(re.findall('\{([^\}]+)\}', line))
|
||||
results.append((character, onyomi, kunyomi, glossary))
|
||||
results.append((character, kunyomi, onyomi, glossary))
|
||||
|
||||
return results
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 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
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 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
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 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
|
||||
#
|
||||
# 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.setObjectName(_fromUtf8("verticalLayout_3"))
|
||||
self.textKanjiDefs = QtGui.QTextBrowser(self.dockWidgetContents_3)
|
||||
self.textKanjiDefs.setAcceptDrops(False)
|
||||
self.textKanjiDefs.setOpenLinks(False)
|
||||
self.textKanjiDefs.setObjectName(_fromUtf8("textKanjiDefs"))
|
||||
self.verticalLayout_3.addWidget(self.textKanjiDefs)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 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)
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4718fcf7ca6fbb26611ba5246e75faed0a4d8ccb994e811724a5c5ca1b9e182a
|
||||
size 20370432
|
||||
oid sha256:ee0729e4d5ea0664f655902ad56d64bc930689f251ab1e9efe28292f1dc7de13
|
||||
size 20201472
|
||||
|
@ -31,7 +31,7 @@ class Dictionary:
|
||||
self.requireIndex('Terms', 'reading')
|
||||
|
||||
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()
|
||||
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):
|
||||
name = 'index_{0}_{1}'.format(table, column)
|
||||
if not self.hasIndex(name):
|
||||
|
@ -50,13 +50,13 @@ class Translator:
|
||||
return results, length
|
||||
|
||||
|
||||
def findCharacter(self, text):
|
||||
assert len(text) == 1
|
||||
return self.dictionary.findCharacter(text)
|
||||
def findCharacters(self, text):
|
||||
results = dict()
|
||||
for c in text:
|
||||
if c not in results:
|
||||
results[c] = self.dictionary.findCharacter(c)
|
||||
|
||||
|
||||
def findCharacterVisually(self, text):
|
||||
return self.dictionary.findCharacterVisually(text)
|
||||
return filter(operator.truth, results.values())
|
||||
|
||||
|
||||
def processTerm(self, groups, source, rules=list(), root=str(), partial=False):
|
||||
|
@ -265,12 +265,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
|
||||
def onKanjiDefSearchReturn(self):
|
||||
text = unicode(self.textKanjiSearch.text())
|
||||
if len(text) == 1:
|
||||
result = self.language.findCharacter(text)
|
||||
self.state.kanjiDefs = list() if result is None else [result]
|
||||
else:
|
||||
self.state.kanjiDefs = self.language.findCharacterVisually(text)
|
||||
|
||||
self.state.kanjiDefs = self.language.findCharacters(text)
|
||||
self.updateKanjiDefs()
|
||||
|
||||
|
||||
|
@ -162,7 +162,7 @@ def buildVocabDef(definition, index, query):
|
||||
rules = '<span class = "rules"><{0}><br/></span>'.format(rules)
|
||||
|
||||
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)):
|
||||
links += '<a href = "addVocabExp:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index)
|
||||
if query('vocab', markupVocabReading(definition)):
|
||||
@ -170,7 +170,8 @@ def buildVocabDef(definition, index, query):
|
||||
|
||||
html = u"""
|
||||
<span class = "links">{0}</span>
|
||||
<span class = "expression">{1} {2}<br/></span>
|
||||
<span class = "expression">{1}<br/></span>
|
||||
<span class = "reading">{2}<br/></span>
|
||||
<span class = "glossary">{3}<br/></span>
|
||||
<span class = "rules">{4}</span>
|
||||
<br clear = "all"/>""".format(links, definition['expression'], reading, definition['glossary'], rules)
|
||||
@ -194,14 +195,16 @@ def buildVocabDefs(definitions, query):
|
||||
|
||||
def buildKanjiDef(definition, index, query):
|
||||
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)
|
||||
|
||||
readings = ', '.join([definition['kunyomi'], definition['onyomi']])
|
||||
html = u"""
|
||||
<span class = "links">{0}</span>
|
||||
<span class = "character">{1}<br/></span>
|
||||
<span class = "glossary">{2}<br/></span>
|
||||
<br clear = "all"/>""".format(links, definition['character'], definition['glossary'])
|
||||
<span class = "expression">{1}<br/></span>
|
||||
<span class = "reading">[{2}]<br/></span>
|
||||
<span class = "glossary">{3}</span>
|
||||
<br clear = "all"/>""".format(links, definition['character'], readings, definition['glossary'])
|
||||
|
||||
return html
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user