diff --git a/.gitignore b/.gitignore index d059840a2..d61164584 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,4 @@ exclude-filter.txt.meta /Travis/installUnity.sh.meta /Travis/README.md.meta /Travis/runTests.sh.meta -/Travis/TravisBuild.cs.meta \ No newline at end of file +/Travis/TravisBuild.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b3617bd..26f3d3684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ _2016-07-15_ * New: Added `Document Conversion` abstraction * New: Added `AlchemyData News` abstraction * New: Added `Retrieve and Rank` abstraction +* New: Added `Conversation` abstraction +* Fix: Added `LanguageTranslation` and `LanguageTranslator` ## Version 0.5.0 diff --git a/Config.json.enc b/Config.json.enc index c0e1d46cb..1b3c87c1d 100644 Binary files a/Config.json.enc and b/Config.json.enc differ diff --git a/Examples/ServiceExamples/Scripts/ExampleConversation.cs b/Examples/ServiceExamples/Scripts/ExampleConversation.cs old mode 100644 new mode 100755 index 9c40ee2c1..b2d6b0b2a --- a/Examples/ServiceExamples/Scripts/ExampleConversation.cs +++ b/Examples/ServiceExamples/Scripts/ExampleConversation.cs @@ -18,23 +18,28 @@ using UnityEngine; using System.Collections; using IBM.Watson.DeveloperCloud.Services.Conversation.v1; +using IBM.Watson.DeveloperCloud.Utilities; +using IBM.Watson.DeveloperCloud.Logging; public class ExampleConversation : MonoBehaviour { private Conversation m_Conversation = new Conversation(); - private string m_WorkspaceID = "25dfa8a0-0263-471b-8980-317e68c30488"; + private string m_WorkspaceID; private string m_Input = "Can you unlock the door?"; void Start () { - Debug.Log("User: " + m_Input); - m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage); + LogSystem.InstallDefaultReactors(); + m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_WorkspaceID"); + Debug.Log("User: " + m_Input); + + m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage); } - void OnMessage (DataModels.MessageResponse resp) + void OnMessage (MessageResponse resp) { if(resp != null) { - foreach(DataModels.MessageIntent mi in resp.intents) + foreach(MessageIntent mi in resp.intents) Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence); if(resp.output != null && !string.IsNullOrEmpty(resp.output.text)) diff --git a/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs new file mode 100755 index 000000000..5bb64d1e2 --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs @@ -0,0 +1,53 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using UnityEngine; +using System.Collections; +using IBM.Watson.DeveloperCloud.Services.ConversationExperimental.v1; +using IBM.Watson.DeveloperCloud.Logging; +using IBM.Watson.DeveloperCloud.Utilities; + +public class ExampleConversationExperimental : MonoBehaviour +{ + private ConversationExperimental m_Conversation = new ConversationExperimental(); + private string m_WorkspaceID; + private string m_Input = "Can you unlock the door?"; + + void Start () { + LogSystem.InstallDefaultReactors(); + m_WorkspaceID = Config.Instance.GetVariableValue("ConversationExperimentalV1_ID"); + Debug.Log("User: " + m_Input); + + m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage); + } + + void OnMessage (MessageResponse resp) + { + if(resp != null) + { + foreach(MessageIntent mi in resp.intents) + Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence); + + if(resp.output != null && !string.IsNullOrEmpty(resp.output.text)) + Debug.Log("response: " + resp.output.text); + } + else + { + Debug.Log("Failed to invoke Message();"); + } + } +} diff --git a/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs.meta b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs.meta new file mode 100755 index 000000000..1847201fd --- /dev/null +++ b/Examples/ServiceExamples/Scripts/ExampleConversationExperimental.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 200ef04a114ced34b8c25728d3980fc5 +timeCreated: 1468512254 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/ServiceExamples/ServiceExamples.unity b/Examples/ServiceExamples/ServiceExamples.unity index a767f8050..36445187f 100755 --- a/Examples/ServiceExamples/ServiceExamples.unity +++ b/Examples/ServiceExamples/ServiceExamples.unity @@ -653,6 +653,46 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 1 +--- !u!1 &1937656527 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1937656529} + - 114: {fileID: 1937656528} + m_Layer: 0 + m_Name: ExampleConversation + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1937656528 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1937656527} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 87040e721f2394a4a9f444ecbaf9d991, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1937656529 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1937656527} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 5 --- !u!1 &1979050314 GameObject: m_ObjectHideFlags: 0 diff --git a/Scripts/Editor/ConfigEditor.cs b/Scripts/Editor/ConfigEditor.cs index 9d528d0bf..e4ff80c13 100755 --- a/Scripts/Editor/ConfigEditor.cs +++ b/Scripts/Editor/ConfigEditor.cs @@ -64,7 +64,9 @@ private class ServiceSetup URL ="https://console.ng.bluemix.net/catalog/services/tradeoff-analytics/", ServiceID="TradeoffAnalyticsV1" }, new ServiceSetup() { ServiceName = "Personality Insights", ServiceAPI = "personality-insights/api", URL ="https://console.ng.bluemix.net/catalog/services/personality-insights/", ServiceID="PersonalityInsightsV2" }, - new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation-experimental/api", + //new ServiceSetup() { ServiceName = "Conversation (Experimental)", ServiceAPI = "conversation-experimental/api", + // URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationExperimentalV1" }, + new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation/api", URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" }, new ServiceSetup() { ServiceName = "RetrieveAndRank", ServiceAPI = "retrieve-and-rank/api", URL ="https://console.ng.bluemix.net/catalog/services/retrieve-and-rank/", ServiceID="RetrieveAndRankV1" }, diff --git a/Scripts/Services/Conversation-Experimental.meta b/Scripts/Services/Conversation-Experimental.meta new file mode 100755 index 000000000..e3bf45390 --- /dev/null +++ b/Scripts/Services/Conversation-Experimental.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 345481e35ff059f4ba7eb1cf98520d82 +folderAsset: yes +timeCreated: 1468597717 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs b/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs new file mode 100755 index 000000000..089ceca4b --- /dev/null +++ b/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs @@ -0,0 +1,203 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using System; +using System.Text; +using System.Collections.Generic; +using FullSerializer; +using MiniJSON; +using IBM.Watson.DeveloperCloud.Utilities; +using IBM.Watson.DeveloperCloud.Connection; +using IBM.Watson.DeveloperCloud.Logging; + +namespace IBM.Watson.DeveloperCloud.Services.ConversationExperimental.v1 +{ + /// + /// This class wraps the Watson Conversation service. + /// Conversation Service + /// + public class ConversationExperimental : IWatsonService + { + #region Public Types + /// + /// The callback for GetWorkspaces(). + /// + public delegate void OnGetWorkspaces(Workspaces workspaces); + /// + /// The callback for Message(). + /// + /// + public delegate void OnMessageCallback(bool success); + /// + /// The callback delegate for the Converse() function. + /// + /// The response object to a call to Converse(). + public delegate void OnMessage(MessageResponse resp); + + #endregion + + #region Public Properties + #endregion + + #region Private Data + private const string SERVICE_ID = "ConversationExperimentalV1"; + private static fsSerializer sm_Serializer = new fsSerializer(); + #endregion + + #region Message + private const string SERVICE_MESSAGE = "/v1/workspaces"; + /// + /// Message the specified workspaceId, input and callback. + /// + /// Workspace identifier. + /// Input. + /// Callback. + public bool Message(string workspaceId, string input, OnMessage callback) + { + if(string.IsNullOrEmpty(workspaceId)) + throw new ArgumentNullException("workspaceId"); + if(string.IsNullOrEmpty(input)) + throw new ArgumentNullException("input"); + if(callback == null) + throw new ArgumentNullException("callback"); + + RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE); + if(connector == null) + return false; + + string reqJson = "{{\"input\": {{\"text\": \"{0}\"}}}}"; + string reqString = string.Format(reqJson, input); + + MessageReq req = new MessageReq(); + req.Callback = callback; + req.Headers["Content-Type"] = "application/json"; + req.Headers["Accept"] = "application/json"; + req.Parameters["version"] = Version.VERSION; + req.Function = "/" + workspaceId + "/message"; + req.Send = Encoding.UTF8.GetBytes(reqString); + req.OnResponse = MessageResp; + + return connector.Send(req); + } + + private class MessageReq : RESTConnector.Request + { + public OnMessage Callback { get; set; } + } + + private void MessageResp(RESTConnector.Request req, RESTConnector.Response resp) + { + MessageResponse response = new MessageResponse(); + if (resp.Success) + { + try + { + fsData data = null; + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = response; + r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + } + catch (Exception e) + { + Log.Error("Conversation", "MessageResp Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (((MessageReq)req).Callback != null) + ((MessageReq)req).Callback(resp.Success ? response : null); + } + #endregion + + #region IWatsonService implementation + + public string GetServiceID() + { + return SERVICE_ID; + } + + public void GetServiceStatus(ServiceStatus callback) + { + if (Config.Instance.FindCredentials(SERVICE_ID) != null) + new CheckServiceStatus(this, callback); + else + { + if (callback != null && callback.Target != null) + { + callback(SERVICE_ID, false); + } + } + } + + private class CheckServiceStatus + { + private ConversationExperimental m_Service = null; + private ServiceStatus m_Callback = null; + private int m_ConversationCount = 0; + + public CheckServiceStatus(ConversationExperimental service, ServiceStatus callback) + { + m_Service = service; + m_Callback = callback; + + string customServiceID = Config.Instance.GetVariableValue(SERVICE_ID + "_ID"); + + //If custom classifierID is defined then we are using it to check the service health + if (!string.IsNullOrEmpty(customServiceID)) + { + + if (!m_Service.Message(customServiceID, "Ping", OnMessage)) + OnFailure("Failed to invoke Converse()."); + else + m_ConversationCount += 1; + } + else + { + OnFailure("Please define a workspace variable in config.json (" + SERVICE_ID + "_ID)"); + } + } + + private void OnMessage(MessageResponse resp) + { + if (m_ConversationCount > 0) + { + m_ConversationCount -= 1; + if (resp != null) + { + if (m_ConversationCount == 0 && m_Callback != null && m_Callback.Target != null) + m_Callback(SERVICE_ID, true); + } + else + OnFailure("ConverseResponse is null."); + } + } + + private void OnFailure(string msg) + { + Log.Error("Dialog", msg); + m_Callback(SERVICE_ID, false); + m_ConversationCount = 0; + } + }; + #endregion + } +} diff --git a/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs.meta b/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs.meta new file mode 100755 index 000000000..eb15c28ee --- /dev/null +++ b/Scripts/Services/Conversation-Experimental/Conversation-Experimental.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 99f7ad421e3bc7749a97320b1291bfde +timeCreated: 1468512048 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/Conversation-Experimental/DataModels.cs b/Scripts/Services/Conversation-Experimental/DataModels.cs new file mode 100755 index 000000000..c4b2ac9a5 --- /dev/null +++ b/Scripts/Services/Conversation-Experimental/DataModels.cs @@ -0,0 +1,403 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +using FullSerializer; + +namespace IBM.Watson.DeveloperCloud.Services.ConversationExperimental.v1 +{ + #region Workspaces + /// + /// Workspaces. + /// + [fsObject] + public class Workspaces + { + /// + /// Gets or sets the workspaces. + /// + /// The workspaces. + public Workspace[] workspaces { get; set; } + } + + /// + /// This data class is contained by Workspaces, it represents a single workspace. + /// + [fsObject] + public class Workspace + { + /// + /// Gets or sets the workspace identifier. + /// + /// The ID of the workspace. + public string workspace_id { get; set; } + /// + /// Gets or sets the date created + /// + /// The date created. + public string created { get; set; } + /// + /// Gets or sets the description of the workspace + /// + /// The description of the workspace. + public string description { get; set; } + /// + /// Gets or sets the name of the workspace. + /// + /// The name of the workspace. + public string name { get; set; } + /// + /// Gets or sets the language. + /// + /// The language of the workspace. + public string language { get; set; } + /// + /// Gets or sets the status. + /// + /// The status. + public string status { get; set; } + /// + /// Gets or sets the metadata. + /// + /// The metadata. + public object metadata { get; set; } + } + + #endregion + + #region Message + /// + /// Message response. + /// + [fsObject] + public class MessageResponse + { + /// + /// Gets or sets the intents. + /// + /// The intents. + public MessageIntent[] intents { get; set; } + /// + /// Gets or sets the entities. + /// + /// The entities. + public EntityExample[] entities { get; set; } + /// + /// Gets or sets the output. + /// + /// The output. + public Output output { get; set; } + /// + /// Gets or sets the context. + /// + /// The context. + public object context { get; set; } + } + #endregion + + #region Intent + /// + /// Intents. + /// + [fsObject] + public class Intents + { + /// + /// Gets or sets the intents. + /// + /// The intents. + public Intent[] intents { get; set; } + } + + /// + /// This data class is contained by Intents. It represents a single intent. + /// + [fsObject] + public class Intent + { + /// + /// Gets or sets the intent. + /// + /// The intent. + public string intent { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get;set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + } + + /// + /// Intent Examples. + /// + [fsObject] + public class Examples + { + /// + /// Gets or sets the examples. + /// + /// The examples. + public Example[] examples { get; set; } + } + + /// + /// This class is contained by IntentExamples. It represents a single IntentExample. + /// + [fsObject] + public class Example + { + /// + /// Gets or sets the text. + /// + /// The text. + public string text { get; set; } + /// + /// Gets or sets the entities. + /// + /// The entities. + public EntityExample entities { get; set; } + } + + /// + /// Entity example. + /// + [fsObject] + public class EntityExample + { + /// + /// Gets or sets the entity. + /// + /// The entity. + public string entity { get; set; } + /// + /// Gets or sets the value. + /// + /// The value. + public string value { get; set; } + /// + /// Gets or sets the location. + /// + /// The location. + public int[] location { get; set; } + } + #endregion + + #region Entities + /// + /// Entities. + /// + [fsObject] + public class Entities + { + /// + /// Gets or sets the entities. + /// + /// The entities. + public Entity[] entities { get; set; } + } + + /// + /// This class is contained by Entities. It represents a single entity. + /// + [fsObject] + public class Entity + { + /// + /// Gets or sets the entity. + /// + /// The entity. + public string entity { get; set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get; set; } + /// + /// Gets or sets a value indicating whether this is an open list. + /// + /// true if open list; otherwise, false. + public bool open_list { get; set; } + /// + /// Gets or sets the tags. + /// + /// The tags. + public string[] tags { get; set; } + } + + /// + /// Entity Values. + /// + [fsObject] + public class Values + { + /// + /// Gets or sets the value. + /// + /// The value. + public string value { get; set; } + /// + /// Gets or sets the synonyms. + /// + /// The synonyms. + public string[] synonyms { get; set; } + /// + /// Gets or sets the metadata. + /// + /// The metadata. + public object metadata { get; set; } + } + #endregion + + #region Dialog Nodes + /// + /// The Dialog nodes. + /// + [fsObject] + public class DialogNodes + { + /// + /// Gets or sets the dialog nodes. + /// + /// The dialog nodes. + public DialogNode[] dialog_nodes { get; set; } + } + + /// + /// This class is contained in DialogNodes. It represents a single DialogNode. + /// + [fsObject] + public class DialogNode + { + /// + /// Gets or sets the dialog node. + /// + /// The dialog node. + public string dialog_node { get; set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get; set; } + /// + /// Gets or sets the conditions. + /// + /// The conditions. + public string conditions { get; set; } + /// + /// Gets or sets the parent. + /// + /// The parent. + public string parent { get; set; } + /// + /// Gets or sets the previous sibling. + /// + /// The previous sibling. + public string previous_sibling { get; set; } + /// + /// Gets or sets the output. + /// + /// The output. + public Output output { get; set; } + /// + /// Gets or sets the context. + /// + /// The context. + public object context { get; set; } + /// + /// Gets or sets the go to. + /// + /// The go to. + public GoTo go_to { get; set; } + } + #endregion + + #region Common + /// + /// This class is contained by MessageIntents, it represents a single MessageIntent. + /// + [fsObject] + public class MessageIntent + { + /// + /// Gets or sets the intent. + /// + /// The intent. + public string intent { get; set; } + /// + /// Gets or sets the confidence. + /// + /// The confidence. + public double confidence { get; set; } + } + + /// + /// The output text of the conversation. + /// + [fsObject] + public class Output + { + /// + /// Gets or sets the text. + /// + /// The output text. + public string text { get; set; } + } + + /// + /// Go to. + /// + [fsObject] + public class GoTo + { + /// + /// Gets or sets the dialog node. + /// + /// The dialog node. + public string dialog_node { get; set; } + /// + /// Gets or sets the selector. + /// + /// The selector. + public string selector { get; set; } + /// + /// Gets or sets a value indicating whether this returns. + /// + /// true if m return; otherwise, false. + public bool m_return { get; set; } + } + #endregion + + #region Version + public class Version + { + public const string VERSION = "2016-05-19"; + } + #endregion +} diff --git a/Scripts/Services/Conversation-Experimental/DataModels.cs.meta b/Scripts/Services/Conversation-Experimental/DataModels.cs.meta new file mode 100755 index 000000000..2e043e133 --- /dev/null +++ b/Scripts/Services/Conversation-Experimental/DataModels.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5fa808d3d23b66042b2f4f2353820218 +timeCreated: 1465326470 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Services/Conversation/Conversation.cs b/Scripts/Services/Conversation/Conversation.cs old mode 100644 new mode 100755 index 4e2cca936..07581c342 --- a/Scripts/Services/Conversation/Conversation.cs +++ b/Scripts/Services/Conversation/Conversation.cs @@ -36,7 +36,7 @@ public class Conversation : IWatsonService /// /// The callback for GetWorkspaces(). /// - public delegate void OnGetWorkspaces(DataModels.Workspaces workspaces); + public delegate void OnGetWorkspaces(Workspaces workspaces); /// /// The callback for Message(). /// @@ -46,7 +46,7 @@ public class Conversation : IWatsonService /// The callback delegate for the Converse() function. /// /// The response object to a call to Converse(). - public delegate void OnMessage(DataModels.MessageResponse resp); + public delegate void OnMessage(MessageResponse resp); #endregion @@ -142,7 +142,7 @@ public bool Message(string workspaceId, string input, OnMessage callback) req.Callback = callback; req.Headers["Content-Type"] = "application/json"; req.Headers["Accept"] = "application/json"; - req.Parameters["version"] = DataModels.CONVERSATION_VERSION; + req.Parameters["version"] = Version.VERSION; req.Function = "/" + workspaceId + "/message"; req.Send = Encoding.UTF8.GetBytes(reqString); req.OnResponse = MessageResp; @@ -157,7 +157,7 @@ private class MessageReq : RESTConnector.Request private void MessageResp(RESTConnector.Request req, RESTConnector.Response resp) { - DataModels.MessageResponse response = new DataModels.MessageResponse(); + MessageResponse response = new MessageResponse(); if (resp.Success) { try @@ -237,29 +237,11 @@ public CheckServiceStatus(Conversation service, ServiceStatus callback) } else { -// if (!m_Service.GetWorkspaces(OnGetWorkspaces)) -// OnFailure("Failed to invoke GetDialogs()."); OnFailure("Please define a workspace variable in config.json (" + SERVICE_ID + "_ID)"); } } - /* - private void OnGetWorkspaces(DataModels.Workspaces workspaces) - { - if (m_Callback != null) - { - foreach (DataModels.Workspace workspace in workspaces.workspaces) - { - if (!m_Service.Message(workspace.workspace_id, "Hello", OnMessage)) - OnFailure("Failed to invoke Message()."); - else - m_ConversationCount += 1; - } - } - else - OnFailure("GetMessages() failed."); - } - */ - private void OnMessage(DataModels.MessageResponse resp) + + private void OnMessage(MessageResponse resp) { if (m_ConversationCount > 0) { diff --git a/Scripts/Services/Conversation/DataModels.cs b/Scripts/Services/Conversation/DataModels.cs index 124b358fc..db0b5f207 100755 --- a/Scripts/Services/Conversation/DataModels.cs +++ b/Scripts/Services/Conversation/DataModels.cs @@ -18,382 +18,386 @@ namespace IBM.Watson.DeveloperCloud.Services.Conversation.v1 { - public class DataModels { - public const string CONVERSATION_VERSION = "2016-05-19"; - #region Workspaces - /// - /// Workspaces. - /// - [fsObject] - public class Workspaces - { - /// - /// Gets or sets the workspaces. - /// - /// The workspaces. - public Workspace[] workspaces { get; set; } - } + #region Workspaces + /// + /// Workspaces. + /// + [fsObject] + public class Workspaces + { + /// + /// Gets or sets the workspaces. + /// + /// The workspaces. + public Workspace[] workspaces { get; set; } + } + /// + /// This data class is contained by Workspaces, it represents a single workspace. + /// + [fsObject] + public class Workspace + { + /// + /// Gets or sets the workspace identifier. + /// + /// The ID of the workspace. + public string workspace_id { get; set; } + /// + /// Gets or sets the date created + /// + /// The date created. + public string created { get; set; } + /// + /// Gets or sets the description of the workspace + /// + /// The description of the workspace. + public string description { get; set; } + /// + /// Gets or sets the name of the workspace. + /// + /// The name of the workspace. + public string name { get; set; } + /// + /// Gets or sets the language. + /// + /// The language of the workspace. + public string language { get; set; } /// - /// This data class is contained by Workspaces, it represents a single workspace. - /// - [fsObject] - public class Workspace - { - /// - /// Gets or sets the workspace identifier. - /// - /// The ID of the workspace. - public string workspace_id { get; set; } - /// - /// Gets or sets the date created - /// - /// The date created. - public string created { get; set; } - /// - /// Gets or sets the description of the workspace - /// - /// The description of the workspace. - public string description { get; set; } - /// - /// Gets or sets the name of the workspace. - /// - /// The name of the workspace. - public string name { get; set; } - /// - /// Gets or sets the language. - /// - /// The language of the workspace. - public string language { get; set; } - /// - /// Gets or sets the status. - /// - /// The status. - public string status { get; set; } - /// - /// Gets or sets the metadata. - /// - /// The metadata. - public object metadata { get; set; } - } + /// Gets or sets the status. + /// + /// The status. + public string status { get; set; } + /// + /// Gets or sets the metadata. + /// + /// The metadata. + public object metadata { get; set; } + } - #endregion + #endregion - #region Message - /// - /// Message response. - /// - [fsObject] - public class MessageResponse - { - /// - /// Gets or sets the intents. - /// - /// The intents. - public MessageIntent[] intents { get; set; } - /// - /// Gets or sets the entities. - /// - /// The entities. - public EntityExample[] entities { get; set; } - /// - /// Gets or sets the output. - /// - /// The output. - public Output output { get; set; } - /// - /// Gets or sets the context. - /// - /// The context. - public object context { get; set; } - } - #endregion + #region Message + /// + /// Message response. + /// + [fsObject] + public class MessageResponse + { + /// + /// Gets or sets the intents. + /// + /// The intents. + public MessageIntent[] intents { get; set; } + /// + /// Gets or sets the entities. + /// + /// The entities. + public EntityExample[] entities { get; set; } + /// + /// Gets or sets the output. + /// + /// The output. + public Output output { get; set; } + /// + /// Gets or sets the context. + /// + /// The context. + public object context { get; set; } + } + #endregion - #region Intent - /// - /// Intents. - /// - [fsObject] - public class Intents - { - /// - /// Gets or sets the intents. - /// - /// The intents. - public Intent[] intents { get; set; } - } + #region Intent + /// + /// Intents. + /// + [fsObject] + public class Intents + { + /// + /// Gets or sets the intents. + /// + /// The intents. + public Intent[] intents { get; set; } + } + /// + /// This data class is contained by Intents. It represents a single intent. + /// + [fsObject] + public class Intent + { /// - /// This data class is contained by Intents. It represents a single intent. - /// - [fsObject] - public class Intent - { - /// - /// Gets or sets the intent. - /// - /// The intent. - public string intent { get; set; } - /// - /// Gets or sets the created. - /// - /// The created. - public string created { get;set; } - /// - /// Gets or sets the description. - /// - /// The description. - public string description { get; set; } - } + /// Gets or sets the intent. + /// + /// The intent. + public string intent { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get;set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + } + /// + /// Intent Examples. + /// + [fsObject] + public class Examples + { /// - /// Intent Examples. - /// - [fsObject] - public class Examples - { - /// - /// Gets or sets the examples. - /// - /// The examples. - public Example[] examples { get; set; } - } + /// Gets or sets the examples. + /// + /// The examples. + public Example[] examples { get; set; } + } + /// + /// This class is contained by IntentExamples. It represents a single IntentExample. + /// + [fsObject] + public class Example + { /// - /// This class is contained by IntentExamples. It represents a single IntentExample. - /// - [fsObject] - public class Example - { - /// - /// Gets or sets the text. - /// - /// The text. - public string text { get; set; } - /// - /// Gets or sets the entities. - /// - /// The entities. - public EntityExample entities { get; set; } - } + /// Gets or sets the text. + /// + /// The text. + public string text { get; set; } + /// + /// Gets or sets the entities. + /// + /// The entities. + public EntityExample entities { get; set; } + } + /// + /// Entity example. + /// + [fsObject] + public class EntityExample + { + /// + /// Gets or sets the entity. + /// + /// The entity. + public string entity { get; set; } + /// + /// Gets or sets the value. + /// + /// The value. + public string value { get; set; } /// - /// Entity example. - /// - [fsObject] - public class EntityExample - { - /// - /// Gets or sets the entity. - /// - /// The entity. - public string entity { get; set; } - /// - /// Gets or sets the value. - /// - /// The value. - public string value { get; set; } - /// - /// Gets or sets the location. - /// - /// The location. - public int[] location { get; set; } - } - #endregion + /// Gets or sets the location. + /// + /// The location. + public int[] location { get; set; } + } + #endregion - #region Entities - /// - /// Entities. - /// - [fsObject] - public class Entities - { - /// - /// Gets or sets the entities. - /// - /// The entities. - public Entity[] entities { get; set; } - } + #region Entities + /// + /// Entities. + /// + [fsObject] + public class Entities + { + /// + /// Gets or sets the entities. + /// + /// The entities. + public Entity[] entities { get; set; } + } + /// + /// This class is contained by Entities. It represents a single entity. + /// + [fsObject] + public class Entity + { /// - /// This class is contained by Entities. It represents a single entity. - /// - [fsObject] - public class Entity - { - /// - /// Gets or sets the entity. - /// - /// The entity. - public string entity { get; set; } - /// - /// Gets or sets the description. - /// - /// The description. - public string description { get; set; } - /// - /// Gets or sets the created. - /// - /// The created. - public string created { get; set; } - /// - /// Gets or sets a value indicating whether this is an open list. - /// - /// true if open list; otherwise, false. - public bool open_list { get; set; } - /// - /// Gets or sets the tags. - /// - /// The tags. - public string[] tags { get; set; } - } + /// Gets or sets the entity. + /// + /// The entity. + public string entity { get; set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get; set; } + /// + /// Gets or sets a value indicating whether this is an open list. + /// + /// true if open list; otherwise, false. + public bool open_list { get; set; } + /// + /// Gets or sets the tags. + /// + /// The tags. + public string[] tags { get; set; } + } + /// + /// Entity Values. + /// + [fsObject] + public class Values + { /// - /// Entity Values. - /// - [fsObject] - public class Values - { - /// - /// Gets or sets the value. - /// - /// The value. - public string value { get; set; } - /// - /// Gets or sets the synonyms. - /// - /// The synonyms. - public string[] synonyms { get; set; } - /// - /// Gets or sets the metadata. - /// - /// The metadata. - public object metadata { get; set; } - } - #endregion + /// Gets or sets the value. + /// + /// The value. + public string value { get; set; } + /// + /// Gets or sets the synonyms. + /// + /// The synonyms. + public string[] synonyms { get; set; } + /// + /// Gets or sets the metadata. + /// + /// The metadata. + public object metadata { get; set; } + } + #endregion - #region Dialog Nodes - /// - /// The Dialog nodes. - /// - [fsObject] - public class DialogNodes - { - /// - /// Gets or sets the dialog nodes. - /// - /// The dialog nodes. - public DialogNode[] dialog_nodes { get; set; } - } + #region Dialog Nodes + /// + /// The Dialog nodes. + /// + [fsObject] + public class DialogNodes + { + /// + /// Gets or sets the dialog nodes. + /// + /// The dialog nodes. + public DialogNode[] dialog_nodes { get; set; } + } + /// + /// This class is contained in DialogNodes. It represents a single DialogNode. + /// + [fsObject] + public class DialogNode + { + /// + /// Gets or sets the dialog node. + /// + /// The dialog node. + public string dialog_node { get; set; } + /// + /// Gets or sets the description. + /// + /// The description. + public string description { get; set; } + /// + /// Gets or sets the created. + /// + /// The created. + public string created { get; set; } /// - /// This class is contained in DialogNodes. It represents a single DialogNode. - /// - [fsObject] - public class DialogNode - { - /// - /// Gets or sets the dialog node. - /// - /// The dialog node. - public string dialog_node { get; set; } - /// - /// Gets or sets the description. - /// - /// The description. - public string description { get; set; } - /// - /// Gets or sets the created. - /// - /// The created. - public string created { get; set; } - /// - /// Gets or sets the conditions. - /// - /// The conditions. - public string conditions { get; set; } - /// - /// Gets or sets the parent. - /// - /// The parent. - public string parent { get; set; } - /// - /// Gets or sets the previous sibling. - /// - /// The previous sibling. - public string previous_sibling { get; set; } - /// - /// Gets or sets the output. - /// - /// The output. - public Output output { get; set; } - /// - /// Gets or sets the context. - /// - /// The context. - public object context { get; set; } - /// - /// Gets or sets the go to. - /// - /// The go to. - public GoTo go_to { get; set; } - } - #endregion + /// Gets or sets the conditions. + /// + /// The conditions. + public string conditions { get; set; } + /// + /// Gets or sets the parent. + /// + /// The parent. + public string parent { get; set; } + /// + /// Gets or sets the previous sibling. + /// + /// The previous sibling. + public string previous_sibling { get; set; } + /// + /// Gets or sets the output. + /// + /// The output. + public Output output { get; set; } + /// + /// Gets or sets the context. + /// + /// The context. + public object context { get; set; } + /// + /// Gets or sets the go to. + /// + /// The go to. + public GoTo go_to { get; set; } + } + #endregion - #region Common - /// - /// This class is contained by MessageIntents, it represents a single MessageIntent. - /// - [fsObject] - public class MessageIntent - { - /// - /// Gets or sets the intent. - /// - /// The intent. - public string intent { get; set; } - /// - /// Gets or sets the confidence. - /// - /// The confidence. - public double confidence { get; set; } - } + #region Common + /// + /// This class is contained by MessageIntents, it represents a single MessageIntent. + /// + [fsObject] + public class MessageIntent + { + /// + /// Gets or sets the intent. + /// + /// The intent. + public string intent { get; set; } + /// + /// Gets or sets the confidence. + /// + /// The confidence. + public double confidence { get; set; } + } + /// + /// The output text of the conversation. + /// + [fsObject] + public class Output + { /// - /// The output text of the conversation. - /// - [fsObject] - public class Output - { - /// - /// Gets or sets the text. - /// - /// The output text. - public string text { get; set; } - } + /// Gets or sets the text. + /// + /// The output text. + public string text { get; set; } + } + /// + /// Go to. + /// + [fsObject] + public class GoTo + { /// - /// Go to. - /// - [fsObject] - public class GoTo - { - /// - /// Gets or sets the dialog node. - /// - /// The dialog node. - public string dialog_node { get; set; } - /// - /// Gets or sets the selector. - /// - /// The selector. - public string selector { get; set; } - /// - /// Gets or sets a value indicating whether this returns. - /// - /// true if m return; otherwise, false. - public bool m_return { get; set; } - } - #endregion + /// Gets or sets the dialog node. + /// + /// The dialog node. + public string dialog_node { get; set; } + /// + /// Gets or sets the selector. + /// + /// The selector. + public string selector { get; set; } + /// + /// Gets or sets a value indicating whether this returns. + /// + /// true if m return; otherwise, false. + public bool m_return { get; set; } } +#endregion + + #region Version + public class Version + { + public const string VERSION = "2016-07-11"; + } + #endregion } diff --git a/Scripts/UnitTests/TestConversation.cs b/Scripts/UnitTests/TestConversation.cs old mode 100644 new mode 100755 index 6a3525424..136f6e35c --- a/Scripts/UnitTests/TestConversation.cs +++ b/Scripts/UnitTests/TestConversation.cs @@ -25,12 +25,14 @@ public class TestConversation : UnitTest { private Conversation m_Conversation = new Conversation(); - private string m_WorkspaceID = "car_demo_1"; + private string m_WorkspaceID; private string m_Input = "Can you unlock the door?"; private bool m_MessageTested = false; public override IEnumerator RunTest() { + m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_ID"); + if (Config.Instance.FindCredentials(m_Conversation.GetServiceID()) == null) yield break; @@ -42,12 +44,12 @@ public override IEnumerator RunTest() } } - private void OnMessage(DataModels.MessageResponse resp) + private void OnMessage(MessageResponse resp) { Test(resp != null); if(resp != null) { - foreach(DataModels.MessageIntent mi in resp.intents) + foreach(MessageIntent mi in resp.intents) Log.Debug("TestConversation", "intent: " + mi.intent + ", confidence: " + mi.confidence); Log.Debug("TestConversation", "response: " + resp.output.text); } diff --git a/Scripts/UnitTests/TestConversationExperimental.cs b/Scripts/UnitTests/TestConversationExperimental.cs new file mode 100755 index 000000000..de3cfa5da --- /dev/null +++ b/Scripts/UnitTests/TestConversationExperimental.cs @@ -0,0 +1,59 @@ +/** +* Copyright 2015 IBM Corp. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +using UnityEngine; +using System.Collections; +using IBM.Watson.DeveloperCloud.UnitTests; +using IBM.Watson.DeveloperCloud.Services.ConversationExperimental.v1; +using IBM.Watson.DeveloperCloud.Utilities; +using IBM.Watson.DeveloperCloud.Logging; + +public class TestConversationExperimental// : UnitTest // Commented out integration test +{ + private ConversationExperimental m_Conversation = new ConversationExperimental(); + private string m_WorkspaceID; + private string m_Input = "Can you unlock the door?"; + private bool m_MessageTested = false; + + //public override IEnumerator RunTest() + //{ + // m_WorkspaceID = Config.Instance.GetVariableValue("ConversationExperimentalV1_WorkspaceID"); + + // if (Config.Instance.FindCredentials(m_Conversation.GetServiceID()) == null) + // yield break; + + // if(!m_MessageTested) + // { + // m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage); + // while(!m_MessageTested) + // yield return null; + // } + //} + + //private void OnMessage(MessageResponse resp) + //{ + // Test(resp != null); + // if(resp != null) + // { + // foreach(MessageIntent mi in resp.intents) + // Log.Debug("TestConversation", "intent: " + mi.intent + ", confidence: " + mi.confidence); + // Log.Debug("TestConversation", "response: " + resp.output.text); + // } + + // m_MessageTested = true; + //} +} diff --git a/Scripts/UnitTests/TestConversationExperimental.cs.meta b/Scripts/UnitTests/TestConversationExperimental.cs.meta new file mode 100755 index 000000000..04ab6f458 --- /dev/null +++ b/Scripts/UnitTests/TestConversationExperimental.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d8c32748263ad444ba213ebe06cc19a6 +timeCreated: 1468512255 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/exclude-filter.txt.meta b/exclude-filter.txt.meta new file mode 100755 index 000000000..3ef8cc146 --- /dev/null +++ b/exclude-filter.txt.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 381c436446f698440995e8ef40c04a56 +timeCreated: 1468522240 +licenseType: Pro +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: