|
| 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