1

Cleaning up reader_util, making sorting order better for translator

Former-commit-id: 5597695db5254d71c294404d87431e1c99cc3d9e
This commit is contained in:
Alex Yatskov 2013-11-09 18:08:20 -08:00
parent 21838ed26d
commit d2c9cb7b6b
3 changed files with 7 additions and 14 deletions

View File

@ -41,7 +41,7 @@ class Translator:
results = map(self.formatResult, groups.items()) results = map(self.formatResult, groups.items())
results = filter(operator.truth, results) results = filter(operator.truth, results)
results = sorted(results, key=lambda d: ('P' in d['tags'], len(d['source'])), reverse=True) results = sorted(results, key=lambda d: (len(d['source']), 'P' in d['tags'], -len(d['rules'])), reverse=True)
length = 0 length = 0
for result in results: for result in results:

View File

@ -269,8 +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.findTerm(text, True) self.state.definitions, length = self.language.findTerm(text, True)
self.state.definitions = reader_util.convertDefinitions(definitions)
self.updateDefinitions() self.updateDefinitions()
@ -489,10 +488,12 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
return return
contentSampleFlat = contentSample.replace('\n', unicode()) contentSampleFlat = contentSample.replace('\n', unicode())
definitionsMatched, lengthMatched = self.language.findTerm(contentSampleFlat) self.state.definitions, lengthMatched = self.language.findTerm(contentSampleFlat)
sentence = reader_util.findSentence(content, samplePosStart)
sentence = reader_util.findSentence(content, samplePosStart)
for definition in self.state.definitions:
definition['sentence'] = sentence
self.state.definitions = reader_util.convertDefinitions(definitionsMatched, sentence)
self.updateDefinitions() self.updateDefinitions()
lengthSelect = 0 lengthSelect = 0

View File

@ -117,14 +117,6 @@ def splitTags(tags):
return filter(lambda tag: tag.strip(), re.split('[;,\s]', tags)) return filter(lambda tag: tag.strip(), re.split('[;,\s]', tags))
def convertDefinitions(definitions, sentence=None):
if sentence is not None:
for definition in definitions:
definition['sentence'] = sentence
return definitions
def copyDefinitions(definitions): def copyDefinitions(definitions):
text = unicode() text = unicode()