shorten unique word hints
This commit is contained in:
parent
50b7f260c7
commit
2f9051c6e1
@ -246,12 +246,26 @@ class HintManager(QObject):
|
|||||||
Return:
|
Return:
|
||||||
A list of hint strings, in the same order as the elements.
|
A list of hint strings, in the same order as the elements.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def html_text_to_hint(text):
|
||||||
|
if not text: return None
|
||||||
|
hint = text.split()[0].lower()
|
||||||
|
if hint.isalpha():
|
||||||
|
return hint
|
||||||
|
return None
|
||||||
|
|
||||||
|
def is_prefix(hint, existing):
|
||||||
|
return set(hint[:i+1] for i in range(len(hint))) & set(existing)
|
||||||
|
|
||||||
hints = []
|
hints = []
|
||||||
hintss = set()
|
hintss = set()
|
||||||
words = iter(self._words)
|
words = iter(self._words)
|
||||||
for elem in elems:
|
for elem in elems:
|
||||||
hint = _html_text_to_hint(str(elem)) or next(words)
|
hint = html_text_to_hint(str(elem))
|
||||||
while set(hint[:i+1] for i in range(len(hint))) & set(hintss):
|
if hint and len(hint) >= 3 and not is_prefix(hint, hintss):
|
||||||
|
hint = next(hint[:i] for i in range(3, len(hint) + 1)
|
||||||
|
if not is_prefix(hint[:i], hintss))
|
||||||
|
while not hint or is_prefix(hint, hintss):
|
||||||
hint = next(words)
|
hint = next(words)
|
||||||
hintss.add(hint)
|
hintss.add(hint)
|
||||||
hints.append(hint)
|
hints.append(hint)
|
||||||
@ -1010,9 +1024,3 @@ class HintManager(QObject):
|
|||||||
return
|
return
|
||||||
self._cleanup()
|
self._cleanup()
|
||||||
|
|
||||||
def _html_text_to_hint(text):
|
|
||||||
if not text: return None
|
|
||||||
hint = text.split()[0].lower()
|
|
||||||
if hint.isalpha():
|
|
||||||
return hint
|
|
||||||
return None
|
|
||||||
|
Loading…
Reference in New Issue
Block a user