Exemple #1
0
        public void IgnoreTest()
        {
            var spell = new SpellChecker();

            var examples = spell.Check("codez");

            Assert.IsTrue(examples.Any());

            spell.Ignore("codez");

            examples = spell.Check("codez");

            Assert.AreEqual(examples.Count(), 0);
        }
Exemple #2
0
 public void Check()
 {
     for (int i = 0; i < _words.Count; i++)
     {
         _kurdspell.Check(_words[i]);
     }
 }
Exemple #3
0
        public void CheckSpelling(string content)
        {
            if (_box.IsSpellCheckEnabled)
            {
                ClearLists();

                var matches = Regex.Matches(content, @"\w+[^\s]*\w+|\w");

                foreach (Match match in matches)
                {
                    Words.Add(new Word(match.Value.Trim(), match.Index));
                }

                foreach (var word in Words)
                {
                    bool isIgnored = IgnoredWords.Contains(word);
                    if (!isIgnored)
                    {
                        bool exists = _spellChecker.Check(word.Text);
                        if (exists)
                        {
                            IgnoredWords.Add(word);
                        }
                        else
                        {
                            MisspelledWords.Add(word);
                        }
                    }
                }

                OnPropertyChanged("MisspelledWords");
                OnPropertyChanged("IgnoredWords");
            }
        }
Exemple #4
0
        public void CheckSpelling(string word, bool expected)
        {
            var affixes = new List <Affix>
            {
                new Affix("0", "om", "oyn", "oyt", "on", "wat", "on"),
                new Affix("1", "im", "in", "it", "n", "et", "n"),
                new Affix("2", "m", "man", "t", "tan", "y", "yan"),
                new Affix("3", "em", "eyn", "eyt", "en", "at", "en"),
                new Affix("4", "m", "in", "a", "n", "et", "n"),
                new Affix("5", "ish", ""),
                new Affix("6", "de", ""),
            };

            var patterns = new List <Pattern>
            {
                new Pattern("dex[0]"),
                new Pattern("dekrr[1]"),
                new Pattern("supas[2]dek[3]"),
                new Pattern("m[4][5]mos"),
                new Pattern("[6]kird"),
            };

            var spellChecker = new SpellChecker(patterns, affixes);

            var actual = spellChecker.Check(word);

            Assert.Equal(expected, actual);
        }
Exemple #5
0
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            if (IsSpellCheckEnabled && wordTypedCompleted && !string.IsNullOrEmpty(Text))
            {
                var spellingErrors = spellChecker.Check(Document.EntireRange.Text);

                if (spellingErrors.Any())
                {
                    hasSpellingErrors = true;

                    foreach (var spellingError in spellingErrors)
                    {
                        var range          = Document.GetRange(spellingError.StartIndex, spellingError.StartIndex + spellingError.Length);
                        var misspelledWord = range.Text;
                        misspelledWords.Add(misspelledWord);

                        if (!ranges.ContainsKey(misspelledWord))
                        {
                            ranges.Add(misspelledWord, range);
                        }
                        var font = range.Font;
                        font.Reset((int)tomConstants.tomApplyTmp);
                        font.Underline = (int)UnderlineStyle.Wave;
                        font.Underline = unchecked ((int)0xFF0000FF); //red color
                        font.Reset((int)tomConstants.tomApplyNow);
                    }
                }
            }
        }
        protected void SpellCheck_Click(object sender, EventArgs e)
        {
            List <string> invalidWords = new List <string>();
            SpellChecker  sc           = new SpellChecker();

            string  sql     = String.Format("select * from Chapters where ID= {0}", Page.RouteData.Values["ID"].ToString());
            DataSet data    = connector.query(sql);
            string  content = data.Tables[0].Rows[0]["Content"].ToString();

            string[] words = splitter.split(content);

            foreach (string word in words)
            {
                if (!sc.Check(word))
                {
                    invalidWords.Add(word);
                }
            }

            System.IO.File.WriteAllLines(@"E:\invalid_words.txt", invalidWords);

            foreach (string word in invalidWords)
            {
                content = highlighter.highlight(content, word);
            }
            ChapterContent.Text = content;
            InvalidCount.Text   = String.Format("{0} lỗi", invalidWords.Count);
            //InvalidCount.Text = String.Join("...", invalidWords.ToArray());
            //InvalidCount.Text = words.Length.ToString();
        }
        void CheckCell(int rowIndex, int columnIndex)
        {
            GridColumn column = grid.Columns[columnIndex];

            if (column.IsGrouped)
            {
                return;
            }
            grid.CurrentColumn         = column;
            grid.View.FocusedRowHandle = rowIndex;
            grid.View.ShowEditor();
            grid.UpdateLayout();

            BaseEdit activeEditor = grid.View.ActiveEditor;

            if (activeEditor == null || !SpellChecker.CanCheck(activeEditor))
            {
                CheckNextCell();
            }
            else
            {
                UnsubscribeFromEvents();
                SpellChecker.CheckCompleteFormShowing += new DevExpress.XtraSpellChecker.FormShowingEventHandler(Checker_CheckCompleteFormShowing);
                SpellChecker.AfterCheck += Checker_AfterCheck;
                SpellChecker.Check(activeEditor);
            }
        }
