public void DetectLanguageBatchConvenience() { string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT"); string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY"); // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), new TextAnalyticsSubscriptionKeyCredential(subscriptionKey)); var inputs = new List <string> { "Hello world", "Bonjour tout le monde", "Hola mundo", ":) :( :D", }; Debug.WriteLine($"Detecting language for inputs:"); foreach (string input in inputs) { Debug.WriteLine($" {input}"); } #region Snippet:TextAnalyticsSample1DetectLanguagesConvenience DetectLanguageResultCollection results = client.DetectLanguages(inputs); #endregion int i = 0; foreach (DetectLanguageResult result in results) { Debug.WriteLine($"On document {inputs[i++]}:"); Debug.WriteLine($"Detected language: {result.PrimaryLanguage.Name}, with confidence {result.PrimaryLanguage.Score:0.00}."); } }
public void DetectLanguageBatchAdvanced() { string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT"); string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY"); // Instantiate a client that will be used to call the service. var client = new TextAnalyticsClient(new Uri(endpoint), subscriptionKey); var inputs = new List <DetectLanguageInput> { new DetectLanguageInput("1") { CountryHint = "us", Text = "Hello world" }, new DetectLanguageInput("2") { CountryHint = "fr", Text = "Bonjour tout le monde", }, new DetectLanguageInput("3") { CountryHint = "es", Text = "Hola mundo", }, new DetectLanguageInput("4") { CountryHint = "us", Text = ":) :( :D" } }; DocumentResultCollection <DetectedLanguage> results = client.DetectLanguages(inputs, new TextAnalyticsRequestOptions(showStatistics: true)); int i = 0; Debug.WriteLine($"Results of Azure Text Analytics \"Detect Language\" Model, version: \"{results.ModelVersion}\""); Debug.WriteLine(""); foreach (var result in results) { var document = inputs[i++]; Debug.WriteLine($"On document (Id={document.Id}, CountryHint=\"{document.CountryHint}\", Text=\"{document.Text}\"):"); Debug.WriteLine($" Detected language {result[0].Name} with confidence {result[0].Score:0.00}."); Debug.WriteLine($" Document statistics:"); Debug.WriteLine($" Character count: {result.Statistics.CharacterCount}"); Debug.WriteLine($" Transaction count: {result.Statistics.TransactionCount}"); Debug.WriteLine(""); } Debug.WriteLine($"Batch operation statistics:"); Debug.WriteLine($" Document count: {results.Statistics.DocumentCount}"); Debug.WriteLine($" Valid document count: {results.Statistics.ValidDocumentCount}"); Debug.WriteLine($" Invalid document count:{results.Statistics.InvalidDocumentCount}"); Debug.WriteLine($" Transaction count:{results.Statistics.TransactionCount}"); Debug.WriteLine(""); }
public void DetectLanguageBatch() { string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT"); string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY"); var client = new TextAnalyticsClient(new Uri(endpoint), subscriptionKey); #region Snippet:TextAnalyticsSample1DetectLanguagesBatch var inputs = new List <DetectLanguageInput> { new DetectLanguageInput("1", "Hello world") { CountryHint = "us", }, new DetectLanguageInput("2", "Bonjour tout le monde") { CountryHint = "fr", }, new DetectLanguageInput("3", "Hola mundo") { CountryHint = "es", }, new DetectLanguageInput("4", ":) :( :D") { CountryHint = "us", } }; DetectLanguageResultCollection results = client.DetectLanguages(inputs, new TextAnalyticsRequestOptions { IncludeStatistics = true }); #endregion int i = 0; Debug.WriteLine($"Results of Azure Text Analytics \"Detect Language\" Model, version: \"{results.ModelVersion}\""); Debug.WriteLine(""); foreach (DetectLanguageResult result in results) { DetectLanguageInput document = inputs[i++]; Debug.WriteLine($"On document (Id={document.Id}, CountryHint=\"{document.CountryHint}\", Text=\"{document.Text}\"):"); if (result.ErrorMessage != default) { Debug.WriteLine($" Document error: {result.ErrorMessage}."); } else { Debug.WriteLine($" Detected language {result.PrimaryLanguage.Name} with confidence {result.PrimaryLanguage.Score:0.00}."); Debug.WriteLine($" Document statistics:"); Debug.WriteLine($" Character count: {result.Statistics.CharacterCount}"); Debug.WriteLine($" Transaction count: {result.Statistics.TransactionCount}"); Debug.WriteLine(""); } } Debug.WriteLine($"Batch operation statistics:"); Debug.WriteLine($" Document count: {results.Statistics.DocumentCount}"); Debug.WriteLine($" Valid document count: {results.Statistics.ValidDocumentCount}"); Debug.WriteLine($" Invalid document count: {results.Statistics.InvalidDocumentCount}"); Debug.WriteLine($" Transaction count: {results.Statistics.TransactionCount}"); Debug.WriteLine(""); }