Ejemplo n.º 1
0
 public IActionResult TopResturant()
 {
     try
     {
         using (IWebsiteCrawler crawler = new SnappfoodHelper())
         {
             var sentences = crawler.GetTopSentences();
             if (sentences == null || sentences.Count < 1)
             {
                 return(Ok("sentences null"));
             }
             string _sentences = "";
             foreach (var item in sentences.Where(x => !string.IsNullOrEmpty(x.Text)))
             {
                 if (item.Opinions != null && item.Opinions.Count > 0)
                 {
                     foreach (var op in item.Opinions)
                     {
                         _sentences += $@"{item.id}	{item.Text.Replace(",", " ").Replace("  ", " ")}	{op.category}_{op.aspect}	{op.polarity}"+ "\r\n";
                     }
                 }
             }
             return(File(Encoding.UTF8.GetBytes(_sentences), "text/csv", "ResturantTopSentences.csv"));
         }
     }
     catch (Exception ex)
     {
         return(Ok("Error:\n" + ex.Message + "\n\n\nTime: " + DateTime.Now));
     }
 }
Ejemplo n.º 2
0
        public IActionResult TopSentences(string id)
        {
            id = id.ToLower();

            IWebsiteCrawler web = null;

            if (id == "mobile")
            {
                web = new DigikalaHelper();
            }
            else if (id == "resturant")
            {
                web = new SnappfoodHelper();
            }
            else
            {
                return(Ok());
            }

            var    sentences  = web.GetTopSentences();
            string _sentences = "";

            foreach (var item in sentences)
            {
                foreach (var op in item.Opinions)
                {
                    _sentences += $@"{item.Text.Replace(",", " ").Replace("  ", " ")}	{op.category}_{op.aspect}	{op.polarity}"+ "\r\n";
                }
            }
            return(File(Encoding.UTF8.GetBytes(_sentences), "text/csv", "TopSentences.csv"));
        }
Ejemplo n.º 3
0
 public string GetStatus()
 {
     using (IWebsiteCrawler digikala = new SnappfoodHelper())
     {
         return(digikala.GetSatatusReview());
     }
 }
Ejemplo n.º 4
0
        public IActionResult Index(string id)
        {
            //Aspects aspects = new Aspects();
            List <User> users = new List <User>();

            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل", Role = "admin"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل", Brand = "اپل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });
            users.Add(new User {
                Username = "******", Password = "******", Category = "گوشی موبایل"
            });

            if (!string.IsNullOrEmpty(id))
            {
                User _user = users.Where(x => x.Username.ToLower() == id.ToLower().Trim()).FirstOrDefault();

                if (_user != null)
                {
                    TaggerResturantVM tagger = new TaggerResturantVM();
                    tagger.User   = _user;
                    tagger.Tagger = _user.Username;

                    using (IWebsiteCrawler snappfood = new SnappfoodHelper())
                    {
                        GetFirstProductByCategoryParam param = new GetFirstProductByCategoryParam();
                        param.tagger = _user.Username;
                        param.title  = _user.Title;
                        var      s        = snappfood.GetFirstProductByCategory <ResturantReviewsDTO>(param).Result;
                        string[] comments = s.Review.Split(". ");

                        tagger.Review    = s.Review;
                        tagger.idBson    = s._id;
                        tagger.CommentId = s._id;
                    }
                    return(View(tagger));
                }
            }
            return(Redirect("http://google.com"));
        }
Ejemplo n.º 5
0
 public IActionResult ResturantRejectReview(int id)
 {
     using (IWebsiteCrawler snappfood = new SnappfoodHelper())
     {
         snappfood.RejectReview(id);
         return(Ok("Ok"));
     }
 }
Ejemplo n.º 6
0
        public IActionResult AddLabel([FromBody] AddLabelResturantParam model)
        {
            Dictionary <string, int> pol = new Dictionary <string, int>()
            {
                { "positive", 1 }, { "neutral", 0 }, { "negative", -1 }
            };

            if (model != null)
            {
                AddReviewToDBParam param = new AddReviewToDBParam();
                param.id     = model.CommentId.ToString();
                param.tagger = model.Tagger;
                ReviewDTO review = new ReviewDTO();
                review._id        = "000";
                review.CreateDate = DateTime.Now;
                review.ProductID  = int.Parse(model.CommentId);
                review.rid        = int.Parse(model.CommentId);

                sentence sentence = new sentence();
                sentence.Text = model.Text;

                List <Opinion> Opinions = new List <Opinion>();
                if (model.ResrurantLabels.Count() > 0)
                {
                    Opinions.AddRange(model.ResrurantLabels.Select(x => new Opinion
                    {
                        category      = x.Label.Split('#')[0].ToUpper().Trim(),
                        aspect        = x.Label.Split('#')[1].ToUpper().Trim(),
                        polarity      = x.Polarity,
                        polarityClass = pol[x.Polarity]
                    }).ToList());
                    sentence.Opinions = Opinions;
                }
                if (Opinions.Count < 1)
                {
                    sentence.OutOfScope = true;
                }
                review.sentences = new List <sentence>();
                review.sentences.Add(sentence);

                param.review = new ReviewDTO();
                param.review = review;
                using (IWebsiteCrawler digikala = new SnappfoodHelper())
                {
                    var result = digikala.AddReviewToDB_NewMethod(param);
                    if (!result)
                    {
                        return(NoContent());
                    }
                }
                return(Json(new { Message = "ثبت شد" }));
            }
            else
            {
                return(NoContent());
            }
        }
Ejemplo n.º 7
0
 private void Insert(List <ResturantReviewsDTO> resturantReviews)
 {
     using (IWebsiteCrawler snapp = new SnappfoodHelper())
     {
         AddResturatsDBParam addResturats = new AddResturatsDBParam();
         addResturats.resturantReviews = resturantReviews;
         snapp.AddRawReviewsToDB(addResturats);
         System.Threading.Thread.Sleep(1500);
     }
 }
Ejemplo n.º 8
0
        public IActionResult init()
        {
            List <SnappfoodMinInfo>    reviews          = new List <SnappfoodMinInfo>();
            List <string>              cleanReviews     = new List <string>();
            List <ResturantReviewsDTO> resturantReviews = new List <ResturantReviewsDTO>();

            using (IWebsiteCrawler snapp = new SnappfoodHelper())
            {
                reviews = snapp.GetAllReviews <GetReviewsMinimumResponse>().Result.ReviewsMinimum;
            }
            using (var html = new HtmlHelper())
            {
                cleanReviews.Clear();
                for (int i = 0; i < reviews.Count; i++)
                {
                    if (!string.IsNullOrEmpty(reviews[i].Review))
                    {
                        string _txt = html.CleanReview(reviews[i].Review);
                        if (!string.IsNullOrEmpty(_txt))
                        {
                            ResturantReviewsDTO rr = new ResturantReviewsDTO()
                            {
                                _id         = i,
                                CommentId   = reviews[i].CommentId,
                                RestId      = reviews[i].RestId,
                                Review      = _txt,
                                Date        = DateTime.Now,
                                Reserve     = false,
                                Seen        = false,
                                Tagged      = false,
                                Tagger      = "_",
                                TagDate     = DateTime.Now.AddDays(-60),
                                ReserveDate = DateTime.Now.AddDays(-60),
                                Reject      = false,
                            };
                            resturantReviews.Add(rr);
                        }
                    }
                    if (resturantReviews.Count > 30000)
                    {
                        Insert(resturantReviews);
                        resturantReviews.Clear();
                    }
                }
            }
            Insert(resturantReviews);
            return(Ok(resturantReviews.Count.ToString()));
        }
Ejemplo n.º 9
0
        public IActionResult DetailsReportV2(string id = null)
        {
            if (id == "digi")
            {
                using (IWebsiteCrawler snapp = new DigikalaHelper())
                {
                    //var jhkkj = digikala.GetAllReviews1();
                    List <sentence> sentences      = new List <sentence>();
                    List <sentence> sentencesTrain = new List <sentence>();
                    List <sentence> sentencesTest  = new List <sentence>();
                    List <sentence> sentencesTest1 = new List <sentence>();

                    var data = snapp.GetLabelReviews();
                    foreach (var rev in data)
                    {
                        if (rev.sentences != null && rev.sentences.Count() > 0)
                        {
                            sentences.AddRange(rev.sentences);
                        }
                    }
                    sentences.ToList();
                    int countTest  = (int)(sentences.Count() * 0.2);
                    int countTrain = sentences.Count() - countTest;
                    sentencesTrain = sentences.Take(countTrain).ToList();
                    sentencesTest  = sentences.Skip(countTrain).Take(countTest).ToList();
                    sentencesTest1 = sentencesTest.Select(x => new sentence
                    {
                        id       = x.id,
                        Opinions = new List <Opinion> {
                            x.Opinions.First()
                        },
                        OutOfScope = x.OutOfScope,
                        Text       = x.Text
                    }).ToList();

                    string result = "Result:";
                    result += "\n\n****************************************\n❌ All Data:\n\n\n" + getDetails(sentences);
                    result += "\n\n****************************************\n❌ 1.Tarin:\n\n\n" + getDetails(sentencesTrain);
                    result += "\n\n****************************************\n❌ 2.Test:\n\n\n" + getDetails(sentencesTest);
                    result += "\n\n****************************************\n❌ 3.Test First:\n\n\n" + getDetails(sentencesTest1);

                    return(Ok(result));
                }
            }
            using (IWebsiteCrawler snapp = new SnappfoodHelper())
            {
                //var jhkkj = digikala.GetAllReviews1();
                List <sentence> sentences      = new List <sentence>();
                List <sentence> sentencesTrain = new List <sentence>();
                List <sentence> sentencesTest  = new List <sentence>();
                List <sentence> sentencesTest1 = new List <sentence>();

                var data = snapp.GetLabelReviews();
                foreach (var rev in data)
                {
                    if (rev.sentences != null && rev.sentences.Count() > 0)
                    {
                        sentences.AddRange(rev.sentences);
                    }
                }
                sentences.ToList();
                int countTest  = (int)(sentences.Count() * 0.2);
                int countTrain = sentences.Count() - countTest;
                sentencesTrain = sentences.Take(countTrain).ToList();
                sentencesTest  = sentences.Skip(countTrain).Take(countTest).ToList();
                sentencesTest1 = sentencesTest.Select(x => new sentence
                {
                    id       = x.id,
                    Opinions = new List <Opinion> {
                        x.Opinions.First()
                    },
                    OutOfScope = x.OutOfScope,
                    Text       = x.Text
                }).ToList();

                string result = "Result:";
                result += "\n\n****************************************\n❌ All Data:\n\n\n" + getDetails(sentences);
                result += "\n\n****************************************\n❌ 1.Tarin:\n\n\n" + getDetails(sentencesTrain);
                result += "\n\n****************************************\n❌ 2.Test:\n\n\n" + getDetails(sentencesTest);
                result += "\n\n****************************************\n❌ 3.Test First:\n\n\n" + getDetails(sentencesTest1);

                return(Ok(result));
            }
        }
