In [4]:
from word2keypress import distance, Keyboard
In [17]:
kb = Keyboard(u'US') # making unicode is mandatory (weird Cython)
kseq = kb.word_to_keyseq('Password')
print "\nRaw sequence:", repr(kseq)
print "\nReadable sequence:", repr(kb.print_keyseq(kseq))
print "\nkeyseq->word:", kb.keyseq_to_word(kseq)
In [19]:
print "All typos of 'Password' (keseq edit distance 1)"
print list(kb.word_to_typos('Password'))[:10]
In [20]:
word_pairs = [
('password', 'PASSWORD'),
('Password', 'password'),
('Password', 'PASSWORD'),
('Password1', 'Password!'),
('pASSWORD', 'Password'), # This is not good!
('P@ssword', 'Password')]
for w1, w2 in word_pairs:
assert distance(w1, w2)<3