public async Task TextAnalyticsAsync(string inputText)
{
//TextAnalyticsReplyBody text = new TextAnalyticsReplyBody();
//text.documents[0].id = DateTime.Now.ToString();
//text.documents[0].
//text.text = inputText;
//text.id = DateTime.Now.ToString();
//var jsonString = JsonConvert.SerializeObject(text);
var detectLanguage = " {\"documents\": [{ \"id\":\"" + DateTime.Now + "\", \"text\":\"" + inputText + "\"}]}";
var textAnalytics = new AzureMachineLearningTextAnalytics();
BatchInputV2 batch = new BatchInputV2()
{
Documents = new List<InputV2>() { }
};
var languageResult =
await
textAnalytics.DetectLanguageWithHttpMessagesAsync(detectLanguage, 1, null,
Constants.TextAnalyticsKey, batch);
//HTTPClient
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Constants.TextAnalyticsKey);
//request parameters
var uri = $"https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/languages?";
HttpResponseMessage response;
var cognitiveService1 = new CognitiveServiceClient();
var result1 = await cognitiveService1.DetectLanguageApiRequestAsync(Constants.TextAnalyticsKey, detectLanguage);
// Request body
byte[] byteData = Encoding.UTF8.GetBytes(detectLanguage);
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response = await client.PostAsync(uri, content);
}
var jsonResult = await response.Content.ReadAsStringAsync();
var feed = JsonConvert.DeserializeObject<TextAnalyticsReplyBody>(jsonResult);
//*****************************************
//continue call keyPhrases API
var detectkeyPhrases = " {\"documents\": [{ \"id\":\"" + DateTime.Now + "\", \"text\":\"" + inputText + "\", \"language\": \"" + IsoName + "\" }]}";
var keyPhrasesUri = "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases?";
HttpResponseMessage response2;
//var cognitiveService = new CognitiveServiceClient();
//var result = await cognitiveService.KeyPhrasesApiRequestAsync(Constants.TextAnalyticsKey, detectkeyPhrases);
// Request body
byte[] byteData2 = Encoding.UTF8.GetBytes(detectkeyPhrases);
using (var content = new ByteArrayContent(byteData2))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response2 = await client.PostAsync(keyPhrasesUri, content);
}
var jsonResult2 = await response2.Content.ReadAsStringAsync();
var feed2 = JsonConvert.DeserializeObject<DetectkeyPhrases>(jsonResult2);
//******************************
//continue call sentiment API
var detectSentiment = " {\"documents\": [{ \"id\":\"" + DateTime.Now + "\", \"text\":\"" + inputText + "\", \"language\": \"" + IsoName + "\" }]}";
var SentimentUri = "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?";
HttpResponseMessage response3;
var cognitiveService = new CognitiveServiceClient();
var result = await cognitiveService.SentimentApiRequestAsync(Constants.TextAnalyticsKey, detectSentiment);
// Request body
byte[] byteData3 = Encoding.UTF8.GetBytes(detectSentiment);
using (var content = new ByteArrayContent(byteData3))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response3 = await client.PostAsync(SentimentUri, content);
}
var jsonResult3 = await response3.Content.ReadAsStringAsync();
var feed3 = JsonConvert.DeserializeObject<Sentiment>(jsonResult3);
AnalysisResult(feed);
AnalysisKeyPhraseResult(feed2);
AnalysisSentimentResult(feed3);
}