Skip to content

Commit 153927e

Browse files
authored
Merge pull request #371 from watson-developer-cloud/6673-natural-language-understanding-v1-examples
Add Natural Langauge Understanding V1 examples
2 parents 3908546 + 7aef7dc commit 153927e

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

IBM.Watson.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.Watson.LanguageTranslat
107107
EndProject
108108
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.Watson.NaturalLangaugeClassifier.v1.Examples", "examples\IBM.Watson.NaturalLangaugeClassifier.v1.Examples\IBM.Watson.NaturalLangaugeClassifier.v1.Examples.csproj", "{B74E72B5-E2C9-43EE-88D2-34315AF3AD33}"
109109
EndProject
110+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.Watson.NaturalLanguageUnderstanding.v1.Examples", "examples\IBM.Watson.NaturalLanguageUnderstanding.v1.Examples\IBM.Watson.NaturalLanguageUnderstanding.v1.Examples.csproj", "{0D0A16C3-CCBD-4072-BA81-40E015F0A062}"
111+
EndProject
110112
Global
111113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
112114
Debug|Any CPU = Debug|Any CPU
@@ -269,6 +271,10 @@ Global
269271
{B74E72B5-E2C9-43EE-88D2-34315AF3AD33}.Debug|Any CPU.Build.0 = Debug|Any CPU
270272
{B74E72B5-E2C9-43EE-88D2-34315AF3AD33}.Release|Any CPU.ActiveCfg = Release|Any CPU
271273
{B74E72B5-E2C9-43EE-88D2-34315AF3AD33}.Release|Any CPU.Build.0 = Release|Any CPU
274+
{0D0A16C3-CCBD-4072-BA81-40E015F0A062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
275+
{0D0A16C3-CCBD-4072-BA81-40E015F0A062}.Debug|Any CPU.Build.0 = Debug|Any CPU
276+
{0D0A16C3-CCBD-4072-BA81-40E015F0A062}.Release|Any CPU.ActiveCfg = Release|Any CPU
277+
{0D0A16C3-CCBD-4072-BA81-40E015F0A062}.Release|Any CPU.Build.0 = Release|Any CPU
272278
EndGlobalSection
273279
GlobalSection(SolutionProperties) = preSolution
274280
HideSolutionNode = FALSE
@@ -312,6 +318,7 @@ Global
312318
{D3FBC964-AF1B-4416-9FE8-8F0A511908D5} = {BE946662-3884-45E9-A3B1-B28F3081AD1B}
313319
{03B2FA0D-14C8-485C-8EE8-16715871E813} = {65D78D49-E54F-4952-A1D4-7C8D0EDAA1B3}
314320
{B74E72B5-E2C9-43EE-88D2-34315AF3AD33} = {5917402E-D9A2-4308-8A1A-9C0692939420}
321+
{0D0A16C3-CCBD-4072-BA81-40E015F0A062} = {89D715BF-7464-45FB-8DA0-9D7B46AB8C7F}
315322
EndGlobalSection
316323
GlobalSection(ExtensibilityGlobals) = postSolution
317324
SolutionGuid = {B9D9D17B-1C17-402F-B701-DC671528690A}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="IBM.Cloud.SDK.Core" Version="0.7.1" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\IBM.Watson.NaturalLanguageUnderstanding.v1\IBM.Watson.NaturalLanguageUnderstanding.v1.csproj" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* Copyright 2019 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.Cloud.SDK.Core.Util;
19+
using IBM.Watson.NaturalLanguageUnderstanding.v1.Model;
20+
using System;
21+
22+
namespace IBM.Watson.NaturalLanguageUnderstanding.v1.Examples
23+
{
24+
public class ServiceExample
25+
{
26+
string apikey = "{apikey}";
27+
string url = "{url}";
28+
string versionDate = "{versionDate}";
29+
private string 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.";
30+
private string modelId;
31+
32+
static void Main(string[] args)
33+
{
34+
ServiceExample example = new ServiceExample();
35+
36+
example.Analyze();
37+
example.ListModels();
38+
39+
Console.WriteLine("Examples complete. Press any key to close the application.");
40+
Console.ReadKey();
41+
}
42+
43+
#region Analyze
44+
public void Analyze()
45+
{
46+
TokenOptions tokenOptions = new TokenOptions()
47+
{
48+
IamApiKey = apikey,
49+
ServiceUrl = url
50+
};
51+
52+
NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService(tokenOptions, versionDate);
53+
54+
var features = new Features()
55+
{
56+
Keywords = new KeywordsOptions()
57+
{
58+
Limit = 8,
59+
Sentiment = true,
60+
Emotion = true
61+
},
62+
Categories = new CategoriesOptions()
63+
{
64+
Limit = 10
65+
}
66+
};
67+
68+
var result = service.Analyze(
69+
features: features,
70+
text: text,
71+
clean: true,
72+
fallbackToRaw: true,
73+
returnAnalyzedText: true,
74+
language: "en"
75+
);
76+
77+
Console.WriteLine(result.Response);
78+
}
79+
#endregion
80+
81+
#region Mangage Models
82+
public void ListModels()
83+
{
84+
TokenOptions tokenOptions = new TokenOptions()
85+
{
86+
IamApiKey = apikey,
87+
ServiceUrl = url
88+
};
89+
90+
NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService(tokenOptions, versionDate);
91+
92+
var result = service.ListModels();
93+
94+
Console.WriteLine(result.Response);
95+
}
96+
97+
public void DeleteModel()
98+
{
99+
TokenOptions tokenOptions = new TokenOptions()
100+
{
101+
IamApiKey = apikey,
102+
ServiceUrl = url
103+
};
104+
105+
NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService(tokenOptions, versionDate);
106+
107+
var result = service.DeleteModel(
108+
modelId: modelId
109+
);
110+
111+
Console.WriteLine(result.Response);
112+
}
113+
#endregion
114+
}
115+
}

0 commit comments

Comments
 (0)