Skip to content

Commit 98f288c

Browse files
committed
started examples
1 parent 81ebdf3 commit 98f288c

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 IBM.Watson.DeveloperCloud.Logging;
19+
using IBM.Watson.DeveloperCloud.Services.NaturalLanguageUnderstanding.v1;
20+
using UnityEngine;
21+
22+
public class ExampleNaturalLanguageUnderstandingV1 : MonoBehaviour
23+
{
24+
NaturalLanguageUnderstanding m_NaturalLanguageUnderstanding = new NaturalLanguageUnderstanding();
25+
26+
void Start ()
27+
{
28+
LogSystem.InstallDefaultReactors();
29+
30+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to get models...");
31+
if (!m_NaturalLanguageUnderstanding.GetModels(OnGetModels))
32+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models.");
33+
34+
Parameters parameters = new Parameters()
35+
{
36+
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.",
37+
url = null,
38+
html = null,
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+
//}
50+
};
51+
52+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to analyze...");
53+
if (!m_NaturalLanguageUnderstanding.Analyze(OnAnalyze, parameters))
54+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models.");
55+
}
56+
57+
private void OnGetModels(ListModelsResults resp, string customData)
58+
{
59+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "ListModelsResult: {0}", JsonUtility.ToJson(resp));
60+
}
61+
62+
private void OnAnalyze(AnalysisResults resp, string customData)
63+
{
64+
Log.Debug("ExampleNaturalLanguageUnderstandingV1", "AnalysisResults: {0}", JsonUtility.ToJson(resp));
65+
}
66+
}

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.

Scripts/Services/NaturalLanguageUnderstanding/v1/DataModels.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,12 @@ public class Parameters
494494
/// <summary>
495495
/// The HTML file to analyze
496496
/// </summary>
497+
[fsIgnore]
497498
public string html { get; set; }
498499
/// <summary>
499500
/// The web page to analyze
500501
/// </summary>
502+
[fsIgnore]
501503
public string url { get; set; }
502504
/// <summary>
503505
/// Specific features to analyze the document for

Scripts/Services/NaturalLanguageUnderstanding/v1/NaturalLanguageUnderstanding.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System;
2424
using System.Collections.Generic;
2525
using System.Text;
26+
using UnityEngine;
2627

2728
namespace IBM.Watson.DeveloperCloud.Services.NaturalLanguageUnderstanding.v1
2829
{
@@ -39,18 +40,18 @@ public class NaturalLanguageUnderstanding : IWatsonService
3940

4041
#region Analyze
4142
/// <summary>
42-
/// The callback used by AddEnvironment().
43+
/// The callback used by Analyze().
4344
/// </summary>
44-
/// <param name="resp">The Environment response.</param>
45+
/// <param name="resp">The AnalysisResult response.</param>
4546
/// <param name="customData">Optional custom data.</param>
4647
public delegate void OnAnalyze(AnalysisResults resp, string customData);
4748

4849
/// <summary>
4950
/// Creates a new environment. You can only create one environment per service instance.An attempt to create another environment
5051
/// will result in an error. The size of the new environment can be controlled by specifying the size parameter.
5152
/// </summary>
52-
/// <param name="callback">The OnAddEnvironment callback.</param>
53-
/// <param name="addEnvironmentData">The AddEnvironmentData.</param>
53+
/// <param name="callback">The OnAnalyze callback.</param>
54+
/// <param name="parameters">The analyze parameters.</param>
5455
/// <param name="customData">Optional custom data.</param>
5556
/// <returns>True if the call succeeds, false if the call is unsuccessful.</returns>
5657
public bool Analyze(OnAnalyze callback, Parameters parameters, string customData = default(string))
@@ -69,9 +70,12 @@ public class NaturalLanguageUnderstanding : IWatsonService
6970
req.Headers["Content-Type"] = "application/json";
7071
req.Headers["Accept"] = "application/json";
7172
req.Parameters["version"] = NaturalLanguageUnderstandingVersion.Version;
72-
string sendjson = Json.Serialize(parameters);
73-
req.Send = Encoding.UTF8.GetBytes(sendjson);
7473

74+
fsData data = null;
75+
fsResult r = sm_Serializer.TrySerialize(parameters, out data);
76+
77+
string sendjson = data.ToString();
78+
req.Send = Encoding.UTF8.GetBytes(sendjson);
7579
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_ANALYZE);
7680
if (connector == null)
7781
return false;

0 commit comments

Comments
 (0)