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);
        }
        private async Task <IEnumerable <AnalysisResult> > GetAnalysisResultsAsync(MultiLanguageBatchInput batchInput)
        {
            KeyPhraseBatchResult keyPhraseBatchResult = await _textAnalyticsAPI.KeyPhrasesAsync(batchInput);

            SentimentBatchResult sentimentBatchResult = await _textAnalyticsAPI.SentimentAsync(batchInput);


            foreach (var keyPhrase in keyPhraseBatchResult.Documents)
            {
                string tweet = batchInput.Documents
                               .Where(d => d.Id == keyPhrase.Id)
                               .Select(t => t.Text)
                               .FirstOrDefault();

                var sentiment = sentimentBatchResult.Documents
                                .Where(s => s.Id == keyPhrase.Id)
                                .FirstOrDefault();

                if (IsSignificant(sentiment.Score) && !keyPhrase.KeyPhrases.Count().Equals(0))
                {
                    AnalysisResult analysisResult = new AnalysisResult
                    {
                        KeyPhrases = keyPhrase.KeyPhrases,
                        Attitude   = DeriveAttitude(sentiment.Score),
                        Tweet      = tweet
                    };

                    _analysisResults.Add(analysisResult);
                }
            }

            return(_analysisResults);
        }
Пример #3
0
        public async Task <double> GetSentimentScoreAsync(string language, string message)
        {
            double score = -1;

            SentimentBatchResult result = await client.SentimentAsync(
                new MultiLanguageBatchInput(
                    new List <MultiLanguageInput>()
            {
                new MultiLanguageInput(language, "1", message)
            }));

            if (result.Documents.Count > 0)
            {
                score = result.Documents[0].Score.Value;
            }

            return(score);
        }
Пример #4
0
 public Task <SentimentBatchResult> SentimentAsync(IList <MultiLanguageInput> inputs,
                                                   CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_client.SentimentAsync(new MultiLanguageBatchInput(inputs), cancellationToken));
 }
Пример #5
0
 internal async Task <SentimentBatchResult> SentimentCall(ITextAnalyticsAPI client, List <MultiLanguageInput> list)
 {
     return(await client.SentimentAsync(
                new MultiLanguageBatchInput(list)));
 }
Пример #6
0
 public async Task <SentimentBatchResult> UploadAndDetectText(string text, CancellationToken cancellationToken)
 {
     return(await _client.SentimentAsync(new MultiLanguageBatchInput(new List <MultiLanguageInput> {
         new MultiLanguageInput("en", "0", text)
     }), cancellationToken));
 }