Package: wordvariations
Generates possible typing errors from a given string (neighboring keys and switch letters)pip install wordvariationsTested against Windows 10 / Python 3.10 / Anacondaswitch_letters:This function generates variations by switching neighboring letters in the input text as they might occur due to typographical errors.
It takes into account the spatial relationships between keys on the specified keyboard layout and creates multiple
unique variations by switching pairs of neighboring letters.change_lettersThis function generates variations by changing some of the letters in the input text to neighboring keys on the specified keyboard layout.
The resulting variations mimic possible errors caused by mistyping or keyboard layout peculiarities.
Users can control the maximum number of letter changes using the max_change parameter.These functions are useful for various applications, such as generating typing exercises for language learners,
creating diverse test datasets for natural language processing applications, or analyzing keyboard layouts'
ergonomic design. The module's advantages include efficiency through LRU caching,
customizability with adjustable parameters, and the ability to preserve the order of appearance for unique variations.Users interested in exploring potential typing errors, keyboard layouts, and text processing applications can
benefit from this module as it provides an easy-to-use interface for generating diverse text variations based on keyboard layout relationships."How to use switch_lettersGeneratevariationsoftheinputtextbyswitchingneighboringlettersonthespecifiedkeyboardlayout.Parameters:-----------text:strTheinputtextforwhichtogeneratevariations.keyboard_layout:strTheidentifierofthekeyboardlayout.Shouldbeoneofthesupportedlayouts(callshow_all_keyboards()toseethem).max_switches:int,optionalThemaximumnumberofswitchestoperform.Defaultis2.switch_numbers:bool,optionalIfTrue,allowsswitchingnumbersaswell.DefaultisFalse.timeout:intorfloat,optionalThemaximumtime(inseconds)tospendgeneratingvariations.Defaultis0.3seconds.Returns:--------listAlistcontainingtheoriginaltext(index0)andthevariationsobtainedbyswitchingneighboringletters.Thevariationsmayincludeupto`max_switches`switches,andtheresultisunique,preservingtheorder.Example:--------fromwordvariationsimportswitch_letters,change_letters,show_all_keyboardstext="Gustavo Lima"keyboard_layout="kbdbr_1"print(switch_letters(text=text,keyboard_layout=keyboard_layout,max_switches=10,switch_numbers=False,timeout=0.3,))['Gustavo Lima','Gutsavo Lima','Gutsavo Lmia','Gutsaov Lmia']Note:-----ThefunctionusesanLRUcachetospeeduprepeatedcallswiththesameinputs.How to use change_lettersGeneratevariationsoftheinputtextbychangingsomeoftheletterstotheirneighboringkeysonthespecifiedkeyboardlayout.Parameters:-----------text:strTheinputtextforwhichtogeneratevariations.keyboard_layout:strTheidentifierofthekeyboardlayout.Shouldbeoneofthesupportedlayouts(callshow_all_keyboards()toseethem).max_change:int,optionalThemaximumnumberofletterstochange.Defaultis1.include_numbers:bool,optionalIfTrue,includesnumbersintheallowedletters.DefaultisFalse.Returns:--------strAvariationoftheinputtextwithsomeletterschangedtoneighboringkeys.Example:--------fromwordvariationsimportswitch_letters,change_letters,show_all_keyboardstext="Gustavo Lima"keyboard_layout="kbdbr_1"forqinrange(3):print(change_letters(text,keyboard_layout,max_change=1,include_numbers=False))# Gustavo Limq# Gjstavo Lima# Vustavo LimaNote:-----ThefunctionusesanLRUcachetospeeduprepeatedcallswiththesameinputs.