snichols Below is some code for a misspelling generator. It will misspell a word 5 different ways, but only one letter. This is the opposite of A Little Spellchecker.
proc cipherVowel {word} {
set vowels aeiou
set i [expr {round(rand() * ([string length $vowels] - 1))}]
set misspelling $word
foreach l [split $vowels ""] {
set j [string first $l $word]
if {$j > -1} {
return [string replace $word $j $j [string index $vowels $i]]
}
}
return $misspelling
}
proc skip {word} {
set i [expr {round(rand() * ([string length $word] -1))}]
return [string replace $word $i $i ""]
}
proc double {word} {
set i [expr {round(rand() * ([string length $word] -1))}]
return [string replace $word $i $i [string index $word $i][string index $word $i]]
}
proc reverse {word} {
set i [expr {round(rand() * ([string length $word] -1))}]
if { $i == [string length $word] -1} {
set i [expr [string length $word] -2]
}
set j [string index $word [expr $i + 1]]
set k [string index $word [expr $i]]
set misspelling [string replace $word $i $i $j]
return [string replace $misspelling [expr $i + 1] [expr $i + 1] $k]
}
proc skipSpace {word} {
set i [string first " " $word]
if { $i > -1} {
return [string replace $word $i $i ""]
} else {
return $word
}
}
proc insert {word} {
set letters abcdefghijklmnopqrstuvwxyz
set i [expr {round(rand() * ([string length $letters] - 1))}]
set j [expr {round(rand() * ([string length $word] - 1))}]
return [string replace $word $j $j [string index $word $j][string index $letters $i]]
}
lappend data "this is a test."
lappend data "fall"
lappend data "summer"
lappend data "spring"
lappend data "winter"
puts "correct|incorrect"
foreach word $data {
puts "$word|[cipherVowel $word]"
puts "$word|[skip $word]"
puts "$word|[reverse $word]"
puts "$word|[skipSpace $word]"
puts "$word|[insert $word]"
}