Analyzes a batch of text to produce a tag-cloud.
        public void Results_are_sorted()
        {
            var result = new TagCloudAnalyzer().ComputeTagCloud(new string[] {
                "hi booger bum hi bum guy booger hi booger hi"
            }).Select(t => t.Text).ToArray();

            result.ShouldEqual(new string[] { "hi", "booger", "bum", "guy" });
        }
 public ActionResult TagCloud(DateTime start, DateTime end)
 {
     var phrases = JournalEntryService.GetEntries(UserId, start, end);
     var model = new TagCloudAnalyzer()
         .ComputeTagCloud(phrases)
         .Shuffle();
     return Json(new { tags = model });
 }
 public ActionResult Index()
 {
     var phrases = new string[] { Resources.TagCloudInput };
     var model = new TagCloudAnalyzer()
         .ComputeTagCloud(phrases)
         .Shuffle();
     return View(model);
 }
        public void There_should_be_a_max_result_size()
        {
            var results = new TagCloudAnalyzer(new TagCloudSetting() { MaxCloudSize = 2 })
                .ComputeTagCloud(new string[] { "hi hi fancy pant pant" });

            results.Count().ShouldEqual(2);
            results.Any(t => t.Text == "hi").ShouldBeTrue();
            results.Any(t => t.Text == "pant").ShouldBeTrue();
        }
示例#5
0
 static void Main(string[] args)
 {
     var words = new TagCloudAnalyzer()
         .ComputeTagCloud(File.ReadAllLines("Sample_Text_1.txt"));
     
     Console.Write(string.Join(
         Environment.NewLine, 
         words.Select(p => "[" + p.Count + "] \t" + p.Text).ToArray()));
     
     Console.ReadLine();
 }
 private static string[] GetShuffledWords(string[] original)
 {
     var result = new TagCloudAnalyzer()
         .ComputeTagCloud(original)
         .Shuffle()
         .Select(t => t.Text)
         .ToArray();
     return result;
 }
示例#7
0
        public ActionResult PostComment(DetailPageViewModel model, FormCollection collection)
        {
            try
            {
                int pageId = Convert.ToInt32(collection["IdPagina"]);
                if (ModelState.IsValid)
                {
                    using (UnitOfWork uow = new UnitOfWork())
                    {
                        PageRepository pr = new PageRepository(uow.Current);
                        Page p = pr.GetById(pageId);

                        Comment c = new Comment(model.Comment.UserName, model.Comment.UserMail, model.Comment.TextComment, p);
                        p.AddComment(c);
                        uow.Commit();
                    }
                }

                DetailPageViewModel m = new DetailPageViewModel();
                using (UnitOfWork uow = new UnitOfWork())
                {
                    //Carica gli ultimi 5 POST
                    PageRepository pr = new PageRepository(uow.Current);

                    IList<Page> pages = pr.GetTopPost(5);
                    if (pages != null && pages.Count > 0)
                    {
                        int k = 0;
                        foreach (var p in pages)
                        {
                            PostViewModel pTemp = new PostViewModel();

                            pTemp.Id = p.Id;
                            pTemp.Data = p.Date.Value;
                            pTemp.Testo = p.BodyText;
                            pTemp.Titolo = p.Title;
                            pTemp.Autore = String.Format("{0} {1}", p.Author.Name, p.Author.Surname);
                            pTemp.Categoria = p.Category.Name;
                            pTemp.IdCategoria = p.Category.Id;
                            pTemp.ImageName = p.ImageName;
                            pTemp.Visualizzazioni = p.Views;
                            pTemp.NumComments = p.Comments.Count;

                            m.PostPreview.Add(pTemp);

                            k++;
                        }
                    }
                    else
                    {
                        PostViewModel pTemp = new PostViewModel();

                        pTemp.Id = 0;
                        pTemp.Data = DateTime.Today;
                        pTemp.Titolo = "OOPS...";
                        pTemp.Testo = "Sembra non siano presenti articoli...";
                        pTemp.Autore = "Pasquale Garzillo";

                        m.PostPreview.Add(pTemp);
                    }

                    if (pageId != 0)
                    {
                        Page p = pr.GetById(pageId);

                        PostViewModel pTemp = new PostViewModel();

                        pTemp.Id = p.Id;
                        pTemp.Data = p.Date.Value;
                        pTemp.Testo = p.BodyText;
                        pTemp.Titolo = p.Title;
                        pTemp.Autore = String.Format("{0} {1}", p.Author.Name, p.Author.Surname);
                        pTemp.Categoria = p.Category.Name;
                        pTemp.IdCategoria = p.Category.Id;
                        pTemp.ImageName = p.ImageName;
                        pTemp.Tags = p.Tags != null && p.Tags.Count > 0 ? p.Tags.Select(x => x.Name).ToList() : null;
                        pTemp.Visualizzazioni = p.Views;
                        pTemp.NumComments = p.Comments.Count;

                        if (pTemp.Tags != null && pTemp.Tags.Count > 0)
                        {
                            var tags = new TagCloudAnalyzer()
                                     .ComputeTagCloud(pTemp.Tags);
                            pTemp.TagCloud = tags;
                        }

                        if (p.Comments != null && p.Comments.Count > 0)
                        {
                            pTemp.Comments = (from c in p.Comments
                                              select new CommentViewModel() { UserMail = c.UserMail, TextComment = c.TextComment, UserName = c.UserName }).ToList<CommentViewModel>();
                        }


                        m.DetailedPost = pTemp;
                    }

                    //Carica le ultime 5 categoria con maggiori post
                    CategoryRepository cr = new CategoryRepository(uow.Current);
                    IList<Category> tempCats = cr.GetTopCategoryByPostCount(3);
                    if (tempCats != null && tempCats.Count > 0)
                    {
                        foreach (var c in tempCats)
                        {
                            CategoryViewModel cvTemp = new CategoryViewModel();

                            cvTemp.Id = c.Id;
                            cvTemp.Nome = c.Name;
                            cvTemp.Descrizione = c.Description;
                            cvTemp.FileName = c.ImageName;

                            m.CategoriesPreview.Add(cvTemp);
                        }
                    }
                    else
                    {
                        CategoryViewModel cvTemp = new CategoryViewModel();

                        cvTemp.Id = 0;
                        cvTemp.Nome = "OOPS...";
                        cvTemp.Descrizione = "Sembra non siano presenti categorie...";

                        m.CategoriesPreview.Add(cvTemp);
                    }
                }
                return View(m);

            }
            catch (Exception ex)
            {
                return Error(ex);
            }
        }