BuildIt.CognitiveServices.CognitiveServiceClient.EntityLinkingApiRequestAsync C# (CSharp) Метод

EntityLinkingApiRequestAsync() публичный Метод

Entity Linking is a natural language processing tool to help analyzing text for your application
public EntityLinkingApiRequestAsync ( string subscriptionKey, string requestBody, string contentType = "text/plain", string selection = null, string offset = null ) : Task>
subscriptionKey string
requestBody string /// Request body ///
contentType string /// Media type of the body sent to the API. ///
selection string /// The specific word or phrase within the text that is to be entity linked ///
offset string /// The location (in offset by characters) of the selected word or phrase within the input text. ///
Результат Task>
        public async Task<ResultDto<EntityLinkingApiFeeds>> EntityLinkingApiRequestAsync(string subscriptionKey,
            string requestBody, string contentType = "text/plain",string selection = null,string offset = null)
        {
            var resultDto = new ResultDto<EntityLinkingApiFeeds>();
            try
            {
                var client = new HttpClient();
                //request header
                client.DefaultRequestHeaders.Add(Constants.SubscriptionTitle,subscriptionKey);
                HttpResponseMessage response;
                //request body
                var byteData = Encoding.UTF8.GetBytes(requestBody);
                var  parameters = string.Empty;
                var pNo = 0;
                if (!string.IsNullOrEmpty(selection))
                {
                    pNo++;
                    parameters += $"selection={selection}";
                }
                if (!string.IsNullOrEmpty(offset))
                {
                    pNo++;
                    parameters += pNo == 2 ? $"&offset={offset}" : $"offset={offset}";
                }
                
                var requestUrl = Constants.EntityLinkingApi + parameters;

                using (var content = new ByteArrayContent(byteData))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
                    response = await client.PostAsync(requestUrl, content);
                }

                var jsonResult = await response.Content.ReadAsStringAsync();

                var feed = JsonConvert.DeserializeObject<EntityLinkingApiFeeds>(jsonResult);


                resultDto.Result = feed;
                resultDto.ErrorMessage = feed.message;
                resultDto.StatusCode = feed.statusCode.ToString();
                resultDto.Success = string.IsNullOrEmpty(feed.message);
            }
            catch (Exception ex)
            {
                resultDto.ErrorMessage = ex.Message;
                resultDto.Exception = ex;
            }

            return resultDto;
        }