简体   繁体   English

从Unity中的Watson对话中获取意图和实体

[英]Get intents and entities from Watson Conversation in Unity

I have made a conversation workspace with intents, entities en dialog nodes. 我已经创建了一个包含意图,对话节点实体的对话工作区。 In Unity i have a connection with Watson conversation, the aforementioned conversation workspace, speech to text and text to speech connected. 在Unity中,我与Watson对话,上述对话工作区,语音到文本以及文本到语音的连接都有联系。 there is a weather intent in my conversation workspace and a city entity. 我的对话工作区和一个城市实体中有一个天气意图。 What i want to achieve with that is to recognize in Unity that the user says the intent #weather with the entity @city and pick out the @city word and show it in the application. 我要实现的目标是在Unity中认识到用户使用实体@city说了意图#weather,并选择了@city单词并将其显示在应用程序中。

For example: the user says: "What is the weather in Berlin?" 例如:用户说:“柏林的天气如何?” Then i want to be able to extract the word Berlin (the entity country) out of that sentence and display it in the console with a Debug.Log. 然后,我希望能够从该句子中提取单词Berlin(实体国家),并使用Debug.Log将其显示在控制台中。

I have everything set-up and working in Unity, I just dont know how to call out intents and entities in C#. 我已经在Unity中进行了所有设置和工作,但我只是不知道如何在C#中调用意图和实体。

I have found the following example from the Watson Cardboard vr example and tried to apply it in my application, but it doesn't work in my application. 我从Watson Cardboard vr示例中找到了以下示例,并尝试将其应用到我的应用程序中,但是在我的应用程序中不起作用。

public string city;

void OnMessage(MessageResponse resp, string customData)
{
    if (resp != null && (resp.intents.Length > 0 || resp.entities.Length > 0))
    {
        string intent = resp.intents[0].intent;
        Debug.Log("Intent: " + intent);

        if (intent == "weather")
        {
            //foreach (EntityResponse entity in resp.entities)
            foreach (RuntimeEntity entity in resp.entities)
            {
                Debug.Log("entityType: " + entity.entity + " , value: " + entity.value);
                if (entity.entity == "country")
                {
                    //zet spraak gelijk aan city || Voer actie uit
                    city = entity.entity;
                    Debug.Log("City: " + city);
                }
            }
        }
        else
        {
            Debug.Log("Failed to invoke OnMessage();");
        }
    }
}

Is there a way to get this to work with Watson 2.0.1 from the Unity Asset store or should this now be approached in a totally different way? 是否可以通过Unity Asset Store将其与Watson 2.0.1一起使用,还是现在应该以完全不同的方式来实现?

This is the code I have for the different Watson functions combined in 1 script. 这是我在1个脚本中组合的不同Watson函数的代码。 With this script I have set-up the conversation service, Speech-to-Text etc. And I wanna try to extract the intents and entities within a different script that contains the code at the top of this post. 使用此脚本,我设置了对话服务,语音转文本等。并且我想尝试在包含本文顶部代码的不同脚本中提取意图和实体。

If you are not getting a response back of any kind, check your workspace id to make sure it's correctly referencing the workspace with your intents, entities, and dialog. 如果没有收到任何响应,请检查您的工作区ID,以确保它正确地引用了您的意图,实体和对话框。

Here's an example from a demo I built. 这是我构建的演示中的示例。 I'm not sure how you are building your MessageResponse, but you need to make sure you are serializing/deserializing since you are working with JSON to and from Watson services. 我不确定您如何构建MessageResponse,但由于要使用往返于Watson服务的JSON,因此需要确保要进行序列化/反序列化。

private void OnMessage(object resp, Dictionary<string, object> customData)
     {
         fsData fsdata = null;
         fsResult r = _serializer.TrySerialize(resp.GetType(), resp, 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;
         (resp as Dictionary<string, object>).TryGetValue("context", out _tempContext);

         if (_tempContext != null)
             _context = _tempContext as Dictionary<string, object>;
         else
             Log.Debug("ExampleConversation.OnMessage()", "Failed to get context");
         //_waitingForResponse = false;

         //if we get a response, do something with it (find the intents, output text, etc.)
         if (resp != null && (messageResponse.intents.Length > 0 || messageResponse.entities.Length > 0))
         {
             string intent = messageResponse.intents[0].intent;
             //foreach (string WatsonResponse in messageResponse.output.text) {
             //    outputText += WatsonResponse + " ";
             //}


             outputText = messageResponse.output.text[0];
             Debug.Log("Intent/Output Text: " + intent + "/" + outputText);
             if (intent.Contains("exit")) {
                 stopListeningFlag = true;
             }
             CallTTS (outputText);
             outputText = "";
         }
     }

Near the bottom you can see I'm looking for an intent that contains "exit". 在底部附近,您可以看到我正在寻找包含“退出”的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Unity中的Watson对话服务获取$ context变量? - How to get $context variables from the Watson Conversation Service in Unity? Watson Conversation Unity-将第三方API数据添加到Watson Conversation / Assistant对话框中 - Watson Conversation Unity - Add third party API data to the Watson Conversation/Assistant dialog answer 通过C#中的API使用IBM Watson Conversation - Using IBM Watson Conversation from an API in C# 如何从javascript和C#中使用IBM Watson对话API - how to consume IBM watson conversation api from javascript and C# IBM Watson会话服务错误:无法从“方法组”转换为“conversation.onMessage” - IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage' Unity Android Intents - Unity Android Intents MS Bot 框架中意图的对话管理 - Conversation Management for Intents in MS Bot framework 从列表中的Unity3d,仅获取特定组件类型的实体 - Unity3d from a list, get only entities of specific component type 从对话索引时间戳获取日期时间 - Get date time from conversation index timestamp 使用Unity和SDK Watson进行人脸识别 - Face Recognition with Unity and SDK Watson
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM