Example #1
0
    public override AgentResponse DecodeResponse(EntityIntent ei)
    {
        AgentResponse agentResponse = new AgentResponse("This is a test.");

        agentResponse.responseTextOCEAN = TextOCEAN.A_pos;
        return(agentResponse);
    }
    public void AfterIntentFound(EntityIntent ei)
    {
        AgentResponse agentResponse = null;

        agentResponse = currentScenario.DecodeResponse(ei);

        agentsController.myNLU.GiveTextToUnderstand(agentsController.GetCurrentAgent(), agentResponse.responseText);

        if (agentResponse.clip != null)
        {
            watsonSpeaker.SpeakFromClip(agentResponse, agentsController.GetCurrentAgent());
        }
        else
        {
            Debug.Log("Clip is not saved before, generating new clip.");
            watsonSpeaker.SetTone(agentsController.GetCurrentAgent());
            watsonSpeaker.SetTextOCEANForCurrentText(agentResponse.responseTextOCEAN);
            watsonSpeaker.SpeakText(agentsController.GetCurrentAgent(), agentResponse.responseText);
        }
    }
Example #3
0
 public override AgentResponse DecodeResponse(EntityIntent ei)
 {
     return(null);
 }
Example #4
0
    public override AgentResponse DecodeResponse(EntityIntent ei)
    {
        // get textOCEAN from agent
        textOCEAN = agentsController.GetCurrentAgent().DetermineTextOCEAN();

        AgentResponse agentResponse = new AgentResponse("EMPTY");

        agentResponse.responseTextOCEAN = textOCEAN;

        {
            switch (ei.Intent)
            {
            case "ComeFrom":     // 01
                currentStateNo             = 1;
                agentResponse.responseText = GetPassportText(textOCEAN, 1);
                cs.SetHelpScreen(GeComputerScreentText(2));
                break;

            case "ShowPassport":     // 02
                currentStateNo = 2;
                if (currentPassport.hasPassport)
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 201);
                    if (!currentPassport.correctPassportExpire || !currentPassport.correctPassportStart)
                    {
                        cs.SetHelpScreen(GeComputerScreentText(3));
                    }
                    else if (!currentPassport.correctVisaExpire)
                    {
                        cs.SetHelpScreen(GeComputerScreentText(5));
                    }
                    else if (!currentPassport.correctVisaStart)
                    {
                        cs.SetHelpScreen(GeComputerScreentText(6));
                    }
                    else
                    {
                        // valid passport
                        cs.SetHelpScreen(GeComputerScreentText(10));
                    }

                    cs.SetPassportToScreen(currentPassport);
                    cs.SetPassportToPaper(currentPassport);

                    agentsController.GetCurrentAgent().SetAnimation(2);
                    gotPassportFromAgent = true;
                }
                else
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 202);
                    cs.SetHelpScreen(GeComputerScreentText(3));
                }
                break;

            case "PassportInvalid":     // 03
                currentStateNo             = 3;
                agentResponse.responseText = GetPassportText(textOCEAN, 3);
                cs.SetHelpScreen(GeComputerScreentText(4));
                break;

            case "ContactEmbassy":     // 04 END CASE
                currentStateNo             = 4;
                agentResponse.responseText = GetPassportText(textOCEAN, 4);
                cs.SetHelpScreen("The passenger is going to contact embassy.");
                if (gotPassportFromAgent)
                {
                    armsAnim.SetInteger("ArmNo", 2);
                    gotPassportFromAgent = false;
                }
                break;

            case "VisaExpired":     // 05
                currentStateNo             = 5;
                agentResponse.responseText = GetPassportText(textOCEAN, 3);
                cs.SetHelpScreen(GeComputerScreentText(4));
                break;

            case "VisaDidNotStart":     // 06
                currentStateNo             = 6;
                agentResponse.responseText = GetPassportText(textOCEAN, 3);
                if (currentPassport.daysUntilStartVisa == 1)
                {
                    cs.SetHelpScreen(GeComputerScreentText(8));
                }
                else
                {
                    cs.SetHelpScreen(GeComputerScreentText(7));
                }
                break;

            case "ReturnAndBack":     // 07
                currentStateNo             = 7;
                agentResponse.responseText = GetPassportText(textOCEAN, 3);
                cs.SetHelpScreen("The passenger is going to return and come back when his/her visa starts.");
                if (gotPassportFromAgent)
                {
                    armsAnim.SetInteger("ArmNo", 2);
                    gotPassportFromAgent = false;
                }
                break;

            case "WaitAtAirport":     // 08
                currentStateNo             = 8;
                agentResponse.responseText = GetPassportText(textOCEAN, 8);
                cs.SetHelpScreen("The passenger is going to wait at the airport.");
                if (gotPassportFromAgent)
                {
                    armsAnim.SetInteger("ArmNo", 2);
                    gotPassportFromAgent = false;
                }
                break;

            case "CountAsValid":     // 09
                currentStateNo             = 9;
                agentResponse.responseText = GetPassportText(textOCEAN, 9);
                cs.SetHelpScreen(GeComputerScreentText(10));
                break;

            case "VisitReason":     // 10
                currentStateNo             = 10;
                agentResponse.responseText = GetPassportText(textOCEAN, 10);
                if (currentPassport.correctVisaType)
                {
                    cs.SetHelpScreen(GeComputerScreentText(12));
                }
                else
                {
                    cs.SetHelpScreen(GeComputerScreentText(11));
                }
                break;

            case "DifferentVisa":     // 11
                currentStateNo             = 11;
                agentResponse.responseText = GetPassportText(textOCEAN, 3);
                cs.SetHelpScreen(GeComputerScreentText(4));
                break;

            case "HowLong":     // 12
                currentStateNo = 12;
                if (currentPassport.stayDuration < 30)
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1201);
                }
                else
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1202);
                }

                if (DateTime.Now.AddDays(currentPassport.stayDuration).CompareTo(currentPassport.visaExpire) > 0)
                {
                    cs.SetHelpScreen(GeComputerScreentText(13));
                }
                else
                {
                    cs.SetHelpScreen(GeComputerScreentText(14));
                }
                break;

            case "CannotStay":     // 13
                currentStateNo             = 13;
                agentResponse.responseText = GetPassportText(textOCEAN, 13);
                cs.SetHelpScreen(GeComputerScreentText(14));
                break;

            case "Occupation":     // 14
                currentStateNo = 14;
                if (currentPassport.hasOccupation)
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1401);
                    cs.SetHelpScreen(GeComputerScreentText(15));
                }
                else
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1402);
                    cs.SetHelpScreen(GeComputerScreentText(17));
                }
                break;

            case "ReturnTicket":     // 15
                currentStateNo = 15;
                if (currentPassport.hasReturnTicket)
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1501);
                    cs.SetHelpScreen(GeComputerScreentText(16));
                }
                else
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1502);
                    cs.SetHelpScreen(GeComputerScreentText(17));
                }
                break;

            case "Success":     // 16
                currentStateNo             = 16;
                agentResponse.responseText = GetPassportText(textOCEAN, 16);
                cs.SetHelpScreen("The passenger is entering the country");
                if (gotPassportFromAgent)
                {
                    armsAnim.SetInteger("ArmNo", 3);
                    gotPassportFromAgent = false;
                }
                break;

            case "HaveBudget":     // 17
                currentStateNo = 17;
                if (currentPassport.hasBudget)
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1701);
                    cs.SetHelpScreen(GeComputerScreentText(18));
                }
                else
                {
                    agentResponse.responseText = GetPassportText(textOCEAN, 1702);
                    cs.SetHelpScreen(GeComputerScreentText(19));
                }
                break;

            case "BuyTicket":     // 18
                currentStateNo             = 18;
                agentResponse.responseText = GetPassportText(textOCEAN, 18);
                cs.SetHelpScreen(GeComputerScreentText(16));
                break;

            case "NoBudget":     // 19
                currentStateNo             = 19;
                agentResponse.responseText = GetPassportText(textOCEAN, 19);
                cs.SetHelpScreen("The passenger is not going to enter the country");
                if (gotPassportFromAgent)
                {
                    armsAnim.SetInteger("ArmNo", 2);
                    gotPassportFromAgent = false;
                }
                break;

            default:
                agentResponse.responseText = "Sorry, I did not understand.";
                break;
            }
        }

        agentResponse.clip = Resources.Load <AudioClip>("0_SOUNDDB/John/" + currentDictionaryString);

        return(agentResponse);
    }
    private void OnMessage(object response, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleAssistant.OnMessage()", "Response: {0}", customData["json"].ToString());

        //  Convert resp to fsdata
        fsData   fsdata = null;
        fsResult r      = _serializer.TrySerialize(response.GetType(), response, out fsdata);

        if (!r.Succeeded)
        {
            throw new WatsonException(r.FormattedMessages);
        }

        //  Convert fsdata to MessageResponse
        MessageResponse messageResponse = new MessageResponse();
        object          obj             = messageResponse;

        r = _serializer.TryDeserialize(fsdata, obj.GetType(), ref obj);
        if (!r.Succeeded)
        {
            throw new WatsonException(r.FormattedMessages);
        }

        //  Set context for next round of messaging
        object _tempContext = null;

        (response as Dictionary <string, object>).TryGetValue("context", out _tempContext);

        if (_tempContext != null)
        {
            _context = _tempContext as Dictionary <string, object>;
        }
        else
        {
            Log.Debug("ExampleAssistant.OnMessage()", "Failed to get context");
        }

        //  Get entity
        object tempEntitiesObj = null;
        string entity          = "";

        (response as Dictionary <string, object>).TryGetValue("entities", out tempEntitiesObj);
        if ((tempEntitiesObj as List <object>).Count > 0)
        {
            object tempIntentObj = (tempEntitiesObj as List <object>)[0];
            object tempIntent    = null;
            (tempIntentObj as Dictionary <string, object>).TryGetValue("value", out tempIntent);
            entity = tempIntent.ToString();
        }

        //  Get intent
        object tempIntentsObj = null;
        string intent         = "";

        (response as Dictionary <string, object>).TryGetValue("intents", out tempIntentsObj);
        if ((tempIntentsObj as List <object>).Count > 0)
        {
            object tempIntentObj = (tempIntentsObj as List <object>)[0];
            object tempIntent    = null;
            (tempIntentObj as Dictionary <string, object>).TryGetValue("intent", out tempIntent);
            intent = tempIntent.ToString();
        }

        EntityIntent ei = new EntityIntent();

        ei.Entity = entity;
        ei.Intent = intent;
        CallAfterRecognition(ei);

        // Log.Debug("ExampleAssistant.OnMessage()", "intent: {0}", intent);

        _recognizeFinished = true;
    }
 private void CallAfterRecognition(EntityIntent e)
 {
     mainLogic.AfterIntentFound(e);
 }
 public abstract AgentResponse DecodeResponse(EntityIntent ei);
Example #8
0
    public override AgentResponse DecodeResponse(EntityIntent ei)
    {
        // get textOCEAN from agent
        textOCEAN = agentsController.GetCurrentAgent().DetermineTextOCEAN();

        AgentResponse agentResponse = new AgentResponse("EMPTY");

        agentResponse.responseTextOCEAN = textOCEAN;

        print("decoding: " + ei.Intent + " * " + textOCEAN);

        switch (ei.Intent)
        {
        case "ProductList":     // 01
            currentStateNo = 1;
            if (currentlyOrdering == CurrentlyOrdering.BURGER)
            {
                agentResponse.responseText = GetFastFoodText(textOCEAN, 2);
            }
            else if (currentlyOrdering == CurrentlyOrdering.DRINK)
            {
                agentResponse.responseText = GetFastFoodText(textOCEAN, 3);
            }
            else if (currentlyOrdering == CurrentlyOrdering.SIDE)
            {
                agentResponse.responseText = GetFastFoodText(textOCEAN, 4);
            }
            break;

        case "BurgerList":     // 02
            currentStateNo             = 2;
            agentResponse.responseText = GetFastFoodText(textOCEAN, 2);
            break;

        case "DrinkList":     // 03
            currentStateNo             = 3;
            agentResponse.responseText = GetFastFoodText(textOCEAN, 3);
            break;

        case "SideList":     // 04
            currentStateNo             = 4;
            agentResponse.responseText = GetFastFoodText(textOCEAN, 4);
            break;

        case "WantProduct":     // 05 - 06 - 07
            productId = GetProductId(ei.Entity);
            if (productId != -1)
            {
                if (currentStateNo == 9)
                {
                    currentStateNo             = 9;
                    agentResponse.responseText = GetFastFoodText(textOCEAN, 10);
                    agentResponse.responseText = agentResponse.responseText.Replace("%product", "" + productNames[productId]);
                }
                else
                {
                    if (productId == 0 || productId == 1 || productId == 2 || productId == 3)
                    {
                        // this is a burger
                        // check if it is in menu
                        menuId = CheckProducInMenu(productId);
                        if (menuId != -1)
                        {
                            currentStateNo             = 5;
                            agentResponse.responseText = GetFastFoodText(textOCEAN, 5);
                            agentResponse.responseText = agentResponse.responseText.Replace("%menu", menuNames[menuId]);
                            agentResponse.responseText = agentResponse.responseText.Replace("%price", "" + menuPrices[menuId]);
                        }
                        else
                        {
                            currentStateNo = 6;
                            AddProductToOrder(productId, false);     // it is not in menu, so add it
                            agentResponse.responseText = GetFastFoodText(textOCEAN, 6);
                            currentlyOrdering          = CurrentlyOrdering.DRINK;
                        }
                    }
                    else if (productId == 4 || productId == 5 || productId == 6)
                    {
                        // this is a drink

                        askedIfLarge = true;
                        agentResponse.responseText = GetFastFoodText(textOCEAN, 8);

                        currentlyOrdering = CurrentlyOrdering.SIDE;
                    }
                    else
                    {
                        // this ia a side meal

                        currentlyOrdering = CurrentlyOrdering.BURGER;
                    }
                }
            }
            else
            {
                // we do not sell this.
                currentStateNo             = 7;
                agentResponse.responseText = GetFastFoodText(textOCEAN, 7);
                agentResponse.responseText = agentResponse.responseText.Replace("%product", ei.Entity);
            }
            break;

        case "Yes":
            if (currentStateNo == 5)
            {
                currentStateNo             = 8;
                agentResponse.responseText = GetFastFoodText(textOCEAN, 8);
                agentResponse.responseText = agentResponse.responseText.Replace("%price", "" + (menuPrices[menuId] + 2f));
            }
            else if (currentStateNo == 8)    // make selection large!
            {
                currentStateNo             = 9;
                agentResponse.responseText = GetFastFoodText(textOCEAN, 9);
                AddMenuToOrder(menuId, true);
            }
            else
            {
                agentResponse.responseText = "Yes to what?";
            }
            break;

        case "No":
            if (currentStateNo == 8)
            {
                currentStateNo             = 9;
                agentResponse.responseText = GetFastFoodText(textOCEAN, 9);
                AddMenuToOrder(menuId, false);
            }
            else if (currentStateNo == 9)
            {
                currentStateNo             = 11;
                agentResponse.responseText = GetFastFoodText(textOCEAN, 11);
                agentResponse.responseText = agentResponse.responseText.Replace("%price", "" + totalPrice);
            }
            break;

        case "CreditCard":
            // play credit animation
            currentStateNo             = 12;
            agentResponse.responseText = GetFastFoodText(textOCEAN, 12);
            break;

        case "Cash":
            // play cash animation
            currentStateNo             = 12;
            agentResponse.responseText = GetFastFoodText(textOCEAN, 12);
            break;

        default:
            agentResponse.responseText = "ERROR! " + ei.Intent;
            break;
        }

        return(agentResponse);
    }