public AlliterationOptions CreateAlliterationOptionsForCategory(AlliterationCategory category)
        {
            var adjectives         = this.wordListBuilder.BuildDictionaryForCategory(AlliterationPart.Adjective, category);
            var nouns              = this.wordListBuilder.BuildDictionaryForCategory(AlliterationPart.Noun, category);
            var startingCharacters = this.allowedStartingCharacterBuilder
                                     .GetAllowedStartingCharacters(adjectives.Keys, nouns.Keys);

            return(new AlliterationOptions
            {
                Adjectives = adjectives,
                Nouns = nouns,
                AllowedStartingCharacters = startingCharacters
            });
        }
Exemplo n.º 2
0
        public IEnumerable <string> GetAlliterationsByCategory(AlliterationCategory category, int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException(nameof(count));
            }

            var options = this.cachingProvider.GetOrSetInCache($"category_{category}",
                                                               () => this.alliterationOptionsFactory.CreateAlliterationOptionsForCategory(category));

            for (var i = 0; i < count; i++)
            {
                var startingCharacter = this.GetRandomEntryFromArray(options.AllowedStartingCharacters);
                yield return(this.GetAlliteration(options, startingCharacter));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <string> GetAlliterationsByCategoryAndStartingChar(AlliterationCategory category, char start, int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException(nameof(count));
            }

            var options = this.cachingProvider.GetOrSetInCache($"category_{category}",
                                                               () => this.alliterationOptionsFactory.CreateAlliterationOptionsForCategory(category));

            start = char.ToUpper(start);
            if (!options.AllowedStartingCharacters.Contains(start))
            {
                throw new ArgumentException(nameof(start));
            }

            for (var i = 0; i < count; i++)
            {
                yield return(this.GetAlliteration(options, start));
            }
        }
        public IDictionary <char, string[]> BuildDictionaryForCategory(AlliterationPart part, AlliterationCategory category)
        {
            var path = this.wordListPathConfigurationProvider
                       .GetPathForPartAndCategory(part, category);
            var words = this.wordFileReader.ReadLines(path);

            var lookup = words.ToLookup(word => char.ToUpper(word[0]));

            return(lookup.ToDictionary(grouping => grouping.Key, grouping => grouping.ToArray()));
        }
Exemplo n.º 5
0
 public string GetPathForPartAndCategory(AlliterationPart part, AlliterationCategory category)
 {
     return(part == AlliterationPart.Adjective
         ? ".\\WordLists\\WordNet\\adjectives.txt"
         : ".\\WordLists\\WordNet\\nouns.txt");
 }