示例#1
0
        /// <summary>
        /// Identify mention and id of meeting members from utterance,
        /// collect them as dynamicLists to be attached to LuisAdaptiveRecognizer
        /// </summary>
        /// <param name="utterance">User utterance</param>
        /// <param name="memberDynamicList">Known meeting members (id, name etc) from Teams</param>
        /// <param name="fuzzyMatch">default true to enable approximate matching</param>
        public List <Luis.DynamicList> GetMatchedEntityDynamicLists(string utterance, Luis.DynamicList memberDynamicList, bool fuzzyMatch = true)
        {
            var matches = Search(utterance, memberDynamicList.List, fuzzyMatch);

            if (matches.Any() == false)
            {
                return(null);
            }

            var idMentionDynamicLists = new List <Luis.DynamicList>();

            var idMentionDynamicList = new Luis.DynamicList();

            idMentionDynamicList.Entity = "MatchedMember";
            idMentionDynamicList.List   = new List <ListElement>();

            var idIdx  = new Dictionary <string, int>();
            var newIdx = 0;

            foreach (var match in matches)
            {
                var id      = match.Id;
                var mention = utterance.Substring(match.StartOffset, match.EndOffset - match.StartOffset);

                if (idIdx.ContainsKey(id))
                {
                    var existingIdx = idIdx[id];
                    idMentionDynamicList.List[existingIdx].Synonyms.Add(mention);
                }
                else
                {
                    idIdx[id] = newIdx;
                    newIdx   += 1;

                    var person = new ListElement()
                    {
                        CanonicalForm = id,
                        Synonyms      = new List <string>()
                    };
                    person.Synonyms.Add(mention);
                    idMentionDynamicList.List.Add(person);
                }
            }

            idMentionDynamicLists.Add(idMentionDynamicList);

            return(idMentionDynamicLists);
        }
示例#2
0
        public List <string> ResolveIds(List <string> names, Luis.DynamicList dynamicList, bool fuzzyMatch = true)
        {
            List <string> res = new List <string>();

            foreach (var name in names)
            {
                var matches = Search(name, dynamicList.List, fuzzyMatch);

                if (matches.Any())
                {
                    var clusters         = matches.GroupBy(match => (match.EndOffset - match.StartOffset));
                    var max_span_cluster = clusters.OrderByDescending(cl => cl.Key).First();
                    var ids      = max_span_cluster.Select(tm => tm.Id).ToArray();
                    var name_ids = $"{name} ({string.Join(" or ", ids)})";
                    res.Add(name_ids);
                }
                else
                {
                    res.Add(name);
                }
            }

            return(res);
        }