Пример #1
0
        public static Dictionary <int, List <string> > GetDictionarySyllableCount(string fileName)
        {
            Dictionary <int, List <string> > dictionary = new Dictionary <int, List <string> >();

            try
            {
                using (var file = new StreamReader(fileName))
                {
                    while (!file.EndOfStream)
                    {
                        var words = file.ReadLine();

                        foreach (var word in words?.Split())
                        {
                            if (dictionary.ContainsKey(TextProcessor.GetNumberOfSyllables(word)))
                            {
                                dictionary[TextProcessor.GetNumberOfSyllables(word)].Add(word);
                            }
                            else
                            {
                                dictionary.Add(TextProcessor.GetNumberOfSyllables(word), new List <string>()
                                {
                                    word
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            return(dictionary);
        }