Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NHunspellSpellCheckEngine"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if
        /// <i>language</i> is <b>null</b> or <b>empty</b>.</exception>
        public NHunspellSpellCheckEngine(string language)
        {
            // if language is not correct
            if (string.IsNullOrEmpty(language))
            {
                throw new ArgumentNullException();
            }

            // save languages
            _languages = new string[] { language };

            string affixFileDataPath = language + ".aff";

            // load affix data
            byte[] affixFileData = DemosResourcesManager.GetExternalResourceAsBytes(affixFileDataPath);


            string dictionaryFileDataPath = language + ".dic";

            // load dictionary data
            byte[] dictionaryFileData = DemosResourcesManager.GetExternalResourceAsBytes(dictionaryFileDataPath);

            // create engine
            _hunspell = new NHunspell.Hunspell(affixFileData, dictionaryFileData);

            // load available symbols of language
            InitializeAvailableSymbols(language);

            // load custom words dictionary
            LoadCustomWordsDictionary();
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_hunspell != null && !_hunspell.IsDisposed)
             _hunspell.Dispose();
         _hunspell = null;
     }
 }
Example #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();
     }
 }
Example #4
0
        /// <summary>
        /// Releases all resources used by this spell check engine.
        /// </summary>
        public void Dispose()
        {
            if (_hunspell != null)
            {
                _hunspell.Dispose();
                _hunspell = null;
            }

            SaveCustomWordsDictionary();
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_hunspell != null && !_hunspell.IsDisposed)
         {
             _hunspell.Dispose();
         }
         _hunspell = null;
     }
 }
Example #6
0
        private Hunspell(string lang)
        {
            string dotnetLang = lang.Replace("_", "-");

            hunspell  = new NHunspell.Hunspell(rootDir + "\\" + lang + ".aff", rootDir + "\\" + lang + ".dic");
            stopWords = new HashSet <string>();

            System.IO.File.ReadAllLines(rootDir + "\\" + lang + ".stopwords")
            .ToList()
            .ForEach(m => stopWords.Add(m));
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this._hunspell != null && !this._hunspell.IsDisposed)
                {
                    this._hunspell.Dispose();
                }

                this._hunspell = null;
            }
        }
        public override void Setup(BenchmarkContext context)
        {
            base.Setup(context);

            var testAssemblyPath   = Path.GetFullPath(GetType().Assembly.Location);
            var filesDirectory     = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/");
            var dictionaryFilePath = Path.Combine(filesDirectory, "English (American).dic");
            var affixFilePath      = Path.ChangeExtension(dictionaryFilePath, "aff");

            Checker = new NHunspell.Hunspell(affixFilePath, dictionaryFilePath);

            WordsChecked = context.GetCounter(nameof(WordsChecked));
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (hunspell != null && !hunspell.IsDisposed)
            {
                hunspell.Dispose();
            }

            hunspell = null;
        }
Example #10
0
        public void LoadSettings(Main View)
        {
            try
            {
                var settingsPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BleckiTreeWriter\\settings.txt";
                if (System.IO.File.Exists(settingsPath))
                {
                    var text           = System.IO.File.ReadAllText(settingsPath);
                    var settingsObject = JsonConvert.DeserializeObject <SerializableSettings>(text);

                    if (!String.IsNullOrEmpty(settingsObject.Dictionary))
                    {
                        DictionaryBase = settingsObject.Dictionary;
                    }

                    SpellChecker = new NHunspell.Hunspell(DictionaryBase + ".aff", DictionaryBase + ".dic");

                    foreach (var folder in settingsObject.OpenProjects)
                    {
                        View.ProcessControllerCommand(new Commands.OpenProject(folder));
                    }

                    foreach (var document in settingsObject.OpenDocuments)
                    {
                        var owner = OpenProjects.FirstOrDefault(p => p.Path == document.Project);
                        if (owner != null)
                        {
                            View.ProcessControllerCommand(new Commands.OpenDocument(document.Path, owner));
                        }
                    }

                    if (settingsObject.CustomDictionaryEntries != null)
                    {
                        foreach (var word in settingsObject.CustomDictionaryEntries)
                        {
                            CustomDictionaryEntries.Add(word);
                            SpellChecker.Add(word);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DictionaryBase = "en_US";

                System.Windows.Forms.MessageBox.Show("Error loading settings.", "Alert!", System.Windows.Forms.MessageBoxButtons.OK);
            }
        }
Example #11
0
        public void LoadSettings(Main View)
        {
            try
            {
                var settingsPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BleckiTreeWriter\\settings.txt";

                if (System.IO.File.Exists(settingsPath))
                {
                    var text = System.IO.File.ReadAllText(settingsPath);
                    Settings.GlobalSettings = JsonConvert.DeserializeObject <Settings>(text);
                }
            }
            catch (Exception e)
            {
                SpellChecker = new NHunspell.Hunspell("en_US.aff", "en_US.dic");
                Thesaurus    = new NHunspell.MyThes("th_en_US_new.dat");

                System.Windows.Forms.MessageBox.Show("Error loading settings.", "Alert!", System.Windows.Forms.MessageBoxButtons.OK);
            }

            if (Settings.GlobalSettings == null)
            {
                Settings.GlobalSettings = new Settings();
            }

            Settings.GlobalSettings.Verify();

            SpellChecker = new NHunspell.Hunspell(
                Settings.GlobalSettings.Dictionary + ".aff",
                Settings.GlobalSettings.Dictionary + ".dic");
            Thesaurus = new NHunspell.MyThes(Settings.GlobalSettings.Thesaurus);

            foreach (var word in Settings.GlobalSettings.CustomDictionaryEntries)
            {
                SpellChecker.Add(word);
            }


            View.UpdateRecentDocuments();
        }
Example #12
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));
        }
