Пример #1
0
        public void NamesListAddMultiWord()
        {
            // Arrange
            var namesList = new NameList(Directory.GetCurrentDirectory(), "da", false, null);

            // Act
            namesList.Add("Charlie Parker123");
            var exists = namesList.GetMultiNames().Contains("Charlie Parker123");

            // Assert
            Assert.IsTrue(exists);
        }
Пример #2
0
        public SpellCheckWordLists(string dictionaryFolder, string languageName, IDoSpell doSpell)
        {
            _dictionaryFolder = dictionaryFolder ?? throw new NullReferenceException(nameof(dictionaryFolder));
            _languageName     = languageName ?? throw new NullReferenceException(nameof(languageName));
            _doSpell          = doSpell ?? throw new NullReferenceException(nameof(doSpell));
            _nameList         = new NameList(Configuration.DictionariesDirectory, languageName, Configuration.Settings.WordLists.UseOnlineNames, Configuration.Settings.WordLists.NamesUrl);
            _names            = _nameList.GetNames();
            var namesMultiWordList = _nameList.GetMultiNames();

            if (Configuration.Settings.Tools.RememberUseAlwaysList)
            {
                LoadUseAlwaysList();
            }

            foreach (string namesItem in _names)
            {
                _namesListUppercase.Add(namesItem.ToUpperInvariant());
            }

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

            if (File.Exists(dictionaryFolder + languageName + "_user.xml"))
            {
                var userWordDictionary = new XmlDocument();
                userWordDictionary.Load(dictionaryFolder + languageName + "_user.xml");
                var xmlNodeList = userWordDictionary.DocumentElement?.SelectNodes("word");
                if (xmlNodeList != null)
                {
                    foreach (XmlNode node in xmlNodeList)
                    {
                        string word = node.InnerText.Trim().ToLowerInvariant();
                        if (word.Contains(' '))
                        {
                            _userPhraseList.Add(word);
                        }
                        else
                        {
                            _userWordList.Add(word);
                        }
                    }
                }
            }
            // Add names/userdic with "." or " " or "-"
            foreach (var word in namesMultiWordList)
            {
                if (word.Contains(PeriodAndDash))
                {
                    _wordsWithDashesOrPeriods.Add(word);
                }
            }
            foreach (string name in _names)
            {
                if (name.Contains(PeriodAndDash))
                {
                    _wordsWithDashesOrPeriods.Add(name);
                }
            }
            foreach (string word in _userWordList)
            {
                if (word.Contains(PeriodAndDash))
                {
                    _wordsWithDashesOrPeriods.Add(word);
                }
            }
            foreach (var phrase in _userPhraseList)
            {
                if (phrase.Contains(PeriodAndDash))
                {
                    _wordsWithDashesOrPeriods.Add(phrase);
                }
            }
        }