MCPcopy Index your code
hub / github.com/clips/pattern / _edit1

Method _edit1

pattern/text/__init__.py:1745–1757  ·  view source on GitHub ↗

Returns a set of words with edit distance 1 from the given word.

(self, w)

Source from the content-addressed store, hash-verified

1743 f.close()
1744
1745 def _edit1(self, w):
1746 """ Returns a set of words with edit distance 1 from the given word.
1747 """
1748 # Of all spelling errors, 80% is covered by edit distance 1.
1749 # Edit distance 1 = one character deleted, swapped, replaced or inserted.
1750 split = [(w[:i], w[i:]) for i in range(len(w) + 1)]
1751 delete, transpose, replace, insert = (
1752 [a + b[1:] for a, b in split if b],
1753 [a + b[1] + b[0] + b[2:] for a, b in split if len(b) > 1],
1754 [a + c + b[1:] for a, b in split for c in Spelling.ALPHA if b],
1755 [a + c + b[0:] for a, b in split for c in Spelling.ALPHA]
1756 )
1757 return set(delete + transpose + replace + insert)
1758
1759 def _edit2(self, w):
1760 """ Returns a set of words with edit distance 2 from the given word

Callers 2

_edit2Method · 0.95
suggestMethod · 0.95

Calls 1

lenFunction · 0.85

Tested by

no test coverage detected