private async Task <double?> MakeAnalysisRequest(string text) { LanguageBatchResult result = await client.DetectLanguageAsync( new BatchInput( new List <Input>() { new Input("1", text) })); var detectedLanguage = result.Documents.First().DetectedLanguages.First(); var englishProbability = detectedLanguage.Name == "English" ? detectedLanguage.Score : 0; SentimentBatchResult sentimentResult = await client.SentimentAsync( new MultiLanguageBatchInput(new List <MultiLanguageInput>() { new MultiLanguageInput(detectedLanguage.Iso6391Name, "1", text) })); double?sentiment = 0; if (sentimentResult.Documents.Any()) { sentiment = sentimentResult.Documents.First().Score; } return((englishProbability + sentiment) / 2); }
public async Task <string> GetMessageLanguageAsync(string message) { var language = string.Empty; LanguageBatchResult result = await client.DetectLanguageAsync( new BatchInput( new List <Input>() { new Input("1", message) } )); if (result.Documents.Count > 0) { language = result.Documents[0].DetectedLanguages[0].Iso6391Name; } return(language); }
public async Task <string> DetectLanguageAsync(string text) { Console.OutputEncoding = System.Text.Encoding.UTF8; LanguageBatchResult result = await _client.DetectLanguageAsync( new BatchInput( new List <Input>() { new Input("1", text) }), numberOfLanguagesToDetect : 1); if (result.Documents.FirstOrDefault() != null && result.Documents.First().DetectedLanguages.FirstOrDefault() != null) { return(result.Documents.First().DetectedLanguages.First().Name); } return(_defaultLanguage); }
public async Task <DetectedLanguage> Execute(ITextAnalyticsAPI client) { var id = Guid.NewGuid().ToString(); var input = new Input(id, text); var documents = new List <Input> { input }; var batchInput = new BatchInput(documents); var result = await client.DetectLanguageAsync(batchInput); // More than one language could be matched at the same max score... // this can cause some confusion var detectedLanguages = result.Documents.First() .DetectedLanguages; var detectedLanguage = detectedLanguages.Where(dl => dl.Score.HasValue && new[] { "en", "fr" }.Contains(dl.Iso6391Name)) .OrderByDescending(dl => dl.Score) .FirstOrDefault(); return(detectedLanguage); }
internal async Task <LanguageBatchResult> DetectLangCall(ITextAnalyticsAPI client, List <Input> list) { return(await client.DetectLanguageAsync( new BatchInput(list))); }