예제 #1
0
        public async Task <QueryResult> Process(string datastoreName, string userId, string sessionId, string query, RUNNINGMODE runningMode)
        {
            this.userId       = userId;
            this.sessionId    = sessionId;
            this.query        = query;
            this.runningMode  = runningMode;
            this.dQuerier     = new DataQuerier(datastoreName, runningMode);
            this.msgGenerator = new MessageGenerator(runningMode);


            LogInformation(log.Here(), "runningMode", runningMode.ToString());

            ContextManager contextMgmt     = new ContextManager(datastoreName, userId, sessionId);
            bool           isSameDataStore = contextMgmt.GetContext();

            QueryResult result = null;

            if (!isSameDataStore)
            {
                result = this.msgGenerator.GenerateErrorMessage("在本轮对话结束前更改 Datastore 导致之前对话退出。");
                contextMgmt.ExitDialog();
                contextMgmt.UpdateContext();
                return(result);
            }

            NLUResult nlu = new NLUProcessor(datastoreName).Parse(query);

            LogInformation(log.Here(), "nlu", nlu.ToString());

            NLUResultType type = nlu.GetType();

            if (type == NLUResultType.NOTEXIST)
            {
                result = this.msgGenerator.GenerateErrorMessage("无法查找语料,请确认 Datastore 是否存在,以及其中是否有数据。");
                contextMgmt.ExitDialog();
            }
            else if (type == NLUResultType.UNKNOWN && contextMgmt.GetIntent() == null)
            {
                result = this.msgGenerator.GenerateErrorMessage("无法识别意图。");
                contextMgmt.ExitDialog();
            }
            else if (type == NLUResultType.QUITDIALOG)
            {
                result = this.msgGenerator.GenerateQuitMessage();
                contextMgmt.ExitDialog();
            }
            else
            {
                result = ResponseDialog(nlu, contextMgmt);
            }

            contextMgmt.UpdateContext();

            return(result);
        }
예제 #2
0
        public async Task <QueryResult> Process(string userId, string sessionId, string query, RUNNINGMODE runningMode)
        {
            this.userId       = userId;
            this.sessionId    = sessionId;
            this.query        = query;
            this.runningMode  = runningMode;
            this.dQuerier     = new DataQuerier(runningMode);
            this.msgGenerator = new MessageGenerator(runningMode);


            LogInformation(_log.Here(), "runningMode", runningMode.ToString());

            ContextManager contextMgmt = new ContextManager(userId, sessionId);

            contextMgmt.GetContext();

            NLUResult nlu = new NLUProcessor().Parse(query);

            LogInformation(_log.Here(), "nlu", nlu.ToString());

            NLUResultType type = nlu.GetType();

            QueryResult result = null;

            if (type == NLUResultType.UNKNOWN && contextMgmt.GetIntent() == null)
            {
                result = this.msgGenerator.GenerateErrorMessage("无法识别意图。");
                contextMgmt.ExitDialog();
            }
            else if (type == NLUResultType.QUITDIALOG)
            {
                result = this.msgGenerator.GenerateQuitMessage();
                contextMgmt.ExitDialog();
            }
            else
            {
                result = ResponseDialog(nlu, contextMgmt);
            }

            contextMgmt.UpdateContext();

            return(result);
        }