예제 #1
0
        /// <summary> Tells the story in the chosen language. </summary>
        static IEnumerable <string> TellStory(Dictionary <string, string> dict, Morpher.IDynamicDeclension grammar)
        {
            // THE PLOT. See if you can read the story from it!
            var story = new []
            {
                new { Verb = "title", Actors = "" },
                new { Verb = "likes2", Actors = "bob,alice,photo" },
                new { Verb = "commented", Actors = "bob,alice,photo" },
                new { Verb = "emailed", Actors = "bob,alice" },
                new { Verb = "likes", Actors = "bob,alice" },
                new { Verb = "likes", Actors = "alice,celebrity" },
            };

            return(story.Select(sentence => Regex.Replace(
                                    string.Format(dict [sentence.Verb], sentence.Actors.Split(',')),
                                    @"<(?<id>\w*)(:(?<format>\w*))?>",
                                    match => GetDeclension(dict [match.Groups ["id"].Value], match.Groups ["format"].Value, grammar))));
        }
예제 #2
0
 static string GetDeclension(string s, string format, Morpher.IDynamicDeclension morpher)
 {
     return(Bold(string.IsNullOrEmpty(format) ? s : morpher.GetCase(s, format)));
 }