Ejemplo n.º 1
0
        /// 判斷User查詢內容
        /// <summary>
        /// 判斷User查詢內容
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetResult(Microsoft.Cognitive.LUIS.LuisResult analysisResult)
        {
            string Message;

            GetResult(analysisResult, out Message);
            return(Message);
        }
Ejemplo n.º 2
0
        /// 判斷User查詢內容(包含Greeting)
        /// <summary>
        /// 判斷User查詢內容(包含Greeting)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool GetResult(Microsoft.Cognitive.LUIS.LuisResult analysisResult, out string ReplyMessage)
        {
            string Default = "很抱歉,無法解析你所問的問題";

            ReplyMessage = Default;
            if (analysisResult == null)
            {
                return(false);
            }

            var intent           = analysisResult.TopScoringIntent;
            var enitiesDictinary = analysisResult.Entities;
            IList <Microsoft.Cognitive.LUIS.Entity> entitiesCollection;

            try
            {
                //TODO 要用設計模式比較好
                if (intent.Name == "Greeting")
                {
                    ReplyMessage = "你好";
                    return(true);
                }
                if (intent.Name == "匯率查詢")
                {
                    string   CurName;
                    DateTime ExDate;
                    if (enitiesDictinary.TryGetValue("Currency", out entitiesCollection))
                    {
                        CurName = entitiesCollection.Select(o => o.Value).FirstOrDefault();
                    }
                    else
                    {
                        return(false);
                    }
                    if (enitiesDictinary.TryGetValue("ExDate", out entitiesCollection))
                    {
                        DateTime.TryParse(entitiesCollection.Select(o => o.Value).FirstOrDefault(), out ExDate);
                    }
                    else
                    {
                        ExDate = DateTime.Today;
                    }
                    ReplyMessage = GetCurrencyExRate(CurName, ExDate);
                    return(false);
                }

                return(false);
            }
            catch (Exception ex)
            {
                ReplyMessage = ex.Message;
                return(false);
            }
        }