Successfully added
Azure Cognitive Services
by Patrik
Detecting the Language of Documents
To create a new TextAnalyticsClient to detect the language a document is written in, you need a Cognitive Services or Language service endpoint and credentials.
string endpoint = "<endpoint>"; string apiKey = "<apiKey>"; var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
To detect the language of a single document, use the DetectLanguage method. The detected language the document is written in will be returned in the DetectedLanguage object, which contains the language and the confidence that the service's prediction is correct.
string document = @"Este documento está escrito en un idioma diferente al Inglés. Tiene como objetivo demostrar cómo invocar el método de Detección de idioma del servicio de Text Analytics en Microsoft Azure."; try { Response<DetectedLanguage> response = client.DetectLanguage(document); DetectedLanguage language = response.Value; Console.WriteLine($"Detected language {language.Name} with confidence score {language.ConfidenceScore}."); } catch (RequestFailedException exception) { Console.WriteLine($"Error Code: {exception.ErrorCode}"); Console.WriteLine($"Message: {exception.Message}"); }
Source: azure-sdk-for-net/Sample1_DetectLanguage.md at main · Azure/azure-sdk-for-net
Referenced in:
Comments