Exemplo n.º 1
0
        public frmSpelling(METAboltInstance instance, string sentence, string[] swords, ChatType type)
        {
            InitializeComponent();

            this.instance = instance;

            afffile = this.instance.AffFile;        // "en_GB.aff";
            dicfile = this.instance.DictionaryFile; // "en_GB.dic";

            string[] idic = dicfile.Split('.');
            dic = dir + idic[0];

            if (!System.IO.File.Exists(dic + ".csv"))
            {
                System.IO.File.Create(dic + ".csv");
            }

            try
            {
                hunspell.Load(dir + afffile, dir + dicfile);   //("en_us.aff", "en_us.dic");
                ReadWords();
            }
            catch
            {
                //string exp = ex.Message;
            }

            //words = sentence;
            richTextBox1.Text = sentence;
            this.swords       = swords;
            this.ctype        = type;

            ischat = true;
        }
Exemplo n.º 2
0
        private void SetLanguage(string language)
        {
            try
            {
                ClearLanguage();
                var speller = new Hunspell();
                var path    = SpellCheckFolder();

                var aff = Path.Combine(path, language + ".aff");
                var dic = Path.Combine(path, language + ".dic");

                if (File.Exists(aff) && File.Exists(dic))
                {
                    speller.Load(aff, dic);
                    LoadCustomDictonary(speller);
                    _speller  = speller;
                    _language = language;
                }
                else
                {
                    Notify.Alert(language + " dictionary not found");
                }
            }
            catch (Exception ex)
            {
                Notify.Alert($"{ex.Message} in {language ?? "null"} file");
            }
        }
Exemplo n.º 3
0
        public void SetLanguage(SpellingLanguages language)
        {
            speller = new Hunspell();

            var languageKey = LangLookup[language];

            var assembly = Assembly.GetExecutingAssembly();

            var dictionaryFileStart = string.Format("{0}.Document.SpellCheck.Dictionaries.{1}", assembly.GetName().Name, languageKey);
            var dictionaryFiles     = assembly
                                      .GetManifestResourceNames()
                                      .Where(name => name.StartsWith(dictionaryFileStart))
                                      .ToArray();

            var affixes      = dictionaryFiles.Where(name => name.EndsWith(".aff")).OrderBy(s => s);
            var dictionaries = dictionaryFiles.Where(name => name.EndsWith(".dic")).OrderBy(s => s);

            var dictionaryPairs = affixes.Zip(dictionaries, (aff, dic) => new { aff, dic });

            foreach (var pair in dictionaryPairs)
            {
                using (var affStream = assembly.GetManifestResourceStream(pair.aff))
                    using (var dicStream = assembly.GetManifestResourceStream(pair.dic))
                    {
                        if (affStream != null && dicStream != null)
                        {
                            var affBytes = new BinaryReader(affStream).ReadBytes((int)affStream.Length);
                            var dicBytes = new BinaryReader(dicStream).ReadBytes((int)dicStream.Length);

                            speller.Load(affBytes, dicBytes);
                        }
                    }
            }
        }
Exemplo n.º 4
0
            public override void Initialize(BuildContext context)
            {
                base.Initialize(context);

                if (this.IsInitialized)
                {
                    BuildSettings settings = context.Settings;
                    CultureInfo   culture  = settings.CultureInfo;

                    BuildLogger logger = context.Logger;

                    string dictionaryDir = Path.Combine(
                        settings.SandAssistDirectory, "Dictionaries");
                    if (Directory.Exists(dictionaryDir))
                    {
                        string langName = culture.Name;
                        langName = langName.Replace('-', '_');

                        string affFile = Path.Combine(dictionaryDir,
                                                      langName + ".aff");
                        string dicFile = Path.Combine(dictionaryDir,
                                                      langName + ".dic");

                        if (File.Exists(affFile) && File.Exists(dicFile))
                        {
                            if (logger != null)
                            {
                                logger.WriteLine(
                                    "Loading dictionary for: " + culture.EnglishName,
                                    BuildLoggerLevel.Info);
                            }

                            _hunspell = new Hunspell();
                            _hunspell.Load(affFile, dicFile);
                        }
                        else
                        {
                            if (logger != null)
                            {
                                logger.WriteLine(
                                    "No dictionary found for: " + culture.EnglishName,
                                    BuildLoggerLevel.Warn);
                            }
                        }
                    }
                }

                if (_hunspell == null)
                {
                    this.IsInitialized = false;
                }
            }
