Ejemplo n.º 1
0
 public void Start()
 {
     string dictionaryPath = Hunspell.NativeDllPath;
     spellEngine = new SpellEngine();
     LanguageConfig enConfig = new LanguageConfig();
     enConfig.LanguageCode = "en";
     enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff");
     enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic");
     enConfig.HunspellKey = "";
     enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic");
     enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat");
     spellEngine.AddLanguage(enConfig);
 }
        protected void Application_Start(object sender, EventArgs e)
        {
            string dictionaryPath = Hunspell.NativeDllPath;

            spellEngine = new SpellEngine();
            var enConfig = new LanguageConfig();
            enConfig.LanguageCode = "en";
            enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff");
            enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic");
            enConfig.HunspellKey = "";
            enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic");
            enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat");
            spellEngine.AddLanguage(enConfig);
        }
        public HunspellSpellingPlugin()
        {
            // Set up the spell engine for multi-threaded access.
            SpellEngine = new SpellEngine();

            // Assume we are disabled unless we can configure it properly.
            projectPlugin = new DisabledSpellingProjectPlugin();

            // Figure out the paths to the dictionary files. For the time being,
            // we're going to assume we're using U.S. English.
            string affixFilename;
            string dictionaryFilename;

            if (!GetDictionaryPaths("en_US", out affixFilename, out dictionaryFilename))
            {
                // We couldn't get the dictionary paths, so just stick with the
                // disabled spelling plugin.
                return;
            }

            // Attempt to load the NHunspell plugin. This is a high-quality
            // plugin based on Managed C++. This works nicely in Windows, but
            // has no support for Linux.
            try
            {
                // Attempt to load the U.S. English language. This will throw
                // an exception if it cannot load. If it does, then we use it.
                var englishUnitedStates = new LanguageConfig
                {
                    LanguageCode = "en_US",
                    HunspellAffFile = affixFilename,
                    HunspellDictFile = dictionaryFilename,
                    HunspellKey = string.Empty
                };

                SpellEngine.AddLanguage(englishUnitedStates);

                // If we got this far, set the project plugin to the one that
                // uses the SpellEngine from NHunspell.
                projectPlugin = new SpellEngineSpellingProjectPlugin(this);
                return;
            }
            catch (Exception exception)
            {
                // Report that we can't load the first attempt.
                Console.WriteLine("Cannot load NHunspell: " + exception);
            }

            // If we got this far, we couldn't load the NHunspell plugin.
            // Attempt to load in the PInvoke implementation instead.
            try
            {
                // Create a new Hunspell P/Invoke loader.
                var pinvokePlugin = new PInvokeSpellingProjectPlugin(
                    affixFilename, dictionaryFilename);
                projectPlugin = pinvokePlugin;
            }
            catch (Exception exception)
            {
                // Report that we can't load the first attempt.
                Console.WriteLine("Cannot load NHunspell via P/Invoke: " + exception);
            }
        }
Ejemplo n.º 4
0
        public List<string> NhunSpellThesaurus(string queryText)
        {
            string dictionaryPath = Hunspell.NativeDllPath;
            spellEngine = new SpellEngine();
            LanguageConfig enConfig = new LanguageConfig();
            enConfig.LanguageCode = "en";
            enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff");
            enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic");
            enConfig.HunspellKey = "";
            enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic");
            enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat");
            spellEngine.AddLanguage(enConfig);
            List<string> myThes = new List<string>();
            bool correct = SpellEngine["en"].Spell(queryText);

            if (correct)
            {

                ThesResult meanings = SpellEngine["en"].LookupSynonyms(queryText, true);
                if (meanings != null)
                {
                    foreach (ThesMeaning meaning in meanings.Meanings)
                    {
                        foreach (string synonym in meaning.Synonyms)
                        {
                            myThes.Add(Server.HtmlEncode(synonym));
                        }
                    }
                }
            }
            return myThes;
        }
Ejemplo n.º 5
0
        public Result GetSuggestions(string input)
        {
            string dictionaryPath = Hunspell.NativeDllPath;
            spellEngine = new SpellEngine();
            LanguageConfig enConfig = new LanguageConfig();
            enConfig.LanguageCode = "en";
            enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff");
            enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic");
            enConfig.HunspellKey = "";
            enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic");
            enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat");
            spellEngine.AddLanguage(enConfig);
            Result objResult = new Result();

            bool correct1;
            using (var hunspell = new Hunspell(enConfig.HunspellAffFile, enConfig.HunspellDictFile))
            {

                string[] lines = System.IO.File.ReadAllLines(@ConfigurationManager.AppSettings["FilePath"].ToString());

                foreach (var line in lines)
                {
                    hunspell.Add(line.ToLower());
                }
                correct1 = hunspell.Spell(input.ToLower());
            }
            bool correct = false;
            try
            {
                correct = SpellEngine["en"].Spell(input);

                if (correct = correct1 == false)
                {
                    objResult.Suggestions = SpellEngine["en"].Suggest(input);
                    objResult.State = "false";
                }
                else
                {
                    objResult.State = "true";

                }
            }
            catch (Exception ex)
            {

            }
            return objResult;
        }