// вход - список слов // выход - список слов, по которым орфография пройдена успешно private List <string> CheckBlock(List <string> InnerWordList) { //результат List <string> res = new List <string>(); if (isObjectReady == false) { return(res); } // для всех слов, если их меньше тысячи foreach (string SingleWord in InnerWordList) { // нормализуем входящее слово string NormalWord = SingleWord.ToLower().Trim(); // отсекаем пустые слова if (NormalWord == "") { continue; } if (isDicionaryLoaded == true) { // проверяем в основном словаре if (dict1.Contains(NormalWord)) { res.Add(NormalWord); continue; } // проверяем в пользовательском словаре if (dict2.Contains(NormalWord)) { res.Add(NormalWord); continue; } } // проверяем в MsWord само слово if (WordApp.CheckSpelling(NormalWord) == true) { res.Add(NormalWord); dict2.Add(NormalWord); continue; } // проверяем в MsWord капитализированное слово string CapitalizedWord = NormalWord.Substring(0, 1).ToUpper() + NormalWord.Substring(1, NormalWord.Length - 1); if (WordApp.CheckSpelling(CapitalizedWord) == true) { res.Add(NormalWord); dict2.Add(NormalWord); continue; } } return(res); }
/* GetPoints() method accepts a string containing a candidate word and returns its potential point value based on two criteria: 1) * the letters of the candidate string are a subset of the letters in the current rack object, 2) the candidate provided is a valid * word as tested using the IApplication interface’s CheckSpelling() method. If a candidate word fails to meet either criteria * the method return 0.*/ public int GetPoints(string candidate) { candidate = candidate.ToLower(); int score = 0; if (word.CheckSpelling(candidate) == true) { int value; for (int nc = 0; nc < candidate.Length; nc++) { if (letterValue.TryGetValue(candidate.ElementAt(nc), out value)) { score += value; } } } return(score); }
//Check Spelling of word public bool CheckSpelling(string word) { try { return(application.CheckSpelling(word.ToLower()));; } catch (Exception Ex) { Console.WriteLine("Exception occurred:" + Ex.Message); } return(false); }
// проверим существование и работу спелчекера // выход - true/false private static bool CheckMsWord() { Log.Write("words Проверяем наличие MS Word"); try { var wa = new Microsoft.Office.Interop.Word.Application(); wa.CheckSpelling(teststring); wa.Quit(); Log.Write("words MS Word точно есть"); return(true); } catch { Log.Write("words ERROR: MS Word не удалось запустить, проверить слова, или какие-то другие проблемы"); return(false); } }