Exemplo n.º 5
0
        private HunspellWraper(string lang)
        {
            _lang = lang;
            _dictionaryLanguages = HunspellDictionaryLanguages.DefaultInstance();
            if (!_dictionaryLanguages.Languages.Contains(_lang))
            {
                throw new Exception("Language not found.");
            }
            _spc = new Hunspell();
            KeyValuePair <string, string> dicPath = _dictionaryLanguages.GetDictionaryPath(_lang);

            _spc.Load(dicPath.Key, dicPath.Value);
        }
Exemplo n.º 6
0
        private void ApplyConfig(Config config)
        {
            if (config.InterfaceStyle == 0) //System
            {
                toolStrip1.RenderMode = ToolStripRenderMode.System;
            }
            else if (config.InterfaceStyle == 1) //Office 2003
            {
                toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode;
            }

            //rtbIMText.BackColor = instance.Config.CurrentConfig.BgColour;

            if (instance.Config.CurrentConfig.EnableSpelling)
            {
                dicfile = instance.Config.CurrentConfig.SpellLanguage;   // "en_GB.dic";

                this.instance.AffFile        = afffile = dicfile + ".aff";
                this.instance.DictionaryFile = dicfile + ".dic";

                dic = dir + dicfile;

                dicfile += ".dic";

                if (!System.IO.File.Exists(dic + ".csv"))
                {
                    //System.IO.File.Create(dic + ".csv");

                    using (StreamWriter sw = File.CreateText(dic + ".csv"))
                    {
                        sw.Dispose();
                    }
                }

                hunspell.Dispose();
                hunspell = new Hunspell();

                hunspell.Load(dir + afffile, dir + dicfile);
                ReadWords();
            }
            else
            {
                hunspell.Dispose();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        void InitSpellCheck()
        {
            var warmUp = new Thread(
                () =>
            {
                try
                {
                    _spellFa.Load("spelldic\\fa.aff", "spelldic\\fa.dic");
                    _spellEn.Load("spelldic\\en_US.aff", "spelldic\\en_US.dic");
                    _spellCheckLoaded = true;
                }
                catch
                {
                }
            });

            warmUp.IsBackground = true;
            warmUp.Name         = "WarmUp-SpellCheck";
            warmUp.Start();
        }
Exemplo n.º 8
0
        public void SetLanguage(string language)
        {
            ClearLanguage();
            var speller        = new Hunspell();
            var assemblyFolder = Utility.AssemblyFolder();
            var path           = Path.Combine(assemblyFolder, "SpellCheck\\Dictionaries");

            var aff = Path.Combine(path, language + ".aff");
            var dic = Path.Combine(path, language + ".dic");

            if (File.Exists(aff) && File.Exists(dic))
            {
                speller.Load(aff, dic);
                LoadCustomDictonary(speller);
                _speller = speller;
            }
            else
            {
                Debug.WriteLine("dictionary not found");
            }
        }
Exemplo n.º 9
0
        private void SetLanguage(string language)
        {
            ClearLanguage();
            var speller = new Hunspell();
            var path    = SpellCheckFolder();

            var aff = Path.Combine(path, language + ".aff");
            var dic = Path.Combine(path, language + ".dic");

            if (File.Exists(aff) && File.Exists(dic))
            {
                speller.Load(aff, dic);
                LoadCustomDictonary(speller);
                _speller  = speller;
                _language = language;
            }
            else
            {
                MessageBox.Show(Application.Current.MainWindow, language + " dictionary not found", App.Title, MessageBoxButton.OK);
            }
        }
 private static void Init()
 {
     Engine = new Hunspell();
     Engine.Load("dictionary.aff", "dictionary.dic");
     Engine.Add("lol");
     Engine.Add("rofl");
     Engine.Add("lmao");
     Engine.Add("lmfao");
     Engine.Add("pmsl");
     Engine.Add("wtf");
     Engine.Add("nvm");
     Engine.Add("irl");
     Engine.Add("ily");
     Engine.Add("bff");
     Engine.Add("tyt");
     Engine.Add("ttyl");
     Engine.Add("brb");
     Engine.Add("bbs");
     Engine.Add("bbl");
     Engine.Add("hb");
     Engine.Add("ty");
     Engine.Add("yw");
     Engine.Add("afaik");
     Engine.Add("afk");
     Engine.Add("idk");
     Engine.Add("bf");
     Engine.Add("gf");
     Engine.Add("btw");
     Engine.Add("np");
     Engine.Add("omg");
     Engine.Add("oic");
     Engine.Add("tmi");
     Engine.Add("asl");
     Engine.Add("ik");
     Engine.Add("ikr");
     Engine.Add("k");
     Engine.Add("plz");
 }
Exemplo n.º 11
0
        /// <summary>
        /// Check every word in an input string if they are all correct
        /// according to Vietnamese vocabularies
        /// </summary>
        /// <param name="inputStr">Input sentence</param>
        /// <returns>
        /// string[] contains at least 1 and maximum 2 records
        /// Record 1: True / False that indicates input value is correct or not
        /// Record 2 (if any): Suggest a correct string value base on input value
        /// </returns>
        public static string[] CheckVocabulary(string inputStr)
        {
            // Declare list of tokens and list of returned results
            string[] resultList = new string[2];
            resultList[0] = Constants.True;
            List <string> tokenList = new List <string>();

            // Normalize input string
            inputStr = inputStr.Trim().ToLower();
            // Tokenizer input string
            tokenList = StringTokenizer(inputStr);

            // Read configutation detail from Web.config
            string viVnAffUrl = WebConfigurationManager.
                                AppSettings[Constants.ViVnAffUrl];
            string viVnDicUrl = WebConfigurationManager.
                                AppSettings[Constants.ViVnDicUrl];

            // Return null if configuration detail is not correct
            if (viVnAffUrl == null || viVnDicUrl == null)
            {
                return(null);
            }

            // Read from diacritic Vietnamese words dictionary
            byte[] affFile = System.IO.File.ReadAllBytes(viVnAffUrl);
            // Read from single Vietnamese words dictionary
            byte[] dicFile = System.IO.File.ReadAllBytes(viVnDicUrl);

            // Check if input string is correct
            Hunspell hunspell = new Hunspell();

            hunspell.Load(affFile, dicFile);

            using (hunspell)
            {
                // Set default value for suggest string
                string result = string.Empty;

                // Check every word in the list of tokens
                foreach (string token in tokenList)
                {
                    string word = token;
                    // Check if the word a correct according to Vietnamese single words dictionary
                    if (hunspell.Spell(word))
                    {
                        result += (word + Constants.WhiteSpace);
                    }
                    else
                    {
                        resultList[0] = Constants.False;

                        // Find relative Vietnamese diacritic characters
                        List <char> relativeDiacraticChars = TakeRelativeDiacriticChars(word);

                        // Load list of suggestion words in dictionary
                        List <string> suggestionsListInDictionary = hunspell.Suggest(word);

                        // Create list of best suggestion words
                        List <string> bestSuggestionList = new List <string>();

                        if (suggestionsListInDictionary.Count > 1)
                        {
                            bestSuggestionList =
                                FindBestSuggestionWords(suggestionsListInDictionary, relativeDiacraticChars);
                        }

                        if ((bestSuggestionList.Count == 0))
                        {
                            bestSuggestionList = suggestionsListInDictionary;
                        }

                        // Find best value for each best suggesion word
                        string bestSuggestion = string.Empty;
                        int    max            = -1;

                        foreach (string suggestion in bestSuggestionList)
                        {
                            // Case of best suggestion contains in the input word
                            if (IsPatternMatched(suggestion, word) || IsPatternMatched(word, suggestion))
                            {
                                bestSuggestion = suggestion;
                                break;
                            }

                            // Process best suggestion word
                            int temp          = 0;
                            int shorterLength = (suggestion.Length < word.Length ? suggestion.Length : word.Length);
                            for (int i = 0; i < shorterLength; i++)
                            {
                                if (word[i] == suggestion[i])
                                {
                                    temp += i;
                                }
                            }

                            // Assign best suggestion word
                            if (temp > max)
                            {
                                bestSuggestion = suggestion;
                                max            = temp;
                            }
                        }

                        // Concate result string
                        result += (bestSuggestion + Constants.WhiteSpace);
                    }
                }

                // Add suggest string to result list
                resultList[1] = result.Trim();
                // Return result
                return(resultList);
            }
        }