/// <summary>
        /// Generate a simple answer from the json template of this dialog.
        /// </summary>
        /// <param name="stepContext">the waterfall step context</param>
        /// <param name="cancellationToken">the cancellation token</param>
        /// <returns></returns>
        protected async Task <DialogTurnResult> SimpleAnswer(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string        json    = MiscExtensions.LoadEmbeddedResource(_smallTalkPath + "." + $"{_top}.json");
            List <string> answers = json == null ? new List <string>() : JsonConvert.DeserializeObject <List <string> >(json);
            await TheBot.SendMessage(GetSimpleAnswer(answers), stepContext.Context);

            return(await ProceedWithDialog(stepContext));
        }
        private async Task <DialogTurnResult> ClassifySmallTalk(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var top = TheBot.Result.GetTopScoringIntent().Item1.Substring("st_".Length);

            if (MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json") == null)
            {
                await TheBot.SendMessage($"Ich habe noch nicht gelernt auf {top} zu antworten.", stepContext.Context);
            }
            else
            {
                List <string> answers = FindSpecificAnswers(top);
                await TheBot.SendMessage(GetAnswer(answers), stepContext.Context);
            }
            return(await ProceedWithDialog(stepContext));
        }
        /// <summary>
        /// Find answers based on the topics.
        /// </summary>
        /// <param name="top">the topic</param>
        /// <returns>a list of answer templates</returns>
        protected virtual List <string> FindSpecificAnswers(string top)
        {
            List <string> files = Assembly.GetEntryAssembly().GetManifestResourceNames().Where(s => s.StartsWith(SmallTalkPath))
                                  .Select(s => s.Substring(SmallTalkPath.Length + 1))
                                  .Select(f => Path.GetFileNameWithoutExtension(f)).Where(f => f.StartsWith(top)).ToList();

            if (!files.Any())
            {
                throw new FileNotFoundException($"No file found for {top}");
            }

            if (files.Count == 1)
            {
                string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{files[0]}.json");
                return(JsonConvert.DeserializeObject <List <string> >(data));
            }

            List <string> entities = files.Where(f => f.StartsWith($"{top}_")).Select(f => f.Split('_', 2)[1]).ToList();

            // Assume List Entity Name to be "E_{topic}"
            if (!TheBot.Result.Entities.TryGetValue($"E_{top}", out List <IEntity> foundEntities))
            {
                string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json");
                return(JsonConvert.DeserializeObject <List <string> >(data));
            }

            // Assume List Entity
            var roots = foundEntities.Where(e => e.EType == EntityType.Group).Cast <GroupEntity>().Select(e => e.Shape);

            List <string> paths = entities.Where(e => roots.Contains(e)).Select(e => SmallTalkPath + "." + $"{top}_{e}.json").ToList();

            if (!paths.Any())
            {
                string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json");
                return(JsonConvert.DeserializeObject <List <string> >(data));
            }

            return(paths.SelectMany(p => JsonConvert.DeserializeObject <List <string> >(MiscExtensions.LoadEmbeddedResource(p))).ToList());
        }
 /// <summary>
 /// Creates the analyzer.
 /// </summary>
 /// <param name="lang">Defines the language.</param>
 /// <exception cref="ArgumentException">unsupported language.</exception>
 public RegexQuestionAnalyzer(Language lang)
 {
     if (!Configs.Contains(lang))
     {
         throw new ArgumentException("Your Language is not supported.");
     }
     _map = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(MiscExtensions.LoadEmbeddedResource($"Framework.DialogAnalyzer.QuestionTypes_{Maps[lang]}.json"));
 }