Spell Checker- Operation on Text-NLP

operation on text:

Split
Delete
Swap
Replace
Insert

Split

We are going to split the word but character by character.

def split(word):
parts=[]
for i in range(len(word)+1):
parts+=[(word[ : i],word[i :])]
return part…


This content originally appeared on DEV Community and was authored by datatoinfinity

operation on text:

  • Split
  • Delete
  • Swap
  • Replace
  • Insert

Split

We are going to split the word but character by character.

def split(word):
    parts=[]
    for i in range(len(word)+1):
        parts+=[(word[ : i],word[i :])]
    return parts
split('datatoinfinity')
Output:
[('', 'datatoinfinity'),
 ('d', 'atatoinfinity'),
 ('da', 'tatoinfinity'),
 ('dat', 'atoinfinity'),
 ('data', 'toinfinity'),
 ('datat', 'oinfinity'),
 ('datato', 'infinity'),
 ('datatoi', 'nfinity'),
 ('datatoin', 'finity'),
 ('datatoinf', 'inity'),
 ('datatoinfi', 'nity'),
 ('datatoinfin', 'ity'),
 ('datatoinfini', 'ty'),
 ('datatoinfinit', 'y'),
 ('datatoinfinity', '')]

Delete

def delete(word):
    output=[]
    for l,r in split(word):
        output.append(l+r[1:])
    return output
delete('hello')
['ello', 'hllo', 'helo', 'helo', 'hell', 'hello']

It is deleting character by character.

Swap

def swap(word):
        
    output = []    
    for l,r in split(word):
        if (len(r) > 1):
            output.append(l + r[1] + r[0] + r[2:])
    return output
            
swap('Hello')
['eHllo', 'Hlelo', 'Hello', 'Helol']

Replace

def replace(word):
    
    characters = 'abcdefghijklmnopqrstuvwxyz'
    output = []    

    for l,r in split(word):
        for char in characters:
            output.append(l + char +  r[1:])
    return output

len(replace('lave'))
130

Insert

def insert(word):

    characters = 'abcdefghijklmnopqrstuvwxyz'
    output = []

    for l,r in split(word):
        for char in characters:
            output.append(l + char + r)

    return output

len(insert('lve'))
104


This content originally appeared on DEV Community and was authored by datatoinfinity


Print Share Comment Cite Upload Translate Updates
APA

datatoinfinity | Sciencx (2025-06-29T09:06:03+00:00) Spell Checker- Operation on Text-NLP. Retrieved from https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/

MLA
" » Spell Checker- Operation on Text-NLP." datatoinfinity | Sciencx - Sunday June 29, 2025, https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/
HARVARD
datatoinfinity | Sciencx Sunday June 29, 2025 » Spell Checker- Operation on Text-NLP., viewed ,<https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/>
VANCOUVER
datatoinfinity | Sciencx - » Spell Checker- Operation on Text-NLP. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/
CHICAGO
" » Spell Checker- Operation on Text-NLP." datatoinfinity | Sciencx - Accessed . https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/
IEEE
" » Spell Checker- Operation on Text-NLP." datatoinfinity | Sciencx [Online]. Available: https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/. [Accessed: ]
rf:citation
» Spell Checker- Operation on Text-NLP | datatoinfinity | Sciencx | https://www.scien.cx/2025/06/29/spell-checker-operation-on-text-nlp/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.