Created
April 5, 2013 19:03
-
-
Save yetanotherchris/5321758 to your computer and use it in GitHub Desktop.
How to Write a Spelling Corrector in C# (example usage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Spelling spelling = new Spelling(); | |
string word = ""; | |
word = "speling"; | |
Console.WriteLine("{0} => {1}", word, spelling.Correct(word)); | |
word = "korrecter"; // 'correcter' is not in the dictionary file so this doesn't work | |
Console.WriteLine("{0} => {1}", word, spelling.Correct(word)); | |
word = "korrect"; | |
Console.WriteLine("{0} => {1}", word, spelling.Correct(word)); | |
word = "acess"; | |
Console.WriteLine("{0} => {1}", word, spelling.Correct(word)); | |
word = "supposidly"; | |
Console.WriteLine("{0} => {1}", word, spelling.Correct(word)); | |
// A sentence | |
string sentence = "I havve speled thes woord wwrong"; // sees speed instead of spelled (see notes on norvig.com) | |
string correction = ""; | |
foreach (string item in sentence.Split(' ')) | |
{ | |
correction += " " +spelling.Correct(item); | |
} | |
Console.WriteLine("Did you mean:" + correction); | |
Console.Read(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment