Ejemplo n.º 1
0
        private bool isInform(AnnotatedQuestionActionEntry action, SLUFactory sluFactory)
        {
            var slu = sluFactory.GetBestDialogAct(UtteranceParser.Parse(action.Text));

            if (slu is DontKnowAct || slu is NegateAct || slu is ChitChatAct || slu is AffirmAct)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        static void MainParsing(string[] args)
        {
            var utterance       = "yes, Obama is president of which state?";
            var parsedUtterance = UtteranceParser.Parse(utterance);

            var factory = new SLUFactory();
            var bestAct = factory.GetBestDialogAct(parsedUtterance);
            var acts    = factory.GetDialogActs(parsedUtterance);

            foreach (var act in acts)
            {
                Console.WriteLine(act);
            }
        }
Ejemplo n.º 3
0
        private Dictionary <string, object> getUserSlu(AnnotatedQuestionActionEntry userAction, SLUFactory sluFactory)
        {
            var slu = sluFactory.GetBestDialogAct(UtteranceParser.Parse(userAction.Text));

            if (slu is DontKnowAct || slu is NegateAct || slu is ChitChatAct || slu is AffirmAct)
            {
                return(slu.GetDialogAct().ToDictionary());
            }

            return(new Dictionary <string, object>()
            {
                { "act", "Inform" },
                { "text", userAction.Text }
            });
        }
Ejemplo n.º 4
0
        public ResponseBase Input(ParsedUtterance utterance)
        {
            if (!_isInitialized)
            {
                throw new InvalidOperationException("Cannot take input before initialization");
            }

            var inputAct = _factory.GetBestDialogAct(utterance);

            _currentState = applyInput(inputAct, _currentState);
            //reset expect answer flag after each input.
            _currentState = _currentState.SetExpectAnswer(false);

            return(applyAction());
        }
Ejemplo n.º 5
0
        internal ActionEntry(int actionIndex, Dictionary <string, object> data)
        {
            ActionIndex = actionIndex;
            Data        = data;

            if (data.ContainsKey(CallStorage.TimeEntry))
            {
                Time = (DateTime)data[CallStorage.TimeEntry];
            }

            if (data.ContainsKey("user_id"))
            {
                UserId = data["user_id"] as string;
            }

            if (data.ContainsKey("task_id"))
            {
                TaskId = int.Parse(data["task_id"] as string);
            }

            Type = "T_" + resolveType(data);

            object textData;

            if (
                data.TryGetValue("message", out textData) ||
                data.TryGetValue("utterance", out textData) ||
                data.TryGetValue("response", out textData)
                )
            {
                Text = textData as string;
            }
            else
            {
                Text = "";
            }

            object actData;

            if (data.TryGetValue("response_act", out actData))
            {
                if (actData != null)
                {
                    Act = actData.ToString();
                }
            }

            if (data.TryGetValue("response_act_json", out actData))
            {
                if (actData != null)
                {
                    MachineActJson = actData.ToString();
                }
            }

            if (data.ContainsKey("task"))
            {
                var substitutions = data["substitutions"] as Newtonsoft.Json.Linq.JArray;
                Text = string.Format(data["format"].ToString(), substitutions.ToArray());

                if (data.ContainsKey("success_code"))
                {
                    Text = $"Success: {data["success_code"]}, " + Text;
                }
            }

            switch (Type)
            {
            case "T_advice":
                Text  = "<b>Question</b>:" + data["question"] + "<br>";
                Text += "<b>Context</b>:" + data["context"] + "<br>";
                Text += "<b>Answer</b>:" + data["correctAnswerNode"] + "<br><br>";
                break;

            case "T_equivalence":
                Text  = "<b>PatternQuestion</b>:" + data["patternQuestion"] + "<br>";
                Text += "<b>QueriedQuestion</b>:" + data["queriedQuestion"] + "<br>";
                Text += "<b>IsEquivalent</b>:" + data["isEquivalent"] + "<br><br>";
                break;

            case "T_utterance":
                var utterance = UtteranceParser.Parse(data["utterance"] as string);
                Act = _factory.GetBestDialogAct(utterance).ToString();
                break;
            }
        }