示例#1
0
文件: Tags.cs 项目: ayende/Subtext
        /// <summary>
        /// Gets the top tags.
        /// </summary>
        /// <param name="itemCount">The item count.</param>
        /// <returns></returns>
        public static IList<Tag> GetTopTags(int itemCount)
        {
            if (itemCount < 0)
                throw new ArgumentNullException("itemCount", "Cannot request negative tags. Pass in 0 to get all tags.");
            IDictionary<string, int> topTags = ObjectProvider.Instance().GetTopTags(itemCount);

            double mean;
            double stdDev = Statistics.StdDev(topTags.Values, out mean);

            IList<Tag> tags = new List<Tag>();
            foreach (KeyValuePair<string, int> tag in topTags)
            {
                Tag t = new Tag(tag);
                t.Factor = (t.Count - mean) / stdDev;
                t.Weight = ComputeWeight(t.Factor, stdDev);
                tags.Add(t);
            }

            return tags;
        }
示例#2
0
        /// <summary>
        /// Gets the top tags.
        /// </summary>
        public static ICollection<Tag> GetMostUsedTags(this ObjectProvider repository, int itemCount)
        {
            if(itemCount < 0)
            {
                throw new ArgumentOutOfRangeException("itemCount", itemCount,
                                                      Resources.ArgumentOutOfRange_NegativeTagItemCount);
            }
            var topTags = repository.GetTopTags(itemCount);

            double mean;
            double stdDev = topTags.Values.StandardDeviation(out mean);

            var tags = new List<Tag>();
            foreach(var tag in topTags)
            {
                var t = new Tag(tag);
                t.Factor = (t.Count - mean) / stdDev;
                t.Weight = ComputeWeight(t.Factor, stdDev);
                tags.Add(t);
            }

            return tags;
        }
示例#3
0
 public void CanSetAndGetSimpleProperties()
 {
     Tag tag = new Tag(new KeyValuePair<string,int>());
     UnitTestHelper.AssertSimpleProperties(tag);
 }
示例#4
0
        public void GetTopTags_WithTagsInCache_RetrievesFromCache()
        {
            // arrange
            var tag = new Tag(new KeyValuePair<string, int>("Test", 123));
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog { Id = 1001 });
            context.Setup(c => c.Cache["TagsCount10BlogId1001"]).Returns(new[] { tag });
            context.Setup(c => c.Repository.GetTopTags(10)).Throws(new Exception("Repository should not have been accessed"));

            // act
            var cachedTags = Cacher.GetTopTags(10, context.Object);

            // assert
            Assert.AreEqual(tag, cachedTags.First());
        }