public async Task <Result <AnalysisScore> > GetTweetScoreByKeyAsync(string key) { var dbResult = _unitOfWork.Tweets.FindByKey(new TweetQuery(key, 100000)).ToList(); if (dbResult.Count > 0) { return(Result <IEnumerable <Tweet> > .Wrap(AnalysisScoreBuilder.AnalysisScore(dbResult, key).Build())); } var apiResult = _unitOfWork.ApiTweets.Get(new TweetQuery(key)); var analyzedTweets = await _sentimentalAnalysisService.AnalyzeAsync(apiResult); if (analyzedTweets.IsSuccess) { _unitOfWork.Tweets.AddRange(analyzedTweets.Value); return(Result <AnalysisScore> .Wrap(AnalysisScoreBuilder.AnalysisScore(analyzedTweets.Value, key).Build())); } return(Result <AnalysisScore> .Error()); }
public Result <AnalysisScore> GetTweetScoreByKey(string key) { var dbResult = _unitOfWork.Tweets.FindByKey(new TweetQuery(key, 100000)).ToList(); if (dbResult.Count > 0) { return(Result <AnalysisScore> .Wrap(AnalysisScoreBuilder.AnalysisScore(dbResult, key).Build())); } var apiResult = _unitOfWork.ApiTweets.Get(new TweetQuery(key)); var analyzedTweets = _sentimentalAnalysisService.Analyze(apiResult); if (!analyzedTweets.IsSuccess) { return(Result <AnalysisScore> .Error()); } _unitOfWork.Tweets.AddRange(analyzedTweets.Value); return(Result <AnalysisScore> .Wrap(AnalysisScoreBuilder.AnalysisScore(analyzedTweets.Value, key).Build())); }
public void Test_From_Tweets_Method_When_Positive_And_Negative_Tweets_Quantity_Is_Equal() { var tweets = new List <Tweet> { new Tweet { Sentiment = WordCategory.Positive, Text = "Test Positive Tweet" }, new Tweet { Sentiment = WordCategory.Positive, Text = "Test Positive Tweet" }, new Tweet { Sentiment = WordCategory.Negative, Text = "Test Negative Tweet" }, new Tweet { Sentiment = WordCategory.Negative, Text = "Test negative Tweet" } }; var score = AnalysisScoreBuilder.AnalysisScore(tweets, "test").Build(); score.Sentiment.Should().Be(GeneralSentiment.Neutral); score.NegativeTweetsQuantity.Should().Be(2); score.PositiveTweetsQuantity.Should().Be(2);; }
public void Test_From_Tweets_Method_When_Most_Tweet_Are_Positive() { var tweets = new List <Tweet> { new Tweet { Sentiment = WordCategory.Positive, Text = "Test Positive Tweet" }, new Tweet { Sentiment = WordCategory.Positive, Text = "Test Positive Tweet" }, new Tweet { Sentiment = WordCategory.Negative, Text = "Test Negative Tweet" }, new Tweet { Sentiment = WordCategory.Positive, Text = "Test Positive Tweet" } }; var score = AnalysisScoreBuilder.AnalysisScore(tweets, "positive").Build(); score.Sentiment.Should().Be(GeneralSentiment.Positive); score.NegativeTweetsQuantity.Should().Be(1); score.PositiveTweetsQuantity.Should().Be(3); }