Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 public bool Validate(string word)
 {
     return(!BlackList.Contains(normalizer.Normalize(word)));
 }