예제 #1
0
파일: DataModel.cs 프로젝트: burstas/rmps
 /// <summary>
 /// 
 /// </summary>
 /// <param name="lan"></param>
 public void DropSentence(MSentence lan)
 {
     _DBE.ReInit();
     _DBE.AddTable(DataConst.P3100100);
     _DBE.AddWhere(DataConst.P3100103, lan.P3100103);
     _DBE.ExecuteDelete();
 }
예제 #2
0
파일: Category.cs 프로젝트: burstas/rmps
 public void ReInit(MSentence question, MSentence response)
 {
     _response = response;
     CbCategory.Items.Clear();
     CbCategory.Items.AddRange(_DataModel.ListTags(response.P3100103).ToArray());
 }
예제 #3
0
파일: Opinions.cs 프로젝트: burstas/rmps
 public void ReInit(MSentence question, MSentence response)
 {
 }
예제 #4
0
파일: DataModel.cs 프로젝트: burstas/rmps
 /// <summary>
 /// 
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 private static MSentence ReadSentence(DataRow row)
 {
     var lan = new MSentence();
     lan.P3100101 = (int)row[DataConst.P3100101];
     lan.P3100102 = (EStyle)Enum.Parse(typeof(EStyle), row[DataConst.P3100101] + "");
     lan.P3100103 = row[DataConst.P3100103] + "";
     lan.P3100104 = row[DataConst.P3100104] + "";
     lan.P3100105 = row[DataConst.P3100105] + "";
     lan.P3100106 = row[DataConst.P3100106] + "";
     return lan;
 }
예제 #5
0
파일: DataModel.cs 프로젝트: burstas/rmps
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sentence"></param>
        /// <returns></returns>
        public int SaveSentence(MSentence sentence)
        {
            _DBE.ReInit();
            _DBE.AddTable(DataConst.P3100100);

            _DBE.AddParam(DataConst.P3100101, sentence.P3100101);
            _DBE.AddParam(DataConst.P3100102, (long)sentence.P3100102);
            _DBE.AddParam(DataConst.P3100104, sentence.P3100104);
            _DBE.AddParam(DataConst.P3100105, _UserModel.Encode(sentence.P3100105));
            _DBE.AddParam(DataConst.P3100106, _UserModel.Encode(sentence.P3100106));
            _DBE.AddParam(DataConst.P3100107, DataConst.NOW, false);

            if (CharUtil.IsValidateHash(sentence.P3100103))
            {
                _DBE.AddWhere(DataConst.P3100103, sentence.P3100103);
                return _DBE.ExecuteUpdate();
            }

            sentence.P3100103 = HashUtil.UtcTimeInEnc(false);
            _DBE.AddParam(DataConst.P3100103, sentence.P3100103);
            _DBE.AddParam(DataConst.P3100108, DataConst.NOW, false);
            return _DBE.ExecuteInsert();
        }
