public TextAnalysis SaveContentAnalysis(string content, long reviewId) { _logger.LogInformation("performing text analysis for text: {0}", content); var languageHolder = _analysisClient.DetectLanguage(content); var textAnalysis = languageHolder.Map(some => new TextAnalysis { ReviewId = reviewId, Language = some.Name, LanguageScore = some.ConfidenceScore } ).Match(some => some, () => new TextAnalysis()); var sentimentHolder = _analysisClient.DetectSentiment(content); var analysis = sentimentHolder.Map(some => new TextAnalysis() { ReviewId = textAnalysis.ReviewId, Language = textAnalysis.Language, LanguageScore = textAnalysis.LanguageScore, Sentiment = some.Sentiment.ToString(), NegativeScore = some.ConfidenceScores.Negative, NeutralScore = some.ConfidenceScores.Neutral, PositiveScore = some.ConfidenceScores.Positive } ).Match(some => some, () => new TextAnalysis()); _dbContext.TextAnalyses.Add(analysis); _dbContext.SaveChanges(); return(analysis); }
public void DetectSentiment() { var responseHolder = _analysisClient.DetectSentiment("la lluvia gris tambien es parte del paisaje"); responseHolder.ShouldBeSome(some => { some.Sentiment.Should().Be(TextSentiment.Negative); }); }