public async Task<int> GetPositiveIndex(Guid newsId) { if (newsId!=null) { try { var WordDict = GetDictFromLemms(await GetLemms(newsId)); var AffinDict = _afinn.GetDictionary(); int PosIndex = 0; int countAffinWordInNews = 0; int CountPos = 0; foreach (var word in WordDict) { if (AffinDict.Keys.Contains<string>(word.Key)) { var AffinWordValui = AffinDict[word.Key]; CountPos += Convert.ToInt32(AffinWordValui) * word.Value; countAffinWordInNews += word.Value; } } if (countAffinWordInNews != 0) { PosIndex = Convert.ToInt32(Math.Round((double)CountPos / countAffinWordInNews, 3)*1000); } return PosIndex; } catch (Exception) { throw; } } return 0; }
public void GetCommentIndex(TorrentMovie movie) { Log.Information($"CommentService.CommentHanlder.GetCommentIndex() started at {DateTime.Now}{ Environment.NewLine}"); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() started at {DateTime.Now}{ Environment.NewLine}"); try { Dictionary <string, int> dictFromLemms = new Dictionary <string, int>(); Dictionary <string, string> DictionaryAffin = _afinn.GetDictionary(); int countAffinWordInText = 0; int IndexWordsFromText = 0; int CommentIndex = 0; var comments = _unitOfWork.comments.Where(x => x.movieId.Id.ToString().Equals(movie.Id.ToString())); if (comments != null) { string commentsString = Regex.Replace(BuildSringFromComments(comments), @"\s{2}", " "); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() work with movie {movie.title}{ Environment.NewLine}{movie.Id}"); Log.Information($"CommentService.CommentHanlder.GetCommentIndex() work with movie {movie.title}{ Environment.NewLine}{movie.Id}"); dictFromLemms = _lemmatization.GetDictFromLemms(commentsString); if (dictFromLemms != null) { foreach (var wordFromText in dictFromLemms) { if (DictionaryAffin.ContainsKey(wordFromText.Key)) { int AffinWordValue = Convert.ToInt32(DictionaryAffin[wordFromText.Key]) + 5;//remove negative values IndexWordsFromText += AffinWordValue * wordFromText.Value; countAffinWordInText += wordFromText.Value; } } if (countAffinWordInText != 0) { int downloadsToInt = movie.downloads; CommentIndex = Convert.ToInt32(Math.Round((double)IndexWordsFromText / countAffinWordInText, 3) * 10) + movie.amountOfComments; movie.commentIndex = CommentIndex; } else { movie.commentIndex = movie.amountOfComments; } } else { movie.commentIndex = movie.amountOfComments; } } else { Log.Information($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}" + $"DB not contain comments by movie {movie.title}{ Environment.NewLine} "); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}" + $"DB not contain comments by movie {movie.title}{ Environment.NewLine} "); movie.commentIndex = 0; } _unitOfWork.Save(); Log.Information($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}"); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}"); } catch (Exception ex) { Log.Error($"CommentService.CommentHanlder.GetCommentIndex() worked with error {DateTime.Now}" + $"{Environment.NewLine}{ex}{Environment.NewLine}"); } }