예제 #1
0
        /// <summary>
        /// 文本分类
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public RES TextClassification(string input)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId  = secretId,
                    SecretKey = secretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile   httpProfile   = new HttpProfile();
                httpProfile.Endpoint      = ("nlp.ap-shanghai.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                NlpClient client = new NlpClient(cred, "ap-guangzhou", clientProfile);
                TextClassificationRequest req = new TextClassificationRequest();
                string strParams = JSON.ToJson(new { Text = input });
                req = TextClassificationRequest.FromJsonString <TextClassificationRequest>(strParams);
                TextClassificationResponse resp = client.TextClassification(req).
                                                  ConfigureAwait(false).GetAwaiter().GetResult();
                return(RES.OK(resp));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex.Message));
            }
        }
예제 #2
0
        /// <summary>
        /// 文本分类接口能够对用户输入的文本进行自动分类,将其映射到具体的类目上,用户只需要提供待分类的文本,而无需关注具体实现。
        ///
        /// 该功能基于千亿级大规模互联网语料和LSTM、BERT等深度神经网络模型进行训练,并持续迭代更新,以保证效果不断提升。
        ///
        /// 目前已提供:
        ///
        /// - 通用领域分类体系,包括15个分类类目,分别是汽车、科技、健康、体育、旅行、教育、职业、文化、军事、房产、娱乐、女性、奥运、财经以及其他,适用于通用的场景。
        ///
        /// - 新闻领域分类体系,包括37个一级分类类目,285个二级分类(详细请见 [类目体系映射表](https://cloud.tencent.com/document/product/271/36459)),已应用于腾讯新闻的文章分类。
        ///
        /// 更多垂直领域的分类体系即将推出,敬请期待。
        /// </summary>
        /// <param name="req"><see cref="TextClassificationRequest"/></param>
        /// <returns><see cref="TextClassificationResponse"/></returns>
        public TextClassificationResponse TextClassificationSync(TextClassificationRequest req)
        {
            JsonResponseModel <TextClassificationResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "TextClassification");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <TextClassificationResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }