Adding code to make Yomichan work with the new dictionary and deinflector
Former-commit-id: dc63a286c7de76d0cbb723a30df5bdf881d6bb34
This commit is contained in:
parent
e15dea9921
commit
18bae9b3d2
@ -27,7 +27,7 @@ class Translator:
|
||||
self.dictionary = dictionary
|
||||
|
||||
|
||||
def wordSearch(self, selection):
|
||||
def findTerm(self, selection, partial=False):
|
||||
groups = dict()
|
||||
|
||||
for i in xrange(len(selection), 0, -1):
|
||||
@ -35,7 +35,7 @@ class Translator:
|
||||
|
||||
deinflections = self.deinflector.deinflect(term, self.validator)
|
||||
if deinflections is None:
|
||||
self.processTerm(groups, term)
|
||||
self.processTerm(groups, term, partial=partial)
|
||||
else:
|
||||
for deinflection in deinflections:
|
||||
self.processTerm(groups, **deinflection)
|
||||
@ -51,10 +51,10 @@ class Translator:
|
||||
return results, length
|
||||
|
||||
|
||||
def processTerm(self, groups, source, rules=list(), root=str()):
|
||||
def processTerm(self, groups, source, rules=list(), root=str(), partial=False):
|
||||
root = root or source
|
||||
|
||||
for entry in self.dictionary.findTerm(root):
|
||||
for entry in self.dictionary.findTerm(root, partial):
|
||||
expression, reading, definition, tags = entry
|
||||
key = expression, reading, definition
|
||||
if key not in groups:
|
||||
|
@ -269,11 +269,7 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
|
||||
def onDefinitionSearchReturn(self):
|
||||
text = unicode(self.textDefinitionSearch.text())
|
||||
definitions, length = self.language.wordSearch(
|
||||
text,
|
||||
self.preferences.searchResultMax,
|
||||
self.preferences.searchGroupByExp
|
||||
)
|
||||
definitions, length = self.language.findTerm(text, True)
|
||||
self.state.definitions = reader_util.convertDefinitions(definitions)
|
||||
self.updateDefinitions()
|
||||
|
||||
@ -493,11 +489,7 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
return
|
||||
|
||||
contentSampleFlat = contentSample.replace('\n', unicode())
|
||||
definitionsMatched, lengthMatched = self.language.wordSearch(
|
||||
contentSampleFlat,
|
||||
self.preferences.searchResultMax,
|
||||
self.preferences.searchGroupByExp
|
||||
)
|
||||
definitionsMatched, lengthMatched = self.language.findTerm(contentSampleFlat)
|
||||
sentence = reader_util.findSentence(content, samplePosStart)
|
||||
|
||||
self.state.definitions = reader_util.convertDefinitions(definitionsMatched, sentence)
|
||||
|
@ -144,9 +144,10 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
|
||||
if definition.reading:
|
||||
reading = u'[{0}]'.format(definition.reading)
|
||||
|
||||
conjugation = unicode()
|
||||
if definition.conjugations:
|
||||
conjugation = '<span class = "conjugations"><{0}><br/></span>'.format(definition.conjugations)
|
||||
conjugations = unicode()
|
||||
if len(definition.conjugations) > 0:
|
||||
conjugations = u' :: '.join(definition.conjugations)
|
||||
conjugations = '<span class = "conjugations"><{0}><br/></span>'.format(conjugations)
|
||||
|
||||
links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex)
|
||||
if factQuery:
|
||||
@ -159,8 +160,8 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
|
||||
<span class = "links">{0}</span>
|
||||
<span class = "expression">{1} {2}<br/></span>
|
||||
<span class = "glossary">{3}<br/></span>
|
||||
<span class = "conjugation">{4}</span>
|
||||
<br clear = "all"/>""".format(links, definition.expression, reading, definition.glossary, conjugation)
|
||||
<span class = "conjugations">{4}</span>
|
||||
<br clear = "all"/>""".format(links, definition.expression, reading, definition.glossary, conjugations)
|
||||
|
||||
return html
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user