Exemplo n.º 1
0
        private Word PlaceWord(string word, double frequency, TagCloudLayouter layouter, Graphics graphics)
        {
            var font          = new Font(fontFamilyProvider.FontFamily, GetFontSize(frequency));
            var wordSize      = graphics.MeasureString(word, font).ToSize();
            var wordRectangle = layouter.PutNextRectangle(wordSize);

            return(new Word(word, font, wordRectangle));
        }
Exemplo n.º 2
0
        public void GetTags_GetWeightedWords_ReturnCorrectCountOfTags()
        {
            var text
                = "So I said yes to Thomas Clinton and later thought that I had said yes to God and later still realized I had said yes only to Thomas Clinton";
            var weightedWords = wordAnalyzer.WeightWords(wordAnalyzer.SplitWords(text));

            var tagLayouter = new TagCloudLayouter(new FontSettings(), new CircularCloudLayouter());

            tagLayouter.GetCloudTags(weightedWords).Count.Should().Be(weightedWords.Count);
        }
Exemplo n.º 3
0
        public void GetTags_AddSingleWord_ReturnWordWithMaxSize()
        {
            var weightedWords = new Dictionary <String, int> {
                { "hello", 3 }
            };
            var tagLayouter = new TagCloudLayouter(new FontSettings(), new CircularCloudLayouter());

            var tags = tagLayouter.GetCloudTags(weightedWords);

            tags.First().Font.SizeInPoints.Should().Be(50);
        }
Exemplo n.º 4
0
        public void GetTags_GetWeightedWords_ReturnTagsSortedByWeightedWordsFrequencies()
        {
            var text
                = "So I said yes to Thomas Clinton and later thought that I had said yes to God and later still realized I had said yes only to Thomas Clinton";
            var weightedWords = wordAnalyzer.WeightWords(wordAnalyzer.SplitWords(text));

            var tagLayouter = new TagCloudLayouter(new FontSettings(), new CircularCloudLayouter());

            var tags = tagLayouter.GetCloudTags(weightedWords);

            tags.Select(tag => tag.Word).Should().ContainInOrder(weightedWords.Select(word => word.Key));
        }
Exemplo n.º 5
0
        public void GetTags_AddThreeWordsWithDescendingFrequensies_ReturnTagsWithCorrectSizes()
        {
            var weightedWords = new Dictionary <String, int> {
                { "how", 4 }, { "are", 2 }, { "you", 1 }
            };
            var tagLayouter = new TagCloudLayouter(new FontSettings(), new CircularCloudLayouter());

            var tags = tagLayouter.GetCloudTags(weightedWords);

            var sizes = new[] { 63, 37, 23 };

            tags.Select(tag => tag.Font.SizeInPoints).ShouldAllBeEquivalentTo(sizes);
        }
Exemplo n.º 6
0
        public void GetTags_GetWeightedWords_ReturnTagsWithDescendingFontSizes()
        {
            var text
                = "So I said yes to Thomas Clinton and later thought that I had said yes to God and later still realized I had said yes only to Thomas Clinton";
            var weightedWords = wordAnalyzer.WeightWords(wordAnalyzer.SplitWords(text));
            var tagLayouter   = new TagCloudLayouter(new FontSettings(), new CircularCloudLayouter());

            var tags = tagLayouter.GetCloudTags(weightedWords);

            var tagFontsSizes = tags.Select(tag => tag.Font.Size).ToList();

            tagFontsSizes.Should().BeInDescendingOrder();
        }
Exemplo n.º 7
0
        public static void DrawDefaultTagCloud()
        {
            var layout = new CircularCloudLayouter();
            var text   =
                "So I said yes to Thomas Clinton and later thought that I had said yes to God and later still realized I had said yes only to Thomas Clinton";
            var analyzer      = new WordAnalyzer();
            var parsedText    = analyzer.TextAnalyzer(text);
            var weightedWords = analyzer.WeightWords(parsedText);
            var tagLayout     = new TagCloudLayouter(layout, weightedWords);
            var tags          = tagLayout.GetTags();
            var visualizer    = new TagCloudVisualization(tags);
            var bitmap        = visualizer.GetTagCloudImage();

            bitmap.Save("tag_cloud.png");
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     center           = new Point(10, 10);
     layouter         = new TagCloudLayouter(new SpiralAlgorithm(center));
     placedRectangles = new List <Rectangle>();
 }