/// <summary> /// Check if the word is spelled correctly /// </summary> /// <param name="word"></param> /// <returns></returns> public bool DoesWordExist(Word word) { if (word.Spell==null || word==null) return false; word = new WordDAO().Query(word); if (word == null || word.Id == 0) return false; else return true; }
/// <summary> /// Recursively checking for partial fit of given word /// Add result and rank (levenshtein distance) to a given dictionary /// </summary> /// <param name="word"></param> /// <param name="LevenshteinDistance"></param> /// <param name="suggestionDict"></param> public void GetSpellSuggestions(string word, int LevenshteinDistance, Dictionary<string, int> suggestionDict) { if (word.Length<3) return; List<Word> partialMatch=new WordDAO().FindPartialMatch(word); foreach (Word w in partialMatch) if (!suggestionDict.Keys.Contains(w.Spell)) suggestionDict[w.Spell]=LevenshteinDistance; GetSpellSuggestions(word.Substring(1), LevenshteinDistance + 1, suggestionDict); GetSpellSuggestions(word.Substring(0, word.Length - 1), LevenshteinDistance + 1, suggestionDict); }
/// <summary> /// Init DB /// </summary> private void LoadData() { new WordDAO().CreateTable(); new CommonMisspellDAO().CreateTable(); Word apple = new Word() { Spell = "Apple" }; Word people = new Word() { Spell = "People" }; apple=new WordDAO().Insert(apple); people=new WordDAO().Insert(people); new CommonMisspellDAO().Insert(new CommonMisspell() { FullWordId = apple.Id, Spell="appla" }); //List<SpellCheckSuggestion> suggestionsList = GetSpellSuggestions(new Word() { Spell = "Zpple" }); }