Example #13
0
        public TextDocumentEditor(
            EditableDocument Document,
            ScintillaNET.Document?LinkingDocument,
            NHunspell.Hunspell SpellChecker,
            NHunspell.MyThes Thesaurus)
            : base(Document)
        {
            this.SpellChecker = SpellChecker;
            this.Thesaurus    = Thesaurus;

            this.InitializeComponent();

            // Load document into editor.
            if (!LinkingDocument.HasValue)
            {
                textEditor.Text = Document.GetContents();
            }
            else
            {
                textEditor.Document = LinkingDocument.Value;
            }

            textEditor.Create(SpellChecker, Thesaurus, (a) => InvokeCommand(a));
            textEditor.CustomizeMenu = (menu) =>
            {
                if (CustomizeContextMenu != null)
                {
                    CustomizeContextMenu(menu);
                }
            };

            Text = Document.GetTitle();

            //Register last to avoid spurius events
            this.textEditor.TextChanged += new System.EventHandler(this.textEditor_TextChanged);

            ReloadSettings();
        }
		public void ProcessRequest(HttpContext context) {
			string request;
			using (System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream)) {
				// pull in the whole request that was sent to us
				request = sr.ReadToEnd();
			}
			try {
				// I had to use the DeserializeObject method to pull back an object because the JSON object
				// has a property called params which is a reserved C# keyword
				object o = Newtonsoft.Json.JsonConvert.DeserializeObject(request);
				var sp = SpellCheckBaseClass.GetObjectFromDeserializedJson(o);
				HunspellInstance = new NHunspell.Hunspell(
					context.Server.MapPath("~/HunspellDictionaries/" + sp.Language + ".aff"),
					context.Server.MapPath("~/HunspellDictionaries/" + sp.Language + ".dic"));
				SpellCheckResultsJson results = this.GetResponse(sp);
				context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(results));
			}
			catch (Exception ex) {
				// If there is an error spit back an error JSON object
				SpellCheckResultsJson errorResults = new SpellCheckResultsJson();
				errorResults.error = ex.Message;
				context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(errorResults));
			}
		}
Example #15
0
 public TokenAnalyser()
 {
     hunspell = new NHunspell.Hunspell($"{HunspellDataPath}en_us.aff", $"{HunspellDataPath}en_us.dic");
 }
Example #16
0
 public void Create(NHunspell.Hunspell SpellChecker, NHunspell.MyThes Thesaurus, Action <ICommand> ControllerCommand)
 {
     this.SpellChecker      = SpellChecker;
     this.Thesaurus         = Thesaurus;
     this.ControllerCommand = ControllerCommand;
 }
 public WindowsHunspell(string affDictionary, string dicDictionary)
 {
     _hunspell = new NHunspell.Hunspell(affDictionary, dicDictionary);
 }
 public WindowsHunspell(string affDictionary, string dicDictionary)
 {
     _hunspell = new NHunspell.Hunspell(affDictionary, dicDictionary);
 }
Example #19
0
        public DocumentEditor(Document Document, ScintillaNET.Document?LinkingDocument, NHunspell.Hunspell SpellChecker)
        {
            this.Document     = Document;
            this.SpellChecker = SpellChecker;

            InitializeComponent();

            #region Setup Folding Margins

            textEditor.Lexer = Lexer.Container;

            textEditor.SetProperty("fold", "1");
            textEditor.SetProperty("fold.compact", "1");

            // Configure a margin to display folding symbols
            textEditor.Margins[2].Type      = MarginType.Symbol;
            textEditor.Margins[2].Mask      = Marker.MaskFolders;
            textEditor.Margins[2].Sensitive = true;
            textEditor.Margins[2].Width     = 20;

            // Set colors for all folding markers
            for (int i = 25; i <= 31; i++)
            {
                textEditor.Markers[i].SetForeColor(SystemColors.ControlLightLight);
                textEditor.Markers[i].SetBackColor(SystemColors.ControlDark);
            }

            // Configure folding markers with respective symbols
            textEditor.Markers[Marker.Folder].Symbol        = MarkerSymbol.BoxPlus;
            textEditor.Markers[Marker.FolderOpen].Symbol    = MarkerSymbol.BoxMinus;
            textEditor.Markers[Marker.FolderEnd].Symbol     = MarkerSymbol.BoxPlusConnected;
            textEditor.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
            textEditor.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
            textEditor.Markers[Marker.FolderSub].Symbol     = MarkerSymbol.VLine;
            textEditor.Markers[Marker.FolderTail].Symbol    = MarkerSymbol.LCorner;

            // Enable automatic folding
            textEditor.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);

            #endregion

            textEditor.Styles[1].ForeColor = Color.Blue;
            textEditor.Styles[1].Hotspot   = true;

            textEditor.Indicators[1].Style     = IndicatorStyle.Squiggle;
            textEditor.Indicators[1].ForeColor = Color.Red;


            // Load document into editor.
            if (!LinkingDocument.HasValue)
            {
                textEditor.Text = Document.Contents;
            }
            else
            {
                textEditor.Document = LinkingDocument.Value;
            }

            UpdateTitle();

            //Register last to avoid spurius events
            this.textEditor.TextChanged += new System.EventHandler(this.textEditor_TextChanged);
        }
        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);
        }
Example #21
0
        public static bool LoadVocabulary()
        {
            string faff = FilePaths.GetReadPath(@"data\cs_CZ.aff");
            string fdic = FilePaths.GetReadPath(@"data\cs_CZ.dic");
            if (File.Exists(faff) && File.Exists(fdic))
            {
                spell = new NHunspell.Hunspell(faff, fdic);
                return true;
            }

            return false;
        }