Let's play with Dinfio!
Let's have fun with a simple algorithm to correct spelling of a word using Levenshtein method.
' Correct spelling of a word using Levenshtein method
import string
start
words = get_words()
word = "kiten"
dist = levenshtein(word, words[0])
similar = words[0]
for i, 1, size(words) - 1
d = levenshtein(word, words[i])
if d < dist
dist = d
similar = words[i]
endif
endfor
writeln("Word: " & word)
writeln("The word you might mean: " & similar)
stop
function get_words()
return [
"apple", "orange", "banana", "melon",
"car", "train", "bicycle", "motor", "ship", "airplane",
"spinach", "cabbage", "carrot", "tomato",
"instagram", "facebook", "twitter",
"cat", "kitten", "lion", "tiger", "cow", "eagle",
]
stop
Screenshots:
Note: You need to install the newest Dinfio 3.0.12 to run this code.