Пример #1
0
        public void removeRepeatedLetters(Token token)
        {
            cutOutRepeatedLetters(token, out List <int> firstIndexesOfRepeatSections);

            if (!hunspell.Spell(token.text))
            {
                string text         = token.text;
                string analysedWord = findEnglishWordFromRepeatedLetters(text, firstIndexesOfRepeatSections);
                if (analysedWord != null)
                {
                    token.text = analysedWord;
                }
            }
        }
 public void Benchmark(BenchmarkContext context)
 {
     foreach (var word in Words)
     {
         var result = Checker.Spell(word);
         WordsChecked.Increment();
     }
 }
Пример #3
0
 public void Benchmark(BenchmarkContext context)
 {
     foreach (var filePair in TestFiles)
     {
         var checker = new NHunspell.Hunspell(filePair.DictionaryFilePath, filePair.AffixFilePath);
         checker.Spell(TestWord);
         FilePairsLoaded.Increment();
     }
 }
Пример #4
0
        /// <summary>
        /// Spells the specified word.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <returns>
        /// <b>True</b> if word is correct; otherwise, <b>false</b>.
        /// </returns>
        public bool Spell(string word)
        {
            // if spell check engine is not enabled
            if (!IsEnabled)
            {
                return(false);
            }

            return(_hunspell.Spell(word));
        }
Пример #5
0
        public ActionResult MemberKeywords(string term)
        {
            List <string> Names =
                _db.Members
                .Where(x => x.Name.Contains(term))
                .Select(x => x.Name.ToLower())
                .Distinct()
                .ToList();

            var spelling    = new NHunspell.Hunspell("en_US.aff", "en_US.dic");
            var suggestions =
                spelling.Spell(term) ?
                new List <string>()
            {
                term
            } :
            spelling.Suggest(term).Take(5);

            var results = suggestions.Union(Names);

            return(Json(results, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
 public override bool Spell(string word)
 {
     return(_hunspell.Spell(word));
 }
        public JsonResult spellCheckTD(List<TableCellsViewModel> tableCells)
        {
            var incorrectCells = new List<TableCellsViewModel>();

            foreach (var tableCell in tableCells)
            {
                var isIncorrectCell = false;
                var incorrectCell = new TableCellsViewModel();
                var returnText = "";

                var value = tableCell.Value ?? "";
                Regex r = new Regex("^[a-zA-Z]*$");

                using (NHunspell.Hunspell hunspell = new NHunspell.Hunspell(this.HttpContext.ApplicationInstance.Server.MapPath("~/App_Data/en_us.aff"), this.HttpContext.ApplicationInstance.Server.MapPath("~/App_Data/en_us.dic")))
                {
                    var words = value.Split(' ');
                    foreach (var word in words)
                    {
                        var returnWord = word + " ";
                        var chkWord = word;
                        chkWord = chkWord.Replace("(", "");
                        chkWord = chkWord.Replace(")", "");
                        chkWord = chkWord.Replace("*", "");
                        chkWord = chkWord.Replace("/", "");
                        chkWord = chkWord.Replace("\\", "");
                        if (r.IsMatch(chkWord))
                        {
                            if (!hunspell.Spell(chkWord))
                            {
                                if (db.Words.Where(x => x.Word == chkWord).Count() == 0)
                                {
                                    if (!IsAllUpper(chkWord))
                                    {
                                        //correct = false;
                                        incorrectCell.Field = tableCell.Field;
                                        incorrectCell.Indicator_ID = tableCell.Indicator_ID;
                                        returnWord = "<span class='misspell'>" + returnWord + "</span>" + " ";
                                        returnText += returnWord;
                                        returnWord = "";
                                        isIncorrectCell = true;
                                    }
                                }
                            }
                        }
                        returnText += returnWord;
                        incorrectCell.Value = returnText;
                    }
                }
                if (isIncorrectCell) incorrectCells.Add(incorrectCell);
            }
            return Json(incorrectCells);
        }
Пример #8
0
        private void textEditor_StyleNeeded(object sender, StyleNeededEventArgs e)
        {
            // Calculate folding

            int startLine = textEditor.LineFromPosition(textEditor.CharPositionFromPoint(0, 0));

            if (startLine > 0)
            {
                startLine -= 1;
            }
            int currentFoldLevel = 1048;

            if (startLine != 0)
            {
                currentFoldLevel = textEditor.Lines[startLine].FoldLevel;
            }

            var endLine     = textEditor.Lines.Count;
            var currentLine = startLine;

            while (currentLine < endLine)
            {
                var line       = textEditor.Lines[currentLine];
                var headerSize = CountHashes(line.Text);

                if (headerSize > 0)
                {
                    line.FoldLevelFlags = FoldLevelFlags.Header;
                    line.FoldLevel      = 1048 - headerSize - 1;
                    currentFoldLevel    = 1048 - headerSize;
                }
                else
                {
                    line.FoldLevelFlags = 0;
                    line.FoldLevel      = currentFoldLevel;
                }

                // Style line.
                textEditor.StartStyling(line.Position);
                textEditor.SetStyling(line.Length, 0);

                // Search line for brackets and style between them.
                var bracketPos = line.Text.IndexOf('[');
                while (bracketPos != -1)
                {
                    var end = line.Text.IndexOf(']', bracketPos);
                    if (end != -1)
                    {
                        textEditor.StartStyling(line.Position + bracketPos);
                        textEditor.SetStyling(end - bracketPos + 1, 1);

                        bracketPos = line.Text.IndexOf('[', end);
                    }
                    else
                    {
                        bracketPos = -1;
                    }
                }

                // Finally, check for spelling.

                // Clear any existing squiggles.
                textEditor.IndicatorCurrent = 1;
                textEditor.IndicatorClearRange(line.Position, line.EndPosition - line.Position);

                // Find all words in line.
                var startPos = FindWordStart(line.Text, 0);
                while (startPos < line.Length)
                {
                    var end = FindWordEnd(line.Text, startPos);
                    // Style between startPos and end
                    var word            = line.Text.Substring(startPos, end - startPos);
                    var spellingResults = SpellChecker.Spell(word);
                    if (!spellingResults)
                    {
                        textEditor.IndicatorFillRange(line.Position + startPos, end - startPos);
                    }

                    startPos = FindWordStart(line.Text, end);
                }

                currentLine += 1;
            }
        }
Пример #9
0
        private void textEditor_StyleNeeded(object sender, StyleNeededEventArgs e)
        {
            // Calculate folding

            int startLine = LineFromPosition(CharPositionFromPoint(0, 0));

            if (startLine > 0)
            {
                startLine -= 1;
            }
            int currentFoldLevel = 1048;

            if (startLine != 0)
            {
                currentFoldLevel = Lines[startLine].FoldLevel;
            }

            var endLine     = startLine + 25;
            var currentLine = startLine;

            while (currentLine < endLine && currentLine < Lines.Count)
            {
                var line       = Lines[currentLine];
                var headerSize = CountHashes(line.Text);

                if (headerSize > 0)
                {
                    line.FoldLevelFlags = FoldLevelFlags.Header;
                    line.FoldLevel      = 1048 - headerSize - 1;
                    currentFoldLevel    = 1048 - headerSize;
                }
                else
                {
                    line.FoldLevelFlags = 0;
                    line.FoldLevel      = currentFoldLevel;
                }

                // Style line.
                StartStyling(line.Position);
                SetStyling(line.Length, 0);

                var bracketPos = line.Text.IndexOf('/');
                while (bracketPos != -1)
                {
                    var end = line.Text.IndexOf('/', bracketPos + 1);
                    if (end != -1)
                    {
                        StartStyling(line.Position + bracketPos);
                        SetStyling(end - bracketPos + 1, 1);

                        bracketPos = line.Text.IndexOf('/', end + 1);
                    }
                    else
                    {
                        bracketPos = -1;
                    }
                }

                // Search line for brackets and style between them.
                bracketPos = line.Text.IndexOf('[');
                while (bracketPos != -1)
                {
                    var end = line.Text.IndexOf(']', bracketPos);
                    if (end != -1)
                    {
                        StartStyling(line.Position + bracketPos);
                        SetStyling(end - bracketPos + 1, 2);

                        bracketPos = line.Text.IndexOf('[', end);
                    }
                    else
                    {
                        bracketPos = -1;
                    }
                }

                //// Search line for brackets and style between them.
                //bracketPos = line.Text.IndexOf('<');
                //while (bracketPos != -1)
                //{
                //    var end = line.Text.IndexOf('>', bracketPos);
                //    if (end != -1)
                //    {
                //        StartStyling(line.Position + bracketPos);
                //        SetStyling(end - bracketPos + 1, 1);

                //        bracketPos = line.Text.IndexOf('<', end);
                //    }
                //    else
                //        bracketPos = -1;
                //}

                // Finally, check for spelling.

                // Clear any existing squiggles.
                IndicatorCurrent = 1;
                IndicatorClearRange(line.Position, line.EndPosition - line.Position);

                if (SpellChecker != null)
                {
                    // Find all words in line.
                    var startPos = FindWordStart(line.Text, 0);
                    while (startPos < line.Length)
                    {
                        var end = FindWordEnd(line.Text, startPos);
                        // Style between startPos and end
                        var word = line.Text.Substring(startPos, end - startPos);

                        var hiliteWord = Settings.GlobalSettings.SpecialWords.FirstOrDefault(h => h.Word == word.ToUpper());
                        if (hiliteWord != null)
                        {
                            StartStyling(line.Position + startPos);
                            SetStyling(end - startPos, hiliteWord.Style);
                        }

                        var spellingResults = SpellChecker.Spell(word);
                        if (!spellingResults)
                        {
                            IndicatorFillRange(line.Position + startPos, end - startPos);
                        }

                        startPos = FindWordStart(line.Text, end);
                    }
                }

                currentLine += 1;
            }
        }