private Dictionary<string, int> GetWordsCounts(IReadOnlyCollection <string> words) { return words.Select(word => normalizer.Normalize(word)) .Where(word => !filters.Any(f => f.ShouldExclude(word))) .GroupBy(word => word) .ToDictionary(group => group.Key, group => group.Count()); }
public Result <Dictionary <string, int> > CountWords(IEnumerable <string> words) { var resultDictionary = new Dictionary <string, int>(); foreach (var word in words) { var normalizedWordResult = normalizer.Normalize(word); if (!normalizedWordResult.IsSuccess) { return(Result.Fail <Dictionary <string, int> >( $"Cannot normalize word {word} {normalizedWordResult.Error}")); } var normalizedWord = normalizedWordResult.Value; if (filter.IsExcluded(normalizedWord)) { continue; } if (resultDictionary.ContainsKey(normalizedWord)) { resultDictionary[normalizedWord]++; } else { resultDictionary[normalizedWord] = 1; } } return(Result.Ok(resultDictionary)); }
public Image GetNewTagcloud(IEnumerable <string> words) { var neededWords = words .Where(word => wordsFilters.All(filter => filter.Validate(word))) .Select(word => wordNormalizer.Normalize(word)) .ToList(); var counts = neededWords .GroupBy(word => word) .Select(group => new Word(group.Key, (double)group.Count() / neededWords.Count)); return(drawer.GetTagsCloud(counts)); }
private Result <List <string> > NormalizeWords(IEnumerable <string> words) { var normalizedWords = new List <string>(); foreach (var word in words) { var normalizeResult = normalizer.Normalize(word); if (!normalizeResult.IsSuccess) { return(Result.Fail <List <string> >(normalizeResult.Error)); } normalizedWords.Add(normalizeResult.Value); } return(Result.Ok(normalizedWords)); }
public bool Validate(string word) { return(!BlackList.Contains(normalizer.Normalize(word))); }