Ejemplo n.º 1
0
        internal ResponseBase Input(string utterance)
        {
            ensureInitialization();

            var          formattedUtterance = utterance == null ? "" : utterance.Trim();
            var          parsedUtterance    = KnowledgeDialog.Dialog.UtteranceParser.Parse(formattedUtterance);
            ResponseBase response;

            lock (_L_qa_index)
            {
                _currentHTML += userTextHTML(formattedUtterance);
                response      = Manager.Input(parsedUtterance);
                _lastResponse = response;

                if (response == null)
                {
                    _currentHTML += systemTextHTML("<i>The dialog has ended, please type <b>reset</b> if you wish another dialog.</i>");
                }
                else
                {
                    _currentHTML += systemTextHTML(response.ToString());
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run dialog service (is blocking)
        /// </summary>
        public void Run(bool useDirectInput = false)
        {
            if (_inputManager != null)
            {
                var initializationResponse = _inputManager.Initialize();
                ConsoleServices.PrintOutput(initializationResponse);
            }

            for (; ;)
            {
                var utterance = readUtterance();

                ResponseBase response;
                if (_manager == null)
                {
                    var parsedSentence = Dialog.UtteranceParser.Parse(utterance);
                    response = _inputManager.Input(parsedSentence);
                }
                else
                {
                    var parsedUtterance = parseUtterance(utterance);
                    if (parsedUtterance == null)
                    {
                        return;
                    }

                    if (useDirectInput)
                    {
                        response = _manager.Ask(utterance);
                    }
                    else
                    {
                        response = parsedUtterance.HandleManager(_manager);
                    }
                }
                ConsoleServices.PrintOutput(response);
            }
        }