예제 #1
0
        public void AddPost(Post post)
        {
            if (dispose) return;

            if (logger.Count < secsPerDay / chkRate.TotalSeconds &&
                (DateTime.UtcNow - post.CreationDate).TotalDays < 1)
            {
                logger.EnqueueItem(post);
            }
        }
예제 #2
0
        public static string FormatReport(Post post, ClassificationResults results, float threshold)
        {
            if (post == null || results == null ||
                results.Action == ClassificationResults.SuggestedAction.Nothing)
            {
                return null;
            }

            var msg = new MessageBuilder();
            var boldTh = 1 - ((1 - threshold) / 2);
            var resData = $"Similarity: {Math.Round(results.Similarity * 100)}%";

            switch (results.Action)
            {
                case ClassificationResults.SuggestedAction.Edit:
                {
                    msg.AppendLink("Edit", editUrl, resData, results.Similarity >= boldTh ?
                        TextFormattingOptions.Bold :
                        TextFormattingOptions.None,
                        WhiteSpace.None);
                    break;
                }
                case ClassificationResults.SuggestedAction.Close:
                {
                    msg.AppendLink("Close", closeUrl, resData, results.Similarity >= boldTh ?
                        TextFormattingOptions.Bold :
                        TextFormattingOptions.None,
                        WhiteSpace.None);
                    break;
                }
                case ClassificationResults.SuggestedAction.Delete:
                {
                    msg.AppendLink("Delete", deleteUrl, resData, results.Similarity >= boldTh ?
                        TextFormattingOptions.Bold :
                        TextFormattingOptions.None,
                        WhiteSpace.None);
                    break;
                }
            }

            msg.AppendText(": ");
            msg.AppendLink(post.Title, post.Url, "Score: " + post.Score, TextFormattingOptions.None, WhiteSpace.None);
            msg.AppendText(", by ");
            msg.AppendLink(post.AuthorName, post.AuthorLink, "Reputation: " + post.AuthorRep, TextFormattingOptions.None, WhiteSpace.None);
            msg.AppendText(".");

            return msg.ToString();
        }
예제 #3
0
        private static void ReportPost(Post post, ClassificationResults results)
        {
            var report = ReportFormatter.FormatReport(post, results, cvClassifier.Threshold);

            if (string.IsNullOrWhiteSpace(report)) return;

            socvr.PostMessageFast(report);
            lqphq.PostMessageFast(report);
        }
예제 #4
0
        private static void CheckAnswer(Post p)
        {
            var dvRes = advClassifier.ClassifyPost(p);

            if (dvRes.Similarity > 0.5)
            {
                ReportPost(p, dvRes);
                return;
            }
        }
예제 #5
0
        private static void CheckQuestion(Post p)
        {
            var cvRes = cvClassifier.ClassifyPost(p);
            var dvRes = qdvClassifier.ClassifyPost(p);

            if (cvRes.Similarity > 0.5 && cvRes.Similarity > dvRes.Similarity * 0.9)
            {
                ReportPost(p, cvRes);
            }
            else if (dvRes.Similarity > 0.5 && dvRes.Similarity > cvRes.Similarity * 1.1)
            {
                ReportPost(p, dvRes);
            }
        }
예제 #6
0
        private static void CheckPost(Post p)
        {
            try
            {
                if (checkedPosts.Contains(p) || p.Site != "stackoverflow.com" ||
                    p.AuthorRep > 10000 || p.Score > 2) return;
                while (checkedPosts.Count > 1000)
                {
                    Post temp;
                    checkedPosts.TryPop(out temp);
                }
                checkedPosts.Push(p);

                Task.Run(() => checkBack.AddPost(p));

                if (p.IsQuestion)
                {
                    CheckQuestion(p);
                }
                else
                {
                    CheckAnswer(p);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #7
0
        private void CheckPosts()
        {
            while (!dispose)
            {
                try
                {
                    checkBackMre.WaitOne(chkRate);

                    if (dispose) return;

                    var post = new Post
                    {
                        CreationDate = DateTime.MaxValue
                    };

                    foreach (var p in logger)
                    {
                        if (p.CreationDate < post.CreationDate)
                        {
                            post = p;
                        }
                    }

                    var timeAlive = DateTime.UtcNow - post.CreationDate;

                    if (timeAlive.TotalDays > 2)
                    {
                        logger.RemoveItem(post);
                        continue;
                    }

                    if (timeAlive.TotalDays > 1)
                    {
                        CQ dom;
                        if (post.IsQuestion && DeletedQuestionFound != null && ClosedQuestionFound != null)
                        {
                            if (PostFetcher.IsPostDeleted(post.Url, out dom))
                            {
                                DeletedQuestionFound(post);
                            }
                            else if (PostFetcher.IsQuestionClosed(dom, post.Url, false))
                            {
                                ClosedQuestionFound(post);
                            }
                        }
                        else if (!post.IsQuestion && PostFetcher.IsPostDeleted(post.Url, out dom) &&
                            DeletedAnswerFound != null)
                        {
                            DeletedAnswerFound(post);
                        }

                        logger.RemoveItem(post);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }