Represents a single batch of text input to the service for analysis
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // List analyzers
            Analyzer[] supportedAnalyzers = null;
            try
            {
                supportedAnalyzers = ListAnalyzers();
                var analyzersAsJson = JsonConvert.SerializeObject(supportedAnalyzers, Formatting.Indented, jsonSerializerSettings);
                Console.WriteLine("Supported analyzers: " + analyzersAsJson);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
                Environment.Exit(1);
            }

            // Analyze text with all available analyzers
            var analyzeTextRequest = new AnalyzeTextRequest()
            {
                Language = "en",
                AnalyzerIds = supportedAnalyzers.Select(analyzer => analyzer.Id).ToArray(),
                Text = "Welcome to Microsoft Linguistic Analysis!"
            };

            try
            {
                var analyzeTextResults = AnalyzeText(analyzeTextRequest);
                var resultsAsJson = JsonConvert.SerializeObject(analyzeTextResults, Formatting.Indented, jsonSerializerSettings);
                Console.WriteLine("Analyze text results: " + resultsAsJson);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
                Environment.Exit(1);
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Analyze text synchronously.
 /// </summary>
 /// <param name="request">Analyze text request.</param>
 /// <returns>An array of analyze text result.</returns>
 private static AnalyzeTextResult[] AnalyzeText(AnalyzeTextRequest request)
 {
     try
     {
         return Client.AnalyzeTextAsync(request).Result;
     }
     catch (Exception exception)
     {
         throw new Exception("Failed to analyze text", exception as ClientException);
     }
 }