Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Peter Norvig (Director of Research at Google) has written a little introductory piece on <a href="http://norvig.com/spell-correct.html" rel="nofollow noreferrer">spell checking in Python</a> using statistical heuristics.</p> <p>It's a great read, and shows how to use statistical heuristics in a very simple way. It could be ported to C# (with LINQ) quite easily (Python's list comprehensions are very close to Linq expressions).</p> <p>The core part of this snippet is having all simple typos for a word (edit1 function) the C# equivalent is the following</p> <pre><code>public static IEnumerable&lt;string&gt; Edit1(string word){ const string alphabet = "abcdefghijklmnopqrstuvwxyz"; var s = from i in Enumerable.Range (0, word.Length - 1) select new Pair&lt;string&gt;(word.Substring (0, i), word.RSlice(i)); var deletes = from p in s select p.First + p.Second.RSlice (1); var transposes = from p in s let b1 = p.Second where b1.Length &gt; 2 select p.First + b1 [1] + b1 [0] + b1.RSlice (2); var replaces = from p in s let b = p.Second where b.Length &gt; 0 from c in alphabet select p.First + c + b.RSlice (1); var inserts = from p in s from c in alphabet select p.First + c + p.Second; return deletes.Concat (transposes).Concat( replaces) .Concat(inserts).Distinct ();} </code></pre> <p>where Pair is a poor man tuple (obvious code not included) and RSlice is a poor-man string-only right splicing :</p> <pre><code>public static class Extensions { public static string RSlice (this string input, int i) { if (i &gt; input.Length - 1) return ""; return input.Substring (i); }} </code></pre> <p>Once you got the edits for a word, you look for the word in the dictionary or the existing words of the edits (selecting the most frequent word) or the words for edits1(edits1(word)) (selecting the most frequent word). Surprisingly, this can be quite fast and quite accurate. I'll have a link to my blog for the whole stuff ported.</p> <p>Edit: oops just saw that a link in an answer above pointed to a pointer to the same Norvig's piece...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload