Пример #1
0
 public void Prepositions_ShouldBeRemoved()
 {
     WordsFilter.Apply(new List <string> {
         "123", "in", "of", "word", "anotherword"
     })
     .Should().BeEquivalentTo(new List <string> {
         "123", "word", "anotherword"
     });
 }
Пример #2
0
        public Result <ITagCloud> GenerateTagCloud()
        {
            var filteredWords = WordsProvider.GetWords()
                                .Then(words => WordsFilter.Apply(words));

            if (!filteredWords.IsSuccess)
            {
                return(Result.Fail <ITagCloud>(filteredWords.Error));
            }

            var wordsFrequencies = GetTokens(filteredWords.Value)
                                   .OrderByDescending(wordToken => wordToken.Frequency)
                                   .ToArray();
            var wordsCount = wordsFrequencies.Select(wordToken => wordToken.Frequency).Sum();

            foreach (var wordToken in wordsFrequencies)
            {
                var width  = Math.Max(100, 500 * wordToken.Frequency / wordsCount);
                var height = Math.Max(50, 250 * wordToken.Frequency / wordsCount);
                var size   = new Size(width, height);
                PutNextWord(wordToken.Word, size);
            }

            return(this);
        }
Пример #3
0
        public void TagCloud_ShouldContainUniqueWords()
        {
            tagCloudWithCenterInZero.GenerateTagCloud();

            tagCloudWithCenterInZero.WordRectangles.Select(wordRectangle => wordRectangle.Word).Should()
            .BeEquivalentTo(wordsFilter.Apply(wordsProvider.GetWords().ToHashSet()));
        }
Пример #4
0
        public void GenerateTagCloud()
        {
            var words            = WordsProvider.GetWords();
            var filteredWords    = WordsFilter.Apply(words);
            var wordsFrequencies = GetTokens(filteredWords)
                                   .OrderByDescending(wordToken => wordToken.Frequency);
            var wordsCount = wordsFrequencies.Select(wordToken => wordToken.Frequency).Sum();

            foreach (var wordToken in wordsFrequencies)
            {
                var width  = Math.Max(100, 500 * wordToken.Frequency / wordsCount);
                var height = Math.Max(50, 250 * wordToken.Frequency / wordsCount);
                var size   = new Size(width, height);
                PutNextWord(wordToken.Word, size);
            }
        }