public IEnumerable <RecognizeEntity <T> > RecognizeChoices <T>(IMessageActivity message, IReadOnlyDictionary <T, IReadOnlyList <T> > choicesDictionary, IPromptRecognizeChoicesOptions options = null)
        {
            var entities = new List <RecognizeEntity <T> >();
            var index    = 0;

            foreach (var choices in choicesDictionary)
            {
                var values       = choices.Value?.ToList() ?? new List <T>();
                var excludeValue = options?.ExcludeValue ?? false;
                if (!excludeValue)
                {
                    values.Add(choices.Key);
                }
                var match = RecognizeValues(message, values, options).MaxBy(x => x.Score);
                if (match != null)
                {
                    entities.Add(new RecognizeEntity <T>
                    {
                        Entity = choices.Key,
                        Score  = match.Score
                    });
                }
                index++;
            }
            return(entities);
        }
        private static IEnumerable <RecognizeEntity <T> > RecognizeValues <T>(IMessageActivity message, IEnumerable <T> values, IPromptRecognizeChoicesOptions options = null)
        {
            var            utterance = message?.Text?.Trim().ToLowerInvariant() ?? string.Empty;
            var            entities  = new List <RecognizeEntity <T> >();
            IList <string> tokens    = new List <string>();

            foreach (Match match in simpleTokenizer.Matches(utterance))
            {
                tokens.Add(match.Value);
            }
            var maxDistance = options?.MaxTokenDistance ?? 2;
            var index       = 0;

            foreach (var value in values)
            {
                var            text     = value?.ToString().Trim().ToLowerInvariant();
                var            topScore = 0.0;
                IList <string> vTokens  = new List <string>();
                foreach (Match match in simpleTokenizer.Matches(text))
                {
                    vTokens.Add(match.Value);
                }
                for (int i = 0; i < tokens.Count; i++)
                {
                    var score = MatchValue(tokens.ToArray(), vTokens.ToArray(), i, maxDistance, options?.AllowPartialMatches ?? false);
                    if (topScore < score)
                    {
                        topScore = score;
                    }
                }
                if (topScore > 0.0)
                {
                    entities.Add(new RecognizeEntity <T>
                    {
                        Entity = value,
                        Score  = topScore
                    });
                }
                index++;
            }
            return(entities);
        }
        public IEnumerable <RecognizeEntity <string> > RecognizeLocalizedChoices(IMessageActivity message, string choicesKey, ResourceManager resourceManager, IPromptRecognizeChoicesOptions options = null)
        {
            var locale = message?.Locale ?? string.Empty;

            LocalizedDictionary <ChoicesDictionary> cachedLocalizedChoices;

            if (!choicesCache.TryGetValue(choicesKey, out cachedLocalizedChoices))
            {
                var localizedChoices = new LocalizedDictionary <ChoicesDictionary>();
                cachedLocalizedChoices = choicesCache.GetOrAdd(choicesKey, localizedChoices);
            }

            ChoicesDictionary cachedChoices;

            if (!cachedLocalizedChoices.TryGetValue(locale, out cachedChoices))
            {
                var choicesArray = GetLocalizedResource(choicesKey, locale, resourceManager).Split('|');
                var choices      = ConvertToChoices(choicesArray);
                cachedChoices = cachedLocalizedChoices.GetOrAdd(locale, choices);
            }

            return(RecognizeChoices(message, cachedChoices, options));
        }