Exemple #8
0
 public static void csSpellCheck(this TextBox tb, SpellChecker spellChecker)
 {
     spellChecker.SpellCheckMode = SpellCheckMode.AsYouType;
     spellChecker.CheckAsYouTypeOptions.Color = Color.Magenta;
     spellChecker.Check(tb);
     spellChecker.SetShowSpellCheckMenu(tb, true);
 }
Exemple #9
0
        public void CheckSpellingKurdish(string word, bool expected)
        {
            var affixes = new List <Affix>
            {
                new Affix("0", new string[] { "م", "مان", "ت", "تان", "ی", "یان", "" }),
                new Affix("1", new string[] { "م", "ین", "ە", "ن", "ێت", "ن" }),
                new Affix("2", new string[] { "ۆم", "ۆین", "ۆیت", "ۆن", "وات", "ۆن" }),
                new Affix("3", new string[] { "م", "ین", "ت", "ن", "ێت", "ن" }),
                new Affix("4", new string[] { "یەکە", "یەک", "یەکان", "یان", "" }),
                new Affix("5", new string[] { "یش", "ێک", "" }),
                new Affix("6", new string[] { "وە", "ووە", "" }),
                new Affix("7", new string[] { "م", "مان", "ت", "تان", "ی", "یان", "", "ە" }),
            };

            var patterns = new List <Pattern>
            {
                new Pattern("دوور[0]"),
                new Pattern("مامۆستا[4][0][5]"),
                new Pattern("دە[7]تانی")
            };

            var spellChecker = new SpellChecker(patterns, affixes);

            var actual = spellChecker.Check(word);

            Assert.Equal(expected, actual);
        }
Exemple #10
0
 void CheckActiveEditor(BaseEdit activeEditor)
 {
     activeEditor.Dispatcher.BeginInvoke(new Action(() =>
     {
         if (SpellChecker.CanCheck(activeEditor))
         {
             SpellChecker.Check(activeEditor);
         }
     }), DispatcherPriority.Loaded);
 }
Exemple #11
0
        public void IgnoreTest()
        {
            // ReSharper disable once StringLiteralTypo
            // ReSharper disable IdentifierTypo
            const string codez = "codez";

            using var spell = new SpellChecker();
            var examples = spell.Check(codez);

            Assert.IsTrue(examples.Any());

            spell.Ignore(codez);

            examples = spell.Check(codez);

            Assert.AreEqual(examples.Count(), 0);

            // ReSharper restore IdentifierTypo
        }
Exemple #12
0
        private void gridViewTranslation_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
        {
            RadTextBoxEditor editor = e.ActiveEditor as RadTextBoxEditor;

            if (editor != null)
            {
                RadTextBoxEditorElement element = editor.EditorElement as RadTextBoxEditorElement;
                SpellChecker.Check(element.TextBoxItem.HostedControl);
                correctedValue = e.ActiveEditor.Value.ToString();
            }
        }
Exemple #13
0
        public void Graded_SpellCheckTest()//Grade:E1.3:30
        {
            SpellChecker spellChecker = new SpellChecker(FastLM);

            Validator("Q4", (inFile, outFile) =>
            {
                var word = File.ReadAllText(inFile);
                var expectedCandidates = File.ReadAllLines(outFile);
                var actualCandidates   = spellChecker.Check(word);

                CollectionAssert.AreEqual(
                    expectedCandidates,
                    actualCandidates);
            });
        }
Exemple #14
0
        public void CheckTest()
        {
            using (var spellChecker = new SpellChecker())
            {
                var text = "Hola me yamo Max. Estudio en la univercidad Continental.";

                var results = spellChecker.Check(text).ToList();

                Assert.AreEqual(2, results.Count);

                var firstError = results[0];

                Assert.AreEqual(8, firstError.StartIndex);
                Assert.AreEqual(4, firstError.Length);
                Assert.AreEqual(CorrectiveAction.GetSuggestions, firstError.CorrectiveAction);
                Assert.AreEqual(string.Empty, firstError.Replacement);
            }
        }
Exemple #15
0
        public void CheckTest()
        {
            using var spell = new SpellChecker("en-us");
            var examples = spell.Check("foxx or recieve").ToList();

            Assert.AreEqual(examples.Count(), 2);

            var firstError = examples[0];

            Assert.AreEqual(firstError.StartIndex, 0);
            Assert.AreEqual(firstError.Length, 4);
            Assert.AreEqual(firstError.RecommendedAction, RecommendedAction.GetSuggestions);
            Assert.AreEqual(firstError.RecommendedReplacement, string.Empty);

            var secondError = examples[1];

            Assert.AreEqual(secondError.StartIndex, 8);
            Assert.AreEqual(secondError.Length, 7);
            Assert.AreEqual(secondError.RecommendedAction, RecommendedAction.Replace);
            Assert.AreEqual(secondError.RecommendedReplacement, "receive");
        }
        public void CheckTest()
        {
            var spell = new SpellChecker("en-us");

            var examples = spell.Check("foxx or recieve").ToList();

            Assert.AreEqual(examples.Count(), 2);

            var firstError = examples[0];

            Assert.AreEqual(firstError.StartIndex, 0);
            Assert.AreEqual(firstError.Length, 4);
            Assert.AreEqual(firstError.RecommendedAction, RecommendedAction.GetSuggestions);
            Assert.AreEqual(firstError.RecommendedReplacement, string.Empty);

            var secondError = examples[1];

            Assert.AreEqual(secondError.StartIndex, 8);
            Assert.AreEqual(secondError.Length, 7);
            Assert.AreEqual(secondError.RecommendedAction, RecommendedAction.Replace);
            Assert.AreEqual(secondError.RecommendedReplacement, "receive");
        }
        public MistakesListViewModel(IDocumentService documentService, SpellChecker spellChecker)
        {
            _documentService = documentService;
            _spellChecker    = spellChecker;

            FindMistakesCommand = new DelegateCommand(_ =>
            {
                Mistakes.Clear();
                var words = _documentService.GetAllWords().ToList();
                foreach (var word in words)
                {
                    if (string.IsNullOrWhiteSpace(word.Literal))
                    {
                        continue;
                    }

                    if (_spellChecker.Check(word.Literal) == false)
                    {
                        var mistake = new MistakeViewModel
                        {
                            Start = word.Start,
                            End   = word.End,
                            Text  = word.Literal
                        };

                        mistake.Suggestions = _spellChecker.Suggest(word.Literal, 3)
                                              .Select(i => new SuggestionViewModel(mistake, i))
                                              .ToList();

                        Mistakes.Add(mistake);
                    }
                }
            });

            ApplyFixCommand = new DelegateCommand(p =>
            {
                var fix = p as SuggestionViewModel;
                if (fix is null)
                {
                    return;
                }

                Mistakes.Remove(fix.Parent);
                var word = _documentService.Replace(fix.Parent.Start, fix.Parent.End, fix.Text);
                _documentService.Select(word);
                var delta = fix.Parent.Text.Length - fix.Text.Length;

                foreach (var mistake in Mistakes.Where(m => m.Start > fix.Parent.Start))
                {
                    mistake.Start -= delta;
                    mistake.End   -= delta;
                }
            });

            AddToDictionaryCommand = new DelegateCommand(p =>
            {
                var mistake = p as MistakeViewModel;
                if (mistake is null)
                {
                    return;
                }

                for (int i = Mistakes.Count - 1; i >= 0; i--)
                {
                    if (Mistakes[i].Text == mistake.Text)
                    {
                        Mistakes.Remove(Mistakes[i]);
                    }
                }

                _spellChecker.AddToDictionary(mistake.Text);
            });
        }
Exemple #18
0
 bool ShouldWordBeMarkedAsMisspelled(ParsedTextSpan part) => part.IsWord && !SpellChecker.Check(part.Text);
Exemple #19
0
 public bool Check(string word)
 => _isvalidCache.GetOrAdd(word, w => _spellchecker.Check(w));
 void btnCheckSpelling_Click(object sender, RoutedEventArgs e)
 {
     spellChecker.Check(richEdit);
 }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     // Start checking the text within a text edit control.
     checker.Check(textEdit1);
 }
        public void IgnoreTest()
        {
            var spell = new SpellChecker();

            var examples = spell.Check("codez");

            Assert.IsTrue(examples.Any());

            spell.Ignore("codez");

            examples = spell.Check("codez");

            Assert.AreEqual(examples.Count(), 0);
        }
Exemple #23
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     // Call the spell checker to inspect the text box.
     checker.Check(textEdit);
 }
 void Button_Click(object sender, RoutedEventArgs e)
 {
     SpellChecker.Check(richEdit);
 }
        private async Task GenerateFromSolutionCodeAsync(DirectoryInfo directory, FileInfo outputFile)
        {
            var wordBag    = new Dictionary <string, bool>();
            var seperators = new char[] { ' ', '\r', '\n', '>', '<', '.', ';', '?' };
            var wordRegex  = new Regex(@"([A-Za-z]+)", RegexOptions.Compiled);
            var caseRegex  = new Regex(@"(?<=[A-Za-z])(?=[A-Z][a-z])|(?<=[a-z0-9])(?=[0-9]?[A-Z])", RegexOptions.Compiled);

            var spell = new SpellChecker("en-us");

            var count = 0;

            foreach (var file in directory.EnumerateFiles("*.cs", SearchOption.AllDirectories))
            {
                var text    = File.ReadAllText(file.FullName);
                var matches = wordRegex.Matches(text);
                foreach (Match match in matches)
                {
                    var words         = caseRegex.Replace(match.Value, " ");
                    var splittedwords = words.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var word in splittedwords)
                    {
                        var w = word.ToLower(CultureInfo.InvariantCulture);
                        if (!wordBag.ContainsKey(w))
                        {
                            count++;
                            var hasError = spell.Check(w).Any();
                            if (hasError)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }
                            Console.WriteLine($"[{count.ToString().PadLeft(5, ' ')}] {word.PadRight(32, ' ')} {file.Name}");
                            Console.ResetColor();
                            wordBag[w] = !hasError;
                        }
                    }
                }
            }

            var builder = new StringBuilder();

            builder.AppendLine($"Label\tValue");
            foreach (var word in wordBag)
            {
                //var formatted = Format(word.Key, 10);
                //if (string.IsNullOrWhiteSpace(formatted))
                //{
                //    continue;
                //}
                builder.AppendLine($"{(word.Value ? "1" : "0")}\t{word.Key}");
            }

            File.WriteAllText(outputFile.FullName, builder.ToString());

            var spellBuilder = new StringBuilder();

            foreach (var word in wordBag)
            {
                spellBuilder.AppendLine(word.Key);
            }

            File.WriteAllText(Path.Combine(outputFile.DirectoryName, "spell-" + outputFile.Name), spellBuilder.ToString());
        }
Exemple #26
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     SpellChecker.Check(textEdit);
 }