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