Return a list of (word, confidence) spelling corrections for the given word, based on the probability of known words with edit distance 1-2 from the given word.
(self, w)
| 1769 | return set(w for w in words if w in self) |
| 1770 | |
| 1771 | def suggest(self, w): |
| 1772 | """ Return a list of (word, confidence) spelling corrections for the given word, |
| 1773 | based on the probability of known words with edit distance 1-2 from the given word. |
| 1774 | """ |
| 1775 | if len(self) == 0: |
| 1776 | self.load() |
| 1777 | candidates = self._known([w]) \ |
| 1778 | or self._known(self._edit1(w)) \ |
| 1779 | or self._known(self._edit2(w)) \ |
| 1780 | or [w] |
| 1781 | candidates = [(self.get(w, 0.0), w) for w in candidates] |
| 1782 | s = float(sum(p for p, w in candidates) or 1) |
| 1783 | candidates = sorted(((p / s, w) for p, w in candidates), reverse=True) |
| 1784 | candidates = [(w, p) for p, w in candidates] |
| 1785 | return candidates |
| 1786 | |
| 1787 | #### MULTILINGUAL ################################################################################## |
| 1788 | # The default functions in each language submodule, with an optional language parameter: |