Ejemplo n.º 1
0
        public void NamesListNotInList()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);

            // Act
            var exists = namesList.GetNames().Contains("JonesASDFLKJCKJXFLKJSLDKFJASDF");

            // Assert
            Assert.IsFalse(exists);
        }
Ejemplo n.º 2
0
        public void NamesListAddWordReload()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);
            namesList.Add("Jones123");

            // Act
            namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);

            // Assert
            Assert.IsTrue(namesList.GetNames().Contains("Jones123"));
        }
        public SpellCheckWordLists(string dictionaryFolder, string languageName, IDoSpell doSpell)
        {
            if (languageName == null)
                throw new NullReferenceException("languageName");
            if (doSpell == null)
                throw new NullReferenceException("doSpell");

            _languageName = languageName;
            _doSpell = doSpell;
            _namesList = new NamesList(Configuration.DictionariesFolder, languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            _namesEtcList = _namesList.GetNames();
            var namesEtcMultiWordList = _namesList.GetMultiNames();

            foreach (string namesItem in _namesEtcList)
                _namesEtcListUppercase.Add(namesItem.ToUpper());

            if (languageName.StartsWith("en_", StringComparison.OrdinalIgnoreCase))
            {
                foreach (string namesItem in _namesEtcList)
                {
                    if (!namesItem.EndsWith('s'))
                    {
                        _namesEtcListWithApostrophe.Add(namesItem + "'s");
                        _namesEtcListWithApostrophe.Add(namesItem + "’s");
                    }
                    else if (!namesItem.EndsWith('\''))
                    {
                        _namesEtcListWithApostrophe.Add(namesItem + "'");
                    }
                }
            }

            _userWordList = new List<string>();
            _userPhraseList = new List<string>();
            if (File.Exists(dictionaryFolder + languageName + "_user.xml"))
            {
                var userWordDictionary = new XmlDocument();
                userWordDictionary.Load(dictionaryFolder + languageName + "_user.xml");
                if (userWordDictionary.DocumentElement != null)
                {
                    var xmlNodeList = userWordDictionary.DocumentElement.SelectNodes("word");
                    if (xmlNodeList != null)
                    {
                        foreach (XmlNode node in xmlNodeList)
                        {
                            string word = node.InnerText.Trim().ToLower();
                            if (word.Contains(' '))
                                _userPhraseList.Add(word);
                            else
                                _userWordList.Add(word);
                        }
                    }
                }
            }

            // Add names/userdic with "." or " " or "-"
            _wordsWithDashesOrPeriods = new List<string>();
            _wordsWithDashesOrPeriods.AddRange(namesEtcMultiWordList);
            foreach (string name in _namesEtcList)
            {
                if (name.Contains(PeriodAndDash))
                    _wordsWithDashesOrPeriods.Add(name);
            }
            foreach (string word in _userWordList)
            {
                if (word.Contains(PeriodAndDash))
                    _wordsWithDashesOrPeriods.Add(word);
            }
            _wordsWithDashesOrPeriods.AddRange(_userPhraseList);
        }
Ejemplo n.º 4
0
        private void LoadDictionaries(string dictionaryFolder, string dictionary)
        {
            _changeAllDictionary = new Dictionary<string, string>();
            _skipAllList = new List<string>();
            _namesList = new NamesList(Configuration.DictionariesFolder, _languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            _namesEtcList = _namesList.GetNames();
            _namesEtcMultiWordList = _namesList.GetMultiNames();

            foreach (string namesItem in _namesEtcList)
                _namesEtcListUppercase.Add(namesItem.ToUpper());

            if (_languageName.StartsWith("en_", StringComparison.OrdinalIgnoreCase))
            {
                foreach (string namesItem in _namesEtcList)
                {
                    if (!namesItem.EndsWith('s'))
                    {
                        _namesEtcListWithApostrophe.Add(namesItem + "'s");
                        _namesEtcListWithApostrophe.Add(namesItem + "’s");
                    }
                    else if (!namesItem.EndsWith('\''))
                    {
                        _namesEtcListWithApostrophe.Add(namesItem + "'");
                    }
                }
            }

            _userWordList = new List<string>();
            _userPhraseList = new List<string>();
            if (File.Exists(dictionaryFolder + _languageName + "_user.xml"))
            {
                var userWordDictionary = new XmlDocument();
                userWordDictionary.Load(dictionaryFolder + _languageName + "_user.xml");
                foreach (XmlNode node in userWordDictionary.DocumentElement.SelectNodes("word"))
                {
                    string word = node.InnerText.Trim().ToLower();
                    if (word.Contains(' '))
                        _userPhraseList.Add(word);
                    else
                        _userWordList.Add(word);
                }
            }

            // Add names/userdic with "." or " " or "-"
            _wordsWithDashesOrPeriods = new List<string>();
            _wordsWithDashesOrPeriods.AddRange(_namesEtcMultiWordList);
            foreach (string name in _namesEtcList)
            {
                if (name.Contains(new[] { '.', '-' }))
                    _wordsWithDashesOrPeriods.Add(name);
            }
            foreach (string word in _userWordList)
            {
                if (word.Contains(new[] { '.', '-' }))
                    _wordsWithDashesOrPeriods.Add(word);
            }
            _wordsWithDashesOrPeriods.AddRange(_userPhraseList);

            _changeAllDictionary = new Dictionary<string, string>();
            LoadHunspell(dictionary);
        }
Ejemplo n.º 5
0
        private void LoadSpellingDictionariesViaDictionaryFileName(string threeLetterIsoLanguageName, CultureInfo culture, string dictionaryFileName, bool resetSkipList)
        {
            _fiveLetterWordListLanguageName = Path.GetFileNameWithoutExtension(dictionaryFileName);
            if (_fiveLetterWordListLanguageName.Length > 5)
                _fiveLetterWordListLanguageName = _fiveLetterWordListLanguageName.Substring(0, 5);
            string dictionary = Utilities.DictionaryFolder + _fiveLetterWordListLanguageName;
            if (resetSkipList)
            {
                _wordSkipList = new HashSet<string> { Configuration.Settings.Tools.MusicSymbol, "*", "%", "#", "+", "$" };
            }

            // Load names etc list (names/noise words)
            _namesList = new NamesList(Configuration.DictionariesFolder, _fiveLetterWordListLanguageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            _namesEtcList = _namesList.GetNames();
            _namesEtcMultiWordList = _namesList.GetMultiNames();
            _namesEtcListUppercase = new HashSet<string>();
            foreach (string name in _namesEtcList)
                _namesEtcListUppercase.Add(name.ToUpper());

            _namesEtcListWithApostrophe = new HashSet<string>();
            if (threeLetterIsoLanguageName.Equals("eng", StringComparison.OrdinalIgnoreCase))
            {
                foreach (string namesItem in _namesEtcList)
                {
                    if (!namesItem.EndsWith('s'))
                        _namesEtcListWithApostrophe.Add(namesItem + "'s");
                    else
                        _namesEtcListWithApostrophe.Add(namesItem + "'");
                }
            }

            // Load user words
            _userWordList = new HashSet<string>();
            _userWordListXmlFileName = Utilities.LoadUserWordList(_userWordList, _fiveLetterWordListLanguageName);

            // Find abbreviations
            _abbreviationList = new HashSet<string>();
            foreach (string name in _namesEtcList)
            {
                if (name.EndsWith('.'))
                    _abbreviationList.Add(name);
            }
            if (threeLetterIsoLanguageName.Equals("eng", StringComparison.OrdinalIgnoreCase))
            {
                if (!_abbreviationList.Contains("a.m."))
                    _abbreviationList.Add("a.m.");
                if (!_abbreviationList.Contains("p.m."))
                    _abbreviationList.Add("p.m.");
                if (!_abbreviationList.Contains("o.r."))
                    _abbreviationList.Add("o.r.");
            }

            foreach (string name in _userWordList)
            {
                if (name.EndsWith('.'))
                    _abbreviationList.Add(name);
            }

            // Load Hunspell spell checker
            try
            {
                if (!File.Exists(dictionary + ".dic"))
                {
                    var fileMatches = Directory.GetFiles(Utilities.DictionaryFolder, _fiveLetterWordListLanguageName + "*.dic");
                    if (fileMatches.Length > 0)
                        dictionary = fileMatches[0].Substring(0, fileMatches[0].Length - 4);
                }
                if (_hunspell != null)
                    _hunspell.Dispose();
                _hunspell = Hunspell.GetHunspell(dictionary);
                IsDictionaryLoaded = true;
                _spellCheckDictionaryName = dictionary;
                DictionaryCulture = culture;
            }
            catch
            {
                IsDictionaryLoaded = false;
            }
        }
Ejemplo n.º 6
0
        public void NamesListRemoveReload()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "da", false, null);
            namesList.Add("Jones123");

            // Act
            namesList.Remove("Jones123");
            namesList = new NamesList(Directory.GetCurrentDirectory(), "da", false, null);

            // Assert
            Assert.IsFalse(namesList.GetNames().Contains("Jones123"));
        }