예제 #6
0
파일: ManWindow.cs 프로젝트: burstas/rmps
        private void BtSend_Click(object sender, EventArgs e)
        {
            string text = TbText.Text;
            TbText.Focus();
            if (string.IsNullOrEmpty(text))
            {
                ShowNotice("不能发送空的消息!");
                return;
            }
            text = Regex.Replace(text, "\r\n?", "\n");

            #region Append Question
            if (_Options == EOptions.AppendQuestion)
            {
                var question = new MSentence();
                question.P3100102 = _Session.Style;
                question.P3100104 = _Session.Language;
                question.P3100105 = _Session.LastInput;
                question.P3100106 = Trim(_Session.LastInput);
                _DataModel.SaveSentence(question);
                _Session.Question.Add(question);
                _Session.QIndex = _Session.Question.Count - 1;

                MSentence response = _DataModel.FindSentence(text);
                if (response == null)
                {
                    response = new MSentence();
                    response.P3100102 = _Session.Style;
                    response.P3100104 = _Session.Language;
                    response.P3100105 = text;
                    response.P3100106 = Trim(text);
                    _DataModel.SaveSentence(response);
                }
                _Session.Response.Add(response);
                //_session.RIndex = _session.Response.Count - 1;

                _DataModel.AppendResponse(question.P3100103, response.P3100103);
                TbText.Text = "";
                ShowOptions(EOptions.UpdateCategory, "给您的回答加个标签吧!");
                return;
            }
            #endregion

            #region Update Question
            if (_Options == EOptions.UpdateQuestion)
            {
                MSentence question = _Session.Question[_Session.QIndex];
                question.P3100105 = text;
                _DataModel.SaveSentence(question);

                TbText.Text = "";
                ShowOptions(EOptions.Default, "谢谢您的更新,$robot_name$会做得更好!");
                return;
            }
            #endregion

            #region Append Response
            if (_Options == EOptions.AppendResponse)
            {
                MSentence question = _Session.Question[0];

                MSentence response = _DataModel.FindSentence(_UserModel.Encode(text));
                if (response == null)
                {
                    response = new MSentence();
                    response.P3100102 = _Session.Style;
                    response.P3100104 = _Session.Language;
                    response.P3100105 = text;
                    response.P3100106 = Trim(text);
                    _DataModel.SaveSentence(response);
                }
                else
                {
                    _DataModel.RemoveResponse(question.P3100103, response.P3100103);
                }
                _Session.Response.Add(response);
                //_session.RIndex = _session.Response.Count - 1;

                _DataModel.AppendResponse(question.P3100103, response.P3100103);
                TbText.Text = "";
                ShowOptions(EOptions.UpdateCategory, "给您的回答加个标签吧!");
                return;
            }
            #endregion

            #region Update Response
            if (_Options == EOptions.UpdateResponse)
            {
                MSentence response = _Session.Response[_Session.RIndex];
                response.P3100105 = text;
                _DataModel.SaveSentence(response);

                TbText.Text = "";
                ShowOptions(EOptions.Default, "谢谢您的更新,$robot_name$会做得更好!");
                return;
            }
            #endregion

            #region Update Category
            if (_Options == EOptions.UpdateCategory)
            {
                string[] arr = text.Split(' ');
                if (arr.Length < 1)
                {
                    return;
                }

                List<MCategory> catList = _DataModel.SaveCategory(arr);
                _DataModel.SaveTags(_Session.Response[_Session.Response.Count - 1].P3100103, catList);
                TbText.Text = "";
                ShowOptions(EOptions.AppendResponse, "还有其它候选回答吗?您可继续输入哟!");
                return;
            }
            #endregion

            _Session.LastInput = text;
            SetAsnwerText("我:" + text);
            TbText.Text = "";

            // 为空检测
            if (string.IsNullOrEmpty(Trim(text)))
            {
                SendMessage(text);
                return;
            }

            string t = Regex.Replace(text, "\\s+", "");
            // 仅数字
            if (Regex.IsMatch(t, "^\\d+$"))
            {
                SendMessage("你好无聊呀,在这数数呢?");
                return;
            }
            // 数学运算
            if (t[t.Length - 1] == '=')
            {
                t = t.Substring(0, t.Length - 1);
            }
            t = Regex.Replace(t, "[\\[\\{(【{]", "(");
            t = Regex.Replace(t, "[\\]\\})】}]", ")");
            if (Regex.IsMatch('(' + t + ')', @"^(((?<o>\()[-+]?(\d+[-+*/])*)+\d+((?<-o>\))([-+*/]\d+)*)+($|[-+*/]))*(?(o)(?!))$"))
            {
                SendMessage(new Mc(text, 3, null).calculate());
                return;
            }

            #region 正常问答
            // 查询提问
            _Session.Question.Clear();
            _Session.QIndex = 0;
            _DataModel.FindQuestion(_Session.Question, text, _Session.Style, _Session.Language, _Session.Category);
            if (_Session.Question.Count < 1)
            {
                ShowOptions(EOptions.AppendQuestion, "无法回答您的提问,教一下$robot_name$吧?");
                return;
            }

            // 查询应答
            _Session.Response.Clear();
            _Session.RIndex = 0;
            _DataModel.FindResponse(_Session.Response, _Session.Question[0].P3100103, _Session.Style, _Session.Language, _Session.Category);
            if (_Session.Response.Count < 1)
            {
                ShowOptions(EOptions.AppendResponse, "无法回答您的提问,教一下$robot_name$吧?");
                return;
            }
            #endregion

            SendMessage(_Session.Response[_Session.RIndex].P3100105);
            ShowOptions(EOptions.RateInfo, "您觉得这个回答怎么样?");
        }