Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created April 5, 2013 19:03
Show Gist options
  • Save yetanotherchris/5321758 to your computer and use it in GitHub Desktop.
Save yetanotherchris/5321758 to your computer and use it in GitHub Desktop.
How to Write a Spelling Corrector in C# (example usage)
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