// Matt Text Analytics Part 7 public static void CallTextAnalyticsEntityAPI() { try { // Get the file name Console.WriteLine("Please enter a some text to analyze:"); var message = Console.ReadLine(); var document = new MultiLanguageInput() { Id = Guid.NewGuid().ToString(), Language = "en-US", Text = message }; var documentList = new List <MultiLanguageInput>(); documentList.Add(document); var query = new TextAnalyticsQuery(Constants.TEXT_ANALYTICS_PREVIEW_URL, Constants.TEXT_ANALYTICS_KEY, documentList.ToArray()); var result = TextAnalyticsService.callTextAnalyticsEntityAPI(query).Result; ExportJSON(JsonConvert.SerializeObject(result)); Console.WriteLine("\nPress Enter to exit "); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.ReadLine(); throw; } }
public static TextAnalyticsQuery SetLanguage(this TextAnalyticsQuery query, string lang) { foreach (var doc in query.Documents) { doc.Language = lang; } return(query); }
public static TextAnalyticsLanguageQuery ToTextAnalyticsLanguageQuery(this TextAnalyticsQuery query) { return(new TextAnalyticsLanguageQuery { TextAnalyticsKey = query.TextAnalyticsKey, TextAnalyticsEndpoint = query.TextAnalyticsEndpoint, Documents = query.Documents.Select(x => x.ConvertToRegularInput()).ToArray() }); }
public static async Task <EntitiesBatchResultV2dot1> callTextAnalyticsEntityAPI(TextAnalyticsQuery query) { var url = query.TextAnalyticsEndpoint + "/entities"; using (var bingClient = new BingHttpClient(query.TextAnalyticsKey)) { var documents = JsonConvert.SerializeObject(query); var content = new StringContent(documents, Encoding.UTF8, "application/json"); var httpResponseMessage = await bingClient.PostAsync(url, content); if (httpResponseMessage.IsSuccessStatusCode) { var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <EntitiesBatchResultV2dot1>(responseContent)); } else { throw new InvalidOperationException("An error occurred fetching the results from the service"); } } }