Ejemplo n.º 10
0
        public IActionResult DetailsReport()
        {
            List <Aspect>   aspects    = new List <Aspect>();
            List <Category> categories = new List <Category>();

            List <Aspect1>   aspects1    = new List <Aspect1>();
            List <Category1> categories1 = new List <Category1>();

            List <AspectCategory> aspectCategories = new List <AspectCategory>();

            using (IWebsiteCrawler snapp = new SnappfoodHelper())
            {
                //var jhkkj = digikala.GetAllReviews1();
                List <sentence> sentences = new List <sentence>();
                List <Opinion>  opinions  = new List <Opinion>();
                var             data      = snapp.GetLabelReviews();
                foreach (var rev in data)
                {
                    if (rev.sentences != null && rev.sentences.Count() > 0)
                    {
                        sentences.AddRange(rev.sentences);
                    }
                }
                sentences.ToList();
                foreach (var sentence in sentences.Where(x => !string.IsNullOrEmpty(x.Text)))
                {
                    if (sentence.Opinions != null && sentence.Opinions.Count() > 0)
                    {
                        foreach (var op in sentence.Opinions)
                        {
                            var q1 = aspects.Where(x => x.Name == op.aspect && x.polarity == op.polarity).Any();
                            if (q1)
                            {
                                var s = aspects.Where(x => x.Name == op.aspect && x.polarity == op.polarity).FirstOrDefault();
                                s.count += 1;
                            }
                            else
                            {
                                aspects.Add(new Aspect {
                                    Name = op.aspect, count = 1, polarity = op.polarity
                                });
                            }
                            var q12 = aspects1.Where(x => x.Name == op.aspect).Any();
                            if (q12)
                            {
                                var s12 = aspects1.Where(x => x.Name == op.aspect).FirstOrDefault();
                                s12.count += 1;
                            }
                            else
                            {
                                aspects1.Add(new Aspect1 {
                                    Name = op.aspect, count = 1
                                });
                            }
                            var q2 = categories.Where(x => x.Name == op.category && x.polarity == op.polarity).Any();
                            if (q2)
                            {
                                var s1 = categories.Where(x => x.Name == op.category && x.polarity == op.polarity).FirstOrDefault();
                                s1.count += 1;
                            }
                            else
                            {
                                categories.Add(new Category {
                                    Name = op.category, count = 1, polarity = op.polarity
                                });
                            }
                            var q22 = categories1.Where(x => x.Name == op.category).Any();
                            if (q22)
                            {
                                var s1 = categories1.Where(x => x.Name == op.category).FirstOrDefault();
                                s1.count += 1;
                            }
                            else
                            {
                                categories1.Add(new Category1 {
                                    Name = op.category, count = 1
                                });
                            }
                            var q3 = aspectCategories.Where(x => x.aspect == op.aspect && x.category == op.category && x.polarity == op.polarity).Any();
                            if (q3)
                            {
                                var s2 = aspectCategories.Where(x => x.aspect == op.aspect && x.category == op.category && x.polarity == op.polarity).FirstOrDefault();
                                s2.count += 1;
                            }
                            else
                            {
                                aspectCategories.Add(new AspectCategory {
                                    category = op.category, aspect = op.aspect, count = 1, polarity = op.polarity
                                });
                            }

                            opinions.Add(op);
                        }
                    }
                }
                opinions.ToList();
                string aspp = "";
                foreach (var item in aspects)
                {
                    aspp += $"{item.Name}	{item.polarity}	{item.count}\n";
                }
                string cats = "";
                foreach (var item in categories)
                {
                    cats += $"{item.Name}	{item.polarity}	{item.count}\n";
                }
                string aspp1 = "";
                foreach (var item in aspects1)
                {
                    aspp1 += $"{item.Name}	{item.count}\n";
                }
                string cats1 = "";
                foreach (var item in categories1)
                {
                    cats1 += $"{item.Name}	{item.count}\n";
                }
                string aspectCats = "";
                foreach (var item in aspectCategories)
                {
                    aspectCats += $"{item.category}	{item.aspect}	{item.polarity}	{item.count}\n";
                }

                return(Ok(aspp1 + "\n\n\n_____\n\n\n" + cats1 + "\n\n\n_____\n\n\n" + aspp + "\n\n\n_____\n\n\n" + cats + "\n\n\n_____\n\n\n" + aspectCats));
            }
        }