prevent words from the dictionary prefixing smart hints
This commit is contained in:
parent
3c8598f691
commit
fe4800b68f
@ -1068,12 +1068,16 @@ class WordHinter:
|
|||||||
return any(hint.startswith(e) or e.startswith(hint)
|
return any(hint.startswith(e) or e.startswith(hint)
|
||||||
for e in existing)
|
for e in existing)
|
||||||
|
|
||||||
def new_hint_for(self, elem, existing):
|
def filter_prefixes(self, hints, existing):
|
||||||
|
return (h for h in hints if not self.any_prefix(h, existing))
|
||||||
|
|
||||||
|
def new_hint_for(self, elem, existing, fallback):
|
||||||
"""Return a hint for elem, not conflicting with the existing."""
|
"""Return a hint for elem, not conflicting with the existing."""
|
||||||
new = self.tag_words_to_hints(self.extract_tag_words(elem))
|
new = self.tag_words_to_hints(self.extract_tag_words(elem))
|
||||||
no_prefixes = (h for h in new if not self.any_prefix(h, existing))
|
new_no_prefixes = self.filter_prefixes(new, existing)
|
||||||
|
fallback_no_prefixes = self.filter_prefixes(fallback, existing)
|
||||||
# either the first good, or None
|
# either the first good, or None
|
||||||
return next(no_prefixes, None)
|
return next(new_no_prefixes, next(fallback_no_prefixes))
|
||||||
|
|
||||||
def hint(self, elems):
|
def hint(self, elems):
|
||||||
"""Produce hint labels based on the html tags.
|
"""Produce hint labels based on the html tags.
|
||||||
@ -1093,7 +1097,7 @@ class WordHinter:
|
|||||||
used_hints = set()
|
used_hints = set()
|
||||||
words = iter(self.words)
|
words = iter(self.words)
|
||||||
for elem in elems:
|
for elem in elems:
|
||||||
hint = self.new_hint_for(elem, used_hints) or next(words)
|
hint = self.new_hint_for(elem, used_hints, words)
|
||||||
used_hints.add(hint)
|
used_hints.add(hint)
|
||||||
hints.append(hint)
|
hints.append(hint)
|
||||||
return hints
|
return hints
|
||||||
|
Loading…
Reference in New Issue
Block a user