Пример #1
0
        public void WhenDefinitionAutomaticallySourcedFromSuffixStatusShouldBeSuffix()
        {
            var word = "pelicans";
            var temporaryDefinition = TestFileHelper.PelicanTemporaryDefinition;

            _temporaryDefinitionHelper = new TemporaryDefinitionHelper(_fileHelper);
            _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(_dictionary, word, temporaryDefinition);
            _wordService.UpdateDictionaryFile();

            var json       = TestFileHelper.Read(Filename);
            var dictionary = JsonConvert.DeserializeObject <Dictionary>(json);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = temporaryDefinition,
                PermanentDefinition = null,
                Status = WordStatus.Suffix
            });
        }
Пример #2
0
        public bool StrippedSuffixDictionaryCheck(Dictionary dictionary, string word)
        {
            word = word.ToLower();
            var endings = new List <string> {
                "ning", "ing", "ed", "er", "es", "s", "d"
            };

            endings = endings
                      .Where(x => x.Length < word.Length)
                      .OrderByDescending(s => s.Length)
                      .ToList();


            foreach (var ending in endings)
            {
                var shortenedWord = word.Remove(word.Length - ending.Length);

                if (word.Substring(word.Length - ending.Length) != ending)
                {
                    continue;
                }

                if (!_wordExistenceHelper.DoesWordExist(shortenedWord))
                {
                    continue;
                }

                if (CheckWordWithEndingExists(word, shortenedWord))
                {
                    var temporaryDefinition = _wordDefinitionHelper.GetDefinitionForWord(shortenedWord);
                    _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(dictionary, word, temporaryDefinition);
                    return(true);
                }
            }

            return(false);
        }