This Kotlin project implements a simple spell checker using the Wagner-Fischer algorithm. The spell checker provides suggestions for the closest words to a misspelled word based on a given dictionary.
To use the spell checker, follow these steps:
- Ensure Kotlin is installed on your machine.
- Run the
main
function in your Kotlin project.
fun main() {
val wordList = Utils.getStringsFromWordFile()
val misspelledWord = "forsed"
val suggestions = spellCheck(misspelledWord, wordList)
println("Closest suggestions for $misspelledWord:")
for ((suggestion, distance) in suggestions) {
println("$suggestion ($distance)")
}
}
The spell checker utilizes the Wagner-Fischer algorithm, a dynamic programming approach to calculate the edit distance between two strings. It compares the input word to the words in the dictionary, providing a list of suggestions sorted by their edit distance.
Assuming a dictionary loaded from a file(In current project words.txt which contains 10k words), the example above would output suggestions for the misspelled word "forsed."