Skip to content

Commit 3667ef4

Browse files
Merge branch 'develop' into develop
2 parents 72731f5 + fb81974 commit 3667ef4

27 files changed

+1835
-274
lines changed

.editorconfig

Lines changed: 0 additions & 11 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Change Log
22
==========
3+
## Version 0.14.0
4+
_2017-07-xx_
5+
* New: Abstracted `Natural Language Understanding` service.
6+
37
## Version 0.13.0
48
_2017-01-25_
59

Config.json.enc

496 Bytes
Binary file not shown.

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 138 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
using IBM.Watson.DeveloperCloud.Utilities;
2121
using IBM.Watson.DeveloperCloud.Logging;
2222
using System;
23+
using System.Collections.Generic;
24+
using System.Collections;
25+
using IBM.Watson.DeveloperCloud.DataTypes;
26+
using System.Reflection;
2327

2428
public class ExampleConversation : MonoBehaviour
2529
{
@@ -33,75 +37,146 @@ void Start()
3337
LogSystem.InstallDefaultReactors();
3438
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_ID");
3539

36-
Debug.Log("**********User: Hello!");
37-
MessageWithOnlyInput("Hello!");
38-
}
40+
//Debug.Log("**********User: Hello!");
41+
// MessageWithOnlyInput("Hello!");
3942

40-
private void MessageWithOnlyInput(string input)
41-
{
42-
if (string.IsNullOrEmpty(input))
43-
throw new ArgumentNullException("input");
44-
45-
m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, input);
46-
}
47-
48-
49-
private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
50-
{
51-
if (resp != null)
52-
{
53-
foreach (Intent mi in resp.intents)
54-
Debug.Log("Message Only intent: " + mi.intent + ", confidence: " + mi.confidence);
55-
56-
if (resp.output != null && resp.output.text.Length > 0)
57-
foreach (string txt in resp.output.text)
58-
Debug.Log("Message Only output: " + txt);
59-
60-
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
61-
Debug.Log(string.Format("**********User: {0}", questionStr));
62-
63-
MessageRequest messageRequest = new MessageRequest();
64-
messageRequest.InputText = questionStr;
65-
messageRequest.alternate_intents = m_UseAlternateIntents;
66-
messageRequest.ContextData = resp.context;
67-
68-
MessageWithFullMessageRequest(messageRequest);
43+
GetRawOutput("Hello");
6944
}
70-
else
45+
46+
private void GetRawOutput(string input)
7147
{
72-
Debug.Log("Message Only: Failed to invoke Message();");
48+
m_Conversation.Message(OnGetRawOutput, m_WorkspaceID, input);
7349
}
74-
}
75-
76-
private void MessageWithFullMessageRequest(MessageRequest messageRequest)
77-
{
78-
if (messageRequest == null)
79-
throw new ArgumentNullException("messageRequest");
80-
m_Conversation.Message(OnMessageWithFullRequest, m_WorkspaceID, messageRequest);
81-
}
8250

83-
private void OnMessageWithFullRequest(MessageResponse resp, string customData)
84-
{
85-
if (resp != null)
51+
private void OnGetRawOutput(object resp, string customData)
8652
{
87-
foreach (Intent mi in resp.intents)
88-
Debug.Log("Full Request intent: " + mi.intent + ", confidence: " + mi.confidence);
89-
90-
if (resp.output != null && resp.output.text.Length > 0)
91-
foreach (string txt in resp.output.text)
92-
Debug.Log("Full Request output: " + txt);
53+
if (!string.IsNullOrEmpty(customData))
54+
Debug.Log(customData);
55+
else
56+
Debug.Log("No raw data was received.");
57+
58+
if (resp != null)
59+
{
60+
Dictionary<string, object> respDict = resp as Dictionary<string, object>;
61+
object intents;
62+
respDict.TryGetValue("intents", out intents);
63+
64+
foreach(var intentObj in (intents as List<object>))
65+
{
66+
Dictionary<string, object> intentDict = intentObj as Dictionary<string, object>;
67+
68+
object intentString;
69+
intentDict.TryGetValue("intent", out intentString);
70+
71+
object confidenceString;
72+
intentDict.TryGetValue("confidence", out confidenceString);
73+
74+
Log.Debug("ExampleConversation", "intent: {0} | confidence {1}", intentString.ToString(), confidenceString.ToString());
75+
}
76+
}
77+
}
9378

94-
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
95-
Debug.Log(string.Format("**********User: {0}", questionStr));
79+
//private void MessageWithOnlyInput(string input)
80+
//{
81+
// if (string.IsNullOrEmpty(input))
82+
// throw new ArgumentNullException("input");
83+
84+
// m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, input);
85+
//}
86+
87+
88+
//private void OnMessageWithOnlyInput(object resp, string customData)
89+
//{
90+
// if (resp != null)
91+
// {
92+
// foreach (Intent mi in resp.intents)
93+
// Debug.Log("Message Only intent: " + mi.intent + ", confidence: " + mi.confidence);
94+
95+
// if (resp.output != null && resp.output.text.Length > 0)
96+
// foreach (string txt in resp.output.text)
97+
// Debug.Log("Message Only output: " + txt);
98+
99+
// if (resp.context != null)
100+
// {
101+
// if (!string.IsNullOrEmpty(resp.context.conversation_id))
102+
// Log.Debug("ExampleConversation", "Conversation ID: {0}", resp.context.conversation_id);
103+
// else
104+
// Log.Debug("ExampleConversation", "Conversation ID is null.");
105+
106+
// if (resp.context.system != null)
107+
// {
108+
// Log.Debug("ExampleConversation", "dialog_request_counter: {0}", resp.context.system.dialog_request_counter);
109+
// Log.Debug("ExampleConversation", "dialog_turn_counter: {0}", resp.context.system.dialog_turn_counter);
110+
111+
// if (resp.context.system.dialog_stack != null)
112+
// {
113+
// foreach (Dictionary<string, string> dialogNode in resp.context.system.dialog_stack)
114+
// foreach(KeyValuePair<string, string> node in dialogNode)
115+
// Log.Debug("ExampleConversation", "dialogNode: {0}", node.Value);
116+
// }
117+
// else
118+
// {
119+
// Log.Debug("ExampleConversation", "dialog stack is null");
120+
// }
121+
122+
// }
123+
// else
124+
// {
125+
// Log.Debug("ExampleConversation", "system is null.");
126+
// }
127+
128+
// }
129+
// else
130+
// {
131+
// Log.Debug("ExampleConversation", "Context is null");
132+
// }
133+
134+
// string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
135+
// Debug.Log(string.Format("**********User: {0}", questionStr));
136+
137+
// MessageRequest messageRequest = new MessageRequest();
138+
// messageRequest.InputText = questionStr;
139+
// messageRequest.alternate_intents = m_UseAlternateIntents;
140+
// messageRequest.ContextData = resp.context;
141+
142+
// MessageWithFullMessageRequest(messageRequest);
143+
// }
144+
// else
145+
// {
146+
// Debug.Log("Message Only: Failed to invoke Message();");
147+
// }
148+
//}
149+
150+
//private void MessageWithFullMessageRequest(MessageRequest messageRequest)
151+
//{
152+
// if (messageRequest == null)
153+
// throw new ArgumentNullException("messageRequest");
154+
// m_Conversation.Message(OnMessageWithFullRequest, m_WorkspaceID, messageRequest);
155+
//}
156+
157+
//private void OnMessageWithFullRequest(MessageResponse resp, string customData)
158+
//{
159+
// if (resp != null)
160+
// {
161+
// foreach (Intent mi in resp.intents)
162+
// Debug.Log("Full Request intent: " + mi.intent + ", confidence: " + mi.confidence);
163+
164+
// if (resp.output != null && resp.output.text.Length > 0)
165+
// foreach (string txt in resp.output.text)
166+
// Debug.Log("Full Request output: " + txt);
167+
168+
// string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
169+
// Debug.Log(string.Format("**********User: {0}", questionStr));
170+
171+
// MessageRequest messageRequest = new MessageRequest();
172+
// messageRequest.InputText = questionStr;
173+
// messageRequest.alternate_intents = m_UseAlternateIntents;
174+
// messageRequest.ContextData = resp.context;
175+
// }
176+
// else
177+
// {
178+
// Debug.Log("Full Request: Failed to invoke Message();");
179+
// }
180+
//}
96181

97-
MessageRequest messageRequest = new MessageRequest();
98-
messageRequest.InputText = questionStr;
99-
messageRequest.alternate_intents = m_UseAlternateIntents;
100-
messageRequest.ContextData = resp.context;
101-
}
102-
else
103-
{
104-
Debug.Log("Full Request: Failed to invoke Message();");
105-
}
106-
}
107182
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using FullSerializer;
19+
using IBM.Watson.DeveloperCloud.Logging;
20+
using IBM.Watson.DeveloperCloud.Services.NaturalLanguageUnderstanding.v1;
21+
using UnityEngine;
22+
23+
public class ExampleNaturalLanguageUnderstandingV1 : MonoBehaviour
24+
{
25+
NaturalLanguageUnderstanding m_NaturalLanguageUnderstanding = new NaturalLanguageUnderstanding();
26+
private static fsSerializer sm_Serializer = new fsSerializer();
27+
28+
void Start ()
29+
{
30+
LogSystem.InstallDefaultReactors();
31+
32+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to get models...");
33+
if (!m_NaturalLanguageUnderstanding.GetModels(OnGetModels))
34+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models.");
35+
36+
Parameters parameters = new Parameters()
37+
{
38+
text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.",
39+
return_analyzed_text = true,
40+
language = "en",
41+
features = new Features()
42+
{
43+
entities = new EntitiesOptions()
44+
{
45+
limit = 50,
46+
sentiment = true,
47+
emotion = true,
48+
},
49+
keywords = new KeywordsOptions()
50+
{
51+
limit = 50,
52+
sentiment = true,
53+
emotion = true
54+
}
55+
}
56+
};
57+
58+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to analyze...");
59+
if (!m_NaturalLanguageUnderstanding.Analyze(OnAnalyze, parameters))
60+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models.");
61+
}
62+
63+
private void OnGetModels(ListModelsResults resp, string customData)
64+
{
65+
fsData data = null;
66+
sm_Serializer.TrySerialize(resp, out data).AssertSuccess();
67+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "ListModelsResult: {0}", data.ToString());
68+
}
69+
70+
private void OnAnalyze(AnalysisResults resp, string customData)
71+
{
72+
fsData data = null;
73+
sm_Serializer.TrySerialize(resp, out data).AssertSuccess();
74+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "AnalysisResults: {0}", data.ToString());
75+
}
76+
}

Examples/ServiceExamples/Scripts/ExampleNaturalLanguageUnderstandingV1.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)