【问题标题】:On unity3d, my IBM chatbot can't recognize sequential在 unity3d 上,我的 IBM 聊天机器人无法识别顺序
【发布时间】:2017-10-26 18:35:36
【问题描述】:

这是另一个统一 watson sdk 问题。
我通过再次制作假对象解决了第一个谈话问题..
这是另一件事。

在我的聊天机器人中,如果有相同的意图,我可以看到顺序文本。

我必须更改或添加哪一行才能实现?

(另一个问题:我必须更改或添加哪一行才能在我的统一中引入“跳转到”方法?

using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
using IBM.Watson.DeveloperCloud.Utilities;
using System;
using System.Collections.Generic;
using UnityEngine;

class Watson : MonoBehaviour{    
static Credentials credentials;
static Conversation _conversation;
void Start()
{
    credentials = new Credentials("xx-xx-xx-xx-xx", "xx", "https://gateway.watsonplatform.net/conversation/api");
  //  credentials.Url = "";
    _conversation = new Conversation(credentials);

}
static Action<string, ManagerChat.Feel, bool> Act;
public static void GoMessage(string _str,Action<string, ManagerChat.Feel,bool> _act)
{

    if (!_conversation.Message(OnMessage, "xx-xx-xx-xx-xx", _str))
        Debug.Log("ExampleConversation Failed to message!");

    Act = _act;
}

static bool GetIntent(Dictionary<string, object> respDict)
{
    object intents;
    respDict.TryGetValue("intents", out intents);

    object intentString = new object();

    object confidenceString = new object();

    foreach (var intentObj in (intents as List<object>))
    {
        Dictionary<string, object> intentDict = intentObj as Dictionary<string, object>;

        intentDict.TryGetValue("intent", out intentString);


        intentDict.TryGetValue("confidence", out confidenceString);
    }
    string str = intentString as string;

    if (str == "6사용자_마무리")
        return true;

    return false;

}

static string GetOutput(Dictionary<string, object> respDict)
{
    object outputs;
    respDict.TryGetValue("output", out outputs);

    object output;
    (outputs as Dictionary<string, object>).TryGetValue("text", out output);

    string var = (output as List<object>)[0] as string;

    return var;
}

static ManagerChat.Feel GetEntities(Dictionary<string, object> respDict)
{
    object entities;
    respDict.TryGetValue("entities", out entities);

    List<object> entitieList = (entities as List<object>);

    if(entitieList.Count == 0)
    {
        return ManagerChat.Feel.Normal;
    }
    else
    {
        object entitie;
        (entitieList[0] as Dictionary<string, object>).TryGetValue("value", out entitie);
        ManagerChat.Feel feel = ManagerChat.Feel.NONE;

        string str = entitie as string;

        switch (str)
        {
            case "Happy":
                feel = ManagerChat.Feel.Happy;
                break;
            case "Expect":
                feel = ManagerChat.Feel.Expect;
                break;
            case "Born":
                feel = ManagerChat.Feel.Born;
                break;
            case "Sad":
                feel = ManagerChat.Feel.Sad;
                break;
            case "Surprise":
                feel = ManagerChat.Feel.Surprise;
                break;
            case "Normal":
                feel = ManagerChat.Feel.Normal;
                break;
            default:
                break;
        }

        return feel;
    }
}

static void OnMessage(object resp, string data)
{
    Dictionary<string, object> respDict = resp as Dictionary<string, object>;

  bool flag = (GetIntent(respDict));

    string output = (GetOutput(respDict));

   ManagerChat.Feel feel = GetEntities(respDict);
  //      Debug.Log(resp);
  //      Debug.Log(data);
        Act(output,feel, flag);
    }
}

【问题讨论】:

    标签: unity3d ibm-cloud ibm-watson watson-conversation


    【解决方案1】:

    我不太了解您关于顺序文本的问题,但我认为您可能会尝试在应用程序代码中做比需要更多的事情。 我将给出一个关于如何使用 sdk 的高级模式,看看是否能解决问题。我不是 Unity 开发人员,但无论使用哪种语言,模式都是一样的。 您只需向 Watson 提供用户的输入文本和现有的上下文变量,最重要的是系统上下文,但您创建的任何自定义上下文也很有价值。 然后,Watson 将返回一个 output.text 对象,您将其发布给用户,Watson 还返回一个更新的系统上下文。 接下来,用户键入新内容,您的应用程序会抓取该文本,并将其与他上次返回的上下文对象一起传递给 Watson,然后重复该过程。

    您不需要在应用程序代码中对跳转、顺序文本等进行任何操作,因为这一切都由 Watson 处理。

    我能想到的顺序片段的唯一功能是单个对话节点的响应变化。此功能意味着如果用户多次访问特定对话节点,您将给出不同的响应,如果有多个,则按顺序或随机顺序。它确实需要来自用户的多个输入,多次导航到同一个节点。这是为了给你的机器人一些变化,对于常见的输入如“hello”、“googbye”、“thanks”等最有价值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-13
      • 2019-02-15
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2022-06-15
      相关资源
      最近更新 更多