public void TestWord() { Spelling _SpellChecker = NewSpellChecker(); Assert.IsTrue(_SpellChecker.TestWord("test"), "Did not find test word"); Assert.IsFalse(_SpellChecker.TestWord("tst"), "Found tst word and shouldn't have"); }
private SpellingResult CheckSpelling(string text, char delim) { string[] lines = text.Split(delim); List <string> regLines = new List <string>(); string markedLines = ""; int lineNum = 0; int i = 1; foreach (string l in lines) { string editLine = l.Trim(); while (editLine.Contains(" ")) { int iSpace = editLine.IndexOf(" "); editLine = Substring(editLine, 0, iSpace) + Substring(editLine, iSpace + 1, editLine.Length); } if (editLine.Length > 0) { string[] words = editLine.Split(' '); if (words.Length == 2) { words[0] = CapFirst(words[0]); words[1] = CapFirst(words[1]); bool sFirst = spellCheck.TestWord(words[0]); bool sLast = spellCheck.TestWord(words[1]); regLines.Add(words[0] + " " + words[1]); lineNum++; if (sFirst && sLast) { Name n = names.Find(name => name.First.Equals(words[0]) && name.Last.Equals(words[1])); if (n == null) { markedLines += "Entry " + lineNum + ": \"" + regLines[regLines.Count - 1] + "\" name is not registered." + "\n"; } } else { if (!sFirst) { markedLines += "Entry " + lineNum + ": \"" + words[0] + "\" is incorrectly spelled. " + FindSomeSuggestions(words[0]) + "\n"; } if (!sLast) { markedLines += "Entry " + lineNum + ": \"" + words[1] + "\" is incorrectly spelled. " + FindSomeSuggestions(words[1]) + "\n"; } } } else { return(new SpellingResult("Error on entry " + i + ". Name must be two words.")); } } i++; } return(new SpellingResult(regLines.ToArray(), markedLines)); }
private void AnalyzeName(string text, WordNetEngine.POS pOS) { if (text.Length < 2) { throw new Exception("Length is less than 2 char"); } Spelling oSpell = new Spelling(); var words = Regex.Split(text, @"([A-Z _][a-z]+)"); foreach (var word in words.Where(c => !string.IsNullOrEmpty(c) && c != "_")) { if (!oSpell.TestWord(word)) { throw new Exception("FieldName Is not a Valid Word"); } if (pOS == WordNetEngine.POS.Noun) { SynSet token = WordNetEngine.GetMostCommonSynSet(word, pOS); if (token == null) { throw new Exception("FieldName Is Not A Valid noun"); } } } if (pOS == WordNetEngine.POS.Verb) { var word = string.Join(" ", words.Where <string>(c => c.Length > 0)); SynSet token = WordNetEngine.GetMostCommonSynSet(word, pOS); if (token == null) { throw new Exception("MethodName Is Not A Valid Verb"); } } }
public void FindWord(string text) { bool wordFound = false; string foundText = ""; Spelling oSpell = new Spelling(); for (int key = 1; key <= 95; key++) { string textToTest = Decrypt(text, key); string[] words = textToTest.Split(' '); foreach (string word in words) { if (oSpell.TestWord(word)) { wordFound = true; foundText = textToTest; break; } } } Console.WriteLine(wordFound ? foundText : "Kein Wort gefunden!"); }
static void Main(string[] args) { //char[] arr = { 'A', 'C', 'T', 'P' }; Console.WriteLine("Enter the word"); string input = Console.ReadLine(); char[] arr = input.ToCharArray(); // int r = 2; int n = arr.Length; for (int i = 3; i <= n; i++) { Console.WriteLine("Printing words with {0} characters", i); printCombination(arr, n, i); // permute(arr, 0, i); } Console.WriteLine("Printing all strings"); foreach (var item in output) { Console.WriteLine("For {0}, possible permutations", item); //if (item.Length > 1) permute(item.ToCharArray(), 0, item.Length - 1); } WordDictionary oDict = new WordDictionary(); oDict.DictionaryFile = "en-US.dic"; oDict.Initialize(); // string wordToCheck = "door"; Spelling oSpell = new Spelling(); oSpell.Dictionary = oDict; foreach (var item in output1) { // Console.WriteLine(item); if (oSpell.TestWord(item)) { output2.Add(item); Console.WriteLine("Word {0} is a valid english word", item); } } Console.WriteLine("\n\n Final output is ===================== "); var distinctList = output2.Distinct().ToList(); foreach (var item in distinctList) { Console.WriteLine(item); } Console.ReadLine(); }
static bool SpellCheck(string word) { WordDictionary dictionary = new WordDictionary(); dictionary.DictionaryFile = "en-US.dic"; dictionary.Initialize(); Spelling spelling = new Spelling(); spelling.Dictionary = dictionary; return(spelling.TestWord(word)); }
/* * Returner true om det er 45% sjanse for at tittelen er engelsk. * Dette kan justeres, men må testes grundigere. */ public bool isEnglish(List <string> tokenizedTitle, Spelling spelling) { Int32 wordCount = 0; Int32 length = tokenizedTitle.Count; Int32 percentage = 0; foreach (var words in tokenizedTitle) { if (spelling.TestWord(words)) { ++wordCount; percentage = (int)(0.5f + ((100f * wordCount) / length)); } } return(percentage > 51 ? true : false); }
private void CheckIfWordInDictionary(string currentString, int currentScore, int toBeAddedTile, ArrayList usedTiles, int sizeYet) { if (usedTiles.Contains(toBeAddedTile)) { return; } currentString += tiles[toBeAddedTile]; currentScore += scores[toBeAddedTile]; if (++sizeYet >= minWordSize && spellChecker.TestWord(currentString)) { //txtWords.AppendText(currentString + "\n"); //save in list to prevent duplicates lstAllWords.Add(new Word(currentString, currentScore)); //if (lstAllWords.Count % 100 == 0) //{ // lstbWords.DataSource = lstAllWords; //} } if (sizeYet + 1 > maxWordSize) { return; } usedTiles.Add(toBeAddedTile); foreach (int neighbour in neighbours[toBeAddedTile]) { //check if there is hope for new word with current substring if (allSubstringsDictionary.Contains(currentString)) { CheckIfWordInDictionary(currentString, currentScore, neighbour, usedTiles, sizeYet); } } usedTiles.Remove(toBeAddedTile); }
static void Main(string[] args) { Console.WriteLine("Hello"); WordDictionary oDict = new WordDictionary(); oDict.DictionaryFile = "en-US.dic"; oDict.Initialize(); string wordToCheck = "door"; Spelling oSpell = new Spelling(); oSpell.Dictionary = oDict; if (!oSpell.TestWord(wordToCheck)) { Console.WriteLine("Word does not exist"); } else { Console.WriteLine("Word exists"); } Console.ReadLine(); }
private void SpellCheckContextMenuOpening(object sender, CancelEventArgs e) { TextBox.Focus(); SpellCheckContextMenu.Items.Clear(); try { var pos = TextBox.GetCharIndexFromPosition(TextBox.PointToClient(MousePosition)); if (pos < 0) { e.Cancel = true; return; } _spelling.Text = TextBox.Text; _spelling.WordIndex = _spelling.GetWordIndexFromTextIndex(pos); if (_spelling.CurrentWord.Length != 0 && !_spelling.TestWord()) { _spelling.ShowDialog = false; _spelling.MaxSuggestions = 5; //generate suggestions _spelling.Suggest(); foreach (var suggestion in _spelling.Suggestions) { var si = AddContextMenuItem(suggestion, SuggestionToolStripItemClick); si.Font = new System.Drawing.Font(si.Font, FontStyle.Bold); } AddContextMenuItem(addToDictionaryText.Text, AddToDictionaryClick) .Enabled = (_spelling.CurrentWord.Length > 0); AddContextMenuItem(ignoreWordText.Text, IgnoreWordClick) .Enabled = (_spelling.CurrentWord.Length > 0); AddContextMenuItem(removeWordText.Text, RemoveWordClick) .Enabled = (_spelling.CurrentWord.Length > 0); if (_spelling.Suggestions.Count > 0) { AddContextMenuSeparator(); } } } catch (Exception ex) { Trace.WriteLine(ex); } AddContextMenuItem(cutMenuItemText.Text, CutMenuItemClick) .Enabled = (TextBox.SelectedText.Length > 0); AddContextMenuItem(copyMenuItemText.Text, CopyMenuItemdClick) .Enabled = (TextBox.SelectedText.Length > 0); AddContextMenuItem(pasteMenuItemText.Text, PasteMenuItemClick) .Enabled = Clipboard.ContainsText(); AddContextMenuItem(deleteMenuItemText.Text, DeleteMenuItemClick) .Enabled = (TextBox.SelectedText.Length > 0); AddContextMenuItem(selectAllMenuItemText.Text, SelectAllMenuItemClick); /*AddContextMenuSeparator(); * * if (!string.IsNullOrEmpty(_spelling.CurrentWord)) * { * string text = string.Format(translateCurrentWord.Text, _spelling.CurrentWord, CultureCodeToString(Settings.Dictionary)); * AddContextMenuItem(text, translate_Click); * } * * string entireText = string.Format(translateEntireText.Text, CultureCodeToString(Settings.Dictionary)); * AddContextMenuItem(entireText, translateText_Click);*/ AddContextMenuSeparator(); try { var dictionaryToolStripMenuItem = new ToolStripMenuItem(dictionaryText.Text); SpellCheckContextMenu.Items.Add(dictionaryToolStripMenuItem); var toolStripDropDown = new ContextMenuStrip(); var noDicToolStripMenuItem = new ToolStripMenuItem("None"); noDicToolStripMenuItem.Click += DicToolStripMenuItemClick; if (Settings.Dictionary == "None") { noDicToolStripMenuItem.Checked = true; } toolStripDropDown.Items.Add(noDicToolStripMenuItem); foreach ( var fileName in Directory.GetFiles(AppSettings.GetDictionaryDir(), "*.dic", SearchOption.TopDirectoryOnly)) { var file = new FileInfo(fileName); var dic = file.Name.Replace(".dic", ""); var dicToolStripMenuItem = new ToolStripMenuItem(dic); dicToolStripMenuItem.Click += DicToolStripMenuItemClick; if (Settings.Dictionary == dic) { dicToolStripMenuItem.Checked = true; } toolStripDropDown.Items.Add(dicToolStripMenuItem); } dictionaryToolStripMenuItem.DropDown = toolStripDropDown; } catch (Exception ex) { Trace.WriteLine(ex); } AddContextMenuSeparator(); var mi = new ToolStripMenuItem(markIllFormedLinesText.Text) { Checked = AppSettings.MarkIllFormedLinesInCommitMsg }; mi.Click += MarkIllFormedLinesInCommitMsgClick; SpellCheckContextMenu.Items.Add(mi); }
public bool CheckSpelling(string word) { return(_spellChecker.TestWord(word) || _anagrams.Contains(word)); }
/// <summary> /// Checks the spelling of all name pairs in a text string. /// The names are separated by the line delimiter set in the constructor. /// Mispelled names are noted and given suggestions for fixes /// </summary> /// <returns>A <seealso cref="SpellingResult"/> that contains the editted original lines and the errors reported</returns> public SpellingResult CheckSpelling(string text) { string[] lines = text.Split(lineDelim); //lines the user put in, to be editted for captitalization string[] userLines = new string[lines.Length]; //lines that mark errors in spelling and name pairing string[] markedLines = new string[lines.Length]; for (int i = 0; i < lines.Length; i++) { if (lines[i].Length == 0) { //skip blank lines userLines[i] = ""; markedLines[i] = ""; continue; } //parse a name from the line Name parsed = Name.Parse(lines[i]); if (parsed != null) { //correct any user capitalization mistakes userLines[i] = parsed.ToString(); //check the spelling of each name bool sFirst = spellCheck.TestWord(parsed.First); bool sLast = spellCheck.TestWord(parsed.Last); //both correct if (sFirst && sLast) { //see if the name is a registered name pairing Name matchedName = registeredPairs.Find(n => n.IsSame(parsed)); //name pair not registered, but names spelled correctly if (matchedName == null) { markedLines[i] = "Error: \"" + parsed + "\" is not registered name pair."; } else { //all good! markedLines[i] = ""; } } else if (!sFirst && !sLast) { //both mispelled markedLines[i] = "Error: Both \"" + parsed.First + "\" and \"" + parsed.Last + "\" are unregistered names. " + FindSomeSuggestions(parsed.First, parsed.Last); } else if (!sFirst) { //first is bad markedLines[i] = "Error: \"" + parsed.First + "\" is not a registered first name. " + FindSomeSuggestions(parsed.First); } else { //last is bad markedLines[i] = "Error: \"" + parsed.Last + "\" is not a registered last name. " + FindSomeSuggestions(parsed.Last); } } else { //no name could be parsed, too long or too short throw new SpellCheckException("Error with input: \"" + lines[i] + "\". Each name must be from 2 to 4 words. If this is an issue, contact me to fix it."); } } return(new SpellingResult(string.Join("\n", userLines), string.Join("\n", markedLines))); }
private XmlDocument CreateServerXmlDocumentResponse(string action, string text) { Regex _wordEx, _htmlEx; XmlDocument result = new XmlDocument(); result.PreserveWhitespace = true; XmlDeclaration xmlDecl = result.CreateXmlDeclaration("1.0", "utf-8", ""); result.AppendChild(xmlDecl); XmlElement webmailNode = result.CreateElement("webmail"); result.AppendChild(webmailNode); XmlElement spellcheckNode = result.CreateElement("spellcheck"); webmailNode.AppendChild(spellcheckNode); if (action == "spell") { spellcheckNode.SetAttribute("action", "spellcheck"); _htmlEx = new Regex(@"(<.*?\>)|(&[^;]{1,5};)", RegexOptions.IgnoreCase & RegexOptions.Compiled); text = _htmlEx.Replace(text, ReplaceHtml); Log.WriteLine("", ">>>>>>>>>>>>>>>> TEXT >>>>>>>>>>>>>>>>"); Log.WriteLine("", text); Log.WriteLine("", ">>>>>>>>>>>>>>>> TEXT >>>>>>>>>>>>>>>>"); _wordEx = new Regex(@"\b[" + WordDictionary.TryCharacters + @"']+\b", RegexOptions.Compiled); MatchCollection words = _wordEx.Matches(text); foreach (Match word in words) { if (!SpellChecker.TestWord(word.ToString())) { XmlElement node = result.CreateElement("misp"); spellcheckNode.AppendChild(node); node.SetAttribute("pos", word.Index.ToString()); node.SetAttribute("len", word.Length.ToString()); } } } else if (action == "suggest") { spellcheckNode.SetAttribute("action", "suggest"); SpellChecker.Suggest(text); int i = 0; foreach (string word in SpellChecker.Suggestions) { if (i++ < MAX_SUGGESTIONS) { XmlElement node = result.CreateElement("word"); spellcheckNode.AppendChild(node); //node.SetAttribute("name", "word"); node.AppendChild(webmailNode.OwnerDocument.CreateCDataSection(Utils.EncodeCDATABody(word))); //node.SetAttribute("value", word); } } } return(result); }