作者:俏巴
概述
阿里云自然语言处理(Natural Language Processing)是为各类企业及开发者提供的用于文本分析及挖掘的核心工具,旨在帮助用户高效的处理文本,已经广泛应用在电商、文化娱乐、金融、物流等行业客户的多项业务中,取得了良好的效果。这里主要针对目前官方文档中参考Demo使用SDK较老且本身中文打印输出异常的问题,提供包括SDK安装步骤+正常可用示例.NET Demo。
操作步骤
1、Nuget 安装aliyun-net-sdk-core
Install-Package aliyun-net-sdk-core -Version 1.5.3
2、测试Demo
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using System;
namespace NLPDemo
{
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
</span>{
<span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> Main(string[] args)
{
<span class="hljs-comment">// ak,sk 获取参考链接:https://yq.aliyun.com/articles/693979</span>
string accessKeyId = <span class="hljs-string">"******"</span>;
string accessKeySecret = <span class="hljs-string">"******"</span>;
IClientProfile profile = DefaultProfile.GetProfile(<span class="hljs-string">"cn-shanghai"</span>, accessKeyId, accessKeySecret);
IAcsClient client = <span class="hljs-keyword">new</span> DefaultAcsClient(profile);
string postBody = <span class="hljs-string">"{\"text\": \"China真丝韩都衣舍连衣裙\"}"</span>;
CommonRequest request = <span class="hljs-keyword">new</span> CommonRequest();
request.Domain = <span class="hljs-string">"nlp.cn-shanghai.aliyuncs.com"</span>;
request.UriPattern = <span class="hljs-string">"/nlp/api/wordpos/general"</span>;
request.Method = MethodType.POST;
request.SetContent(System.Text.Encoding.UTF8.GetBytes(postBody), <span class="hljs-string">"utf-8"</span>, FormatType.JSON);
request.AddHeadParameters(<span class="hljs-string">"x-acs-signature-method"</span>, <span class="hljs-string">"HMAC-SHA1"</span>);
request.AddHeadParameters(<span class="hljs-string">"x-acs-signature-nonce"</span>, System.Guid.NewGuid().ToString());
request.Action = <span class="hljs-string">"None"</span>;
request.Version = <span class="hljs-string">"2018-04-08"</span>;
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(response.Data);
Console.ReadKey();
}
}
}
3、测试结果
4、控制台功能快速测试
a、测试地址进入
b、功能快速测试