Пример #1
0
        private void HandleCurrentIDChanged(object sender, EventArgs e)
        {
            DialogueItem currentDialogueItem = FindCurrentDialogueItem();

            if (currentDialogueItem != null)
            {
                //  currentDialogueItem.RepetitionCount++;
                // Run the timeout timer only for those items that have the corresponding property:
                PropertyInfo timeoutProperty = currentDialogueItem.GetType().GetProperty(AgentConstants.TIMEOUT_INTERVAL_PROPERTY_NAME);
                if (timeoutProperty != null)
                {
                    dialogueItemTimer.Stop(); // Just in case it was running previously.
                    double timeoutInterval = (double)timeoutProperty.GetValue(currentDialogueItem);
                    if (timeoutInterval > 0)
                    {
                        dialogueItemTimer.Run(timeoutInterval);
                    }
                }
                if (!(currentDialogueItem is InputItem)) // If this is NOT true, then just await the input; see above.
                {
                    if (currentDialogueItem is AsynchronousDialogueItem)
                    {
                        ((AsynchronousDialogueItem)currentDialogueItem).RunAsynchronously(null);
                    }
                    else
                    {
                        string targetContext = null;
                        string targetID      = null;
                        currentDialogueItem.Run(null, out targetContext, out targetID);
                        if (targetContext != workingMemory.CurrentContext)
                        {
                            workingMemory.CurrentContext = targetContext;
                        }                                                                                                    // Triggers the ContextChangedEvent in working memory
                        else
                        {
                            workingMemory.CurrentID = targetID;
                        }                                            // Triggers the IDChangedEvent in working memory
                    }
                }
                // else // But perhaps add a timeout, then repeat, then set context = "".
                //  { }
            }
        }
Пример #2
0
        private void HandleUserInput(MemoryItem inputItem)
        {
            busy = true;
            dialogueItemTimer.Stop();                           // In case the time was running, make sure that it is stopped here, to avoid repeating the agent's previous statement.
            string        inputString   = (string)inputItem.GetContent();
            string        sourceTag     = inputItem.TagList[0]; // Note: input items have precisely one tag; see HandleServerReceived().
            List <object> parameterList = new List <object>()
            {
                inputString, sourceTag
            };
            string       targetContext       = workingMemory.CurrentContext;
            string       targetID            = workingMemory.CurrentID;
            DialogueItem currentDialogueItem = FindCurrentDialogueItem();
            Boolean      itemProcessed       = false;

            if (currentDialogueItem != null)
            {
                if (currentDialogueItem is InputItem) // OK with type comparison here (InputItem is the only possibility).
                {
                    Boolean allowVisionInput = ((InputItem)currentDialogueItem).AllowVisionInput;
                    if ((sourceTag == AgentConstants.LISTENER_INPUT_TAG) ||
                        ((sourceTag == AgentConstants.VISION_INPUT_TAG) && allowVisionInput))
                    {
                        // Run the timeout timer only for those items that have the corresponding property:
                        itemProcessed = currentDialogueItem.Run(parameterList, out targetContext, out targetID);
                        if (itemProcessed)
                        {
                            busy = false;
                            if (targetContext != workingMemory.CurrentContext)
                            {
                                workingMemory.CurrentContext = targetContext;
                            }                                                                                                    // Triggers the ContextChangedEvent in working memory
                            else
                            {
                                workingMemory.CurrentID = targetID;
                            }                                            // Triggers the IDChangedEvent in working memory
                            return;
                        }
                    }
                }
            }
            if (!itemProcessed)  // No dialogue item found OR no dialogue matching the context found
            {
                List <Dialogue> alwaysAvailableDialogueList = GetAlwaysAvailableDialogues();
                foreach (Dialogue dialogue in alwaysAvailableDialogueList)
                {
                    DialogueItem dialogueItem = dialogue.DialogueItemList[0];
                    if (dialogueItem is InputItem) // Should be the case, but just to be sure:
                    {
                        Boolean allowVisionInput = ((InputItem)dialogueItem).AllowVisionInput;
                        if ((sourceTag == AgentConstants.LISTENER_INPUT_TAG) ||
                            ((sourceTag == AgentConstants.VISION_INPUT_TAG) && allowVisionInput))
                        {
                            itemProcessed = dialogueItem.Run(parameterList, out targetContext, out targetID);
                            if (itemProcessed)
                            {
                                workingMemory.CurrentContext = dialogue.Context; // Set the context here.
                                busy = false;
                                if (targetContext != workingMemory.CurrentContext)
                                {
                                    workingMemory.CurrentContext = targetContext;
                                }                                                                                                    // Triggers the ContextChangedEvent in working memory
                                else
                                {
                                    workingMemory.CurrentID = targetID;
                                }                                            // Triggers the IDChangedEvent in working memory
                                return;
                            }
                        }
                    }
                }
            }
            // In case no match has been found, either for the current dialogue or for any of the always available dialogues:
            // if the dialogue item has a customized error phrase, use it. Otherwise, use one of the default error phrases

            if (sourceTag == AgentConstants.VISION_INPUT_TAG)  // Do not trigger errors based on vision input
            {
                busy = false;
                return;
            }
            else  // Listener input
            {
                string failureResponsePhrase = GetFailureResponsePhrase();
                if (currentDialogueItem != null)
                {
                    if (currentDialogueItem is InputItem)  // A bit ugly with a typecast, but OK...
                    {
                        InputItem currentInputItem = (InputItem)currentDialogueItem;
                        if (currentInputItem.FailureResponsePatternList != null)
                        {
                            if (currentInputItem.FailureResponsePatternList.Count > 0)
                            {
                                failureResponsePhrase = currentInputItem.GetFailureResponsePhrase(randomNumberGenerator);
                            }
                        }
                    }
                }
                SendSpeechOutput(failureResponsePhrase);
                busy = false;  // to be removed here (see above).
            }
        }