public static void Benchmark(string path, int testNumber) { int resultSum = 0; string[] testList = new string[testNumber]; List <LinSpell.SuggestItem> suggestions = null; //load 1000 terms with random spelling errors int i = 0; using (StreamReader sr = new StreamReader(File.OpenRead(path))) { String line; //process a single line at a time only for memory efficiency while ((line = sr.ReadLine()) != null) { string[] lineParts = line.Split(null); if (lineParts.Length >= 2) { string key = lineParts[0]; testList[i++] = key; } } } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //perform n rounds of Lookup of 1000 terms with random spelling errors int rounds = 10; for (int j = 0; j < rounds; j++) { resultSum = 0; //spellcheck strings for (i = 0; i < testNumber; i++) { suggestions = LinSpell.LookupLinear(testList[i], "", LinSpell.editDistanceMax); resultSum += suggestions.Count; } } stopWatch.Stop(); Console.WriteLine(resultSum.ToString("N0") + " results in " + (stopWatch.ElapsedMilliseconds / rounds).ToString() + " ms"); }
public static void Correct(string input, string language) { List <LinSpell.SuggestItem> suggestions = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //check if input term or similar terms within edit-distance are in dictionary, return results sorted by ascending edit distance, then by descending word frequency suggestions = LinSpell.LookupLinear(input, language, LinSpell.editDistanceMax); stopWatch.Stop(); Console.WriteLine(stopWatch.ElapsedMilliseconds.ToString() + " ms"); //display term and frequency foreach (var suggestion in suggestions) { Console.WriteLine(suggestion.term + " " + suggestion.distance.ToString() + " " + suggestion.count.ToString("N0")); } if (LinSpell.verbose != 0) { Console.WriteLine(suggestions.Count.ToString() + " suggestions"); } }