コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            CommentMethods commentMethods = new CommentMethods();
            string         articleName    = context.Request.Form["articleName"]; //文章名字
            string         authorName     = context.Request.Form["authorName"];  //文章名字
            string         content        = context.Request.Form["content"];     //base64字节

            #region 切割base64
            string str   = "base64,";
            int    index = content.IndexOf(str) + str.Length;
            int    end   = content.Length - index;
            content = content.Substring(index, end);
            #endregion


            string path     = context.Server.MapPath("../Papers/system/");
            Random rd       = new Random();
            string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "-" + rd.Next(100, 999).ToString() + "-" + articleName;

            byte[] buff = Convert.FromBase64String(content);
            if (commentMethods.ByteToFile(content, path, fileName))
            {
                Bll.AuthorBll authorBll = new Bll.AuthorBll();
                var           author    = new Model.Author()
                {
                    Id     = Guid.NewGuid().ToString(),
                    Name   = authorName,
                    Adress = "",
                    Email  = ""
                };
                if (authorBll.Add(author))
                {
                    Bll.PapersBll papersBll = new Bll.PapersBll();
                    var           paper     = new Model.Papers()
                    {
                        Id       = Guid.NewGuid().ToString(),
                        AuthorId = author.Id,
                        Name     = articleName,
                        Url      = "../Papers/system/" + fileName,
                        Title    = ""
                    };
                    if (papersBll.Add(paper))
                    {
                        var             ketWords    = commentMethods.GetKeyWord(commentMethods.GetAll(path + fileName));
                        Bll.KeyWordsBll keyWordsBll = new Bll.KeyWordsBll();
                        var             keyWord     = new Model.KeyWords()
                        {
                            Id       = Guid.NewGuid().ToString(),
                            PaperId  = paper.Id,
                            KeyWord1 = ketWords[0],
                            KeyWord2 = ketWords[1],
                            KeyWord3 = ketWords[2],
                            KeyWord4 = ketWords[3],
                            KeyWord5 = ketWords[4],
                            KeyWord6 = ketWords[5],
                        };
                        if (keyWordsBll.Add(keyWord))
                        {
                            context.Response.Write(JsonConvert.SerializeObject(new ReturnMessage()
                            {
                                Code = 1, Message = "添加成功"
                            }));
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string articleName  = context.Request.Form["articleName"];  //文章名字
            string authorName   = context.Request.Form["authorName"];   //作者名字
            string isUseMyHouse = context.Request.Form["isUseMyHouse"]; //是否使用自建库 true
            string content      = context.Request.Form["content"];      //string


            if (System.Web.HttpContext.Current.Request.Cookies["userName"] == null || context.Session["userName"] == null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new ReturnMessage()
                {
                    Code = 0, Message = "您没有登陆,请前往登录后检测"
                }));
            }
            else
            {
                //            //提取用户文章中的高频词
                CommentMethods commentMethods = new CommentMethods();
                var            userkeyWords   = commentMethods.GetKeyWord(content);
                //获取系统关键词
                Bll.KeyWordsBll keyWordsBll    = new Bll.KeyWordsBll();
                var             systemKeyWords = keyWordsBll.GetAllList();

                List <string> result = new List <string>();
                for (int i = 0; i < systemKeyWords.Count; i++)
                {
                    var a = systemKeyWords[i].KeyWord1 + "," + systemKeyWords[i].KeyWord2 + "," + systemKeyWords[i].KeyWord3 + "," + systemKeyWords[i].KeyWord4 + "," + systemKeyWords[i].KeyWord5 + "," + systemKeyWords[i].KeyWord6;
                    result.Add(a);
                }
                //两者对比,筛选数据相同的
                int           count    = 0;
                List <string> papersId = new List <string>();
                for (int i = 0; i < userkeyWords.Count; i++)
                {
                    for (int j = 0; j < result.Count; j++)
                    {
                        bool isContains = result[j].Trim().ToString().Contains(userkeyWords[i].Trim().ToString());
                        if (isContains)
                        {
                            papersId.Add(systemKeyWords[j].PaperId);
                            count++;
                            if (count > 2)
                            {
                                break;
                            }
                        }
                    }
                    break;
                }
                //获取对应文章
                Bll.PapersBll       papersBll = new Bll.PapersBll();
                List <Model.Papers> papers    = new List <Model.Papers>();

                papers = papersBll.GetAllList().Where(m => papersId.Contains(m.Id)).ToList();
                //进行比较
                List <double> numbers = new List <double>();
                MyDuplicateChecking.MyDuplicateChecking myDuplicateChecking = new MyDuplicateChecking.MyDuplicateChecking();

                List <Reslut> resluts = new List <Reslut>();
                for (int i = 0; i < papers.Count; i++)
                {
                    var path = papers[i].Url.Trim().ToString();
                    path = context.Server.MapPath(path);
                    var str         = commentMethods.GetAll(path);
                    var userSplit   = content.Split('\n');
                    var systemSplit = str.Split('\r');


                    #region 获取段落/为了给下边数组赋值
                    int paragraph = 0;
                    for (int q = 0; q < userSplit.Length; q++)
                    {
                        var userSplitLength = userSplit[q].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "").Length;
                        if (userSplitLength >= 20)
                        {
                            paragraph++;
                        }
                    }
                    #endregion


                    string[] numUserStr   = new string[paragraph]; //具有相似度的用户字符串
                    string[] numSystemStr = new string[paragraph]; //相似度最高的系统字符串
                    double[] numStr       = new double[paragraph]; //相似度


                    #region

                    for (int q = 0; q < paragraph; q++)
                    {
                        var userSplitLength = userSplit[q].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "").Length;
                        if (userSplitLength >= 20)
                        {
                            for (int w = 0; w < systemSplit.Length; w++)
                            {
                                var systemSplitLength = systemSplit[w].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "").Length;
                                if (systemSplitLength >= 20)
                                {
                                    var    userSplitLengthW   = userSplit[q].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
                                    var    systemSplitLengthQ = systemSplit[w].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
                                    double num = double.Parse(myDuplicateChecking.SumCosine(userSplitLengthW, systemSplitLengthQ));
                                    if (num > 0.5)
                                    {
                                        if (num > numStr[q - 1])
                                        {
                                            numUserStr[q - 1] = userSplit[q].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", ""); numSystemStr[q - 1] = systemSplit[w].Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
                                            numStr[q - 1]     = num;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion


                    #region 将空数组剔除
                    List <string> numUserStr1   = new List <string>();
                    List <string> numSystemStr1 = new List <string>();
                    List <double> numStr1       = new List <double>();
                    for (int r = 0; r < numUserStr.Length; r++)
                    {
                        if (numSystemStr[r] != null)
                        {
                            numUserStr1.Add(numSystemStr[r]);
                            numSystemStr1.Add(numSystemStr[r]);
                            numStr1.Add(numStr[r]);
                        }
                    }
                    #endregion

                    resluts.Add(new Reslut()
                    {
                        useStr    = numUserStr1,
                        systemStr = numSystemStr1,
                        num       = numStr1,
                    });


                    #region 全文直接对比
                    numbers.Add(double.Parse(myDuplicateChecking.SumCosine(content, str)));
                    #endregion
                }



                for (int n = 0; n < numbers.Count - 1; n++)
                {     //外层循环控制排序次数,第几轮
                    for (int j = 0; j < numbers.Count - 1 - n; j++)
                    { //内层循环控制每一轮排序多少次
                        if (numbers[j] > numbers[j + 1])
                        {
                            var paper = papers[j];
                            papers[j]     = papers[j + 1];
                            papers[j + 1] = paper;


                            double max = numbers[j];
                            numbers[j]     = numbers[j + 1];
                            numbers[j + 1] = max;
                        }
                    }
                }

                //小数在前大数在后
                List <Model.Papers> checkPapers = new List <Model.Papers>()
                ; List <double>     checkNum    = new List <double>();
                for (int i = 0; i < numbers.Count; i++)
                {
                    checkNum.Add(numbers[i]);
                    checkPapers.Add(papers[i]);
                }



                context.Response.Write(JsonConvert.SerializeObject(resluts));
            }
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string articleName  = context.Request.Form["articleName"];  //文章名字
            string authorName   = context.Request.Form["authorName"];   //作者名字
            string isUseMyHouse = context.Request.Form["isUseMyHouse"]; //是否使用自建库 true
            string content      = context.Request.Form["content"];      //string
            //提取用户文章中的高频词
            CommentMethods commentMethods = new CommentMethods();
            var            userkeyWords   = commentMethods.GetKeyWord(content);

            //获取系统关键词
            Bll.KeyWordsBll keyWordsBll    = new Bll.KeyWordsBll();
            var             systemKeyWords = keyWordsBll.GetAllList();

            List <string> result = new List <string>();

            for (int i = 0; i < systemKeyWords.Count; i++)
            {
                var a = systemKeyWords[i].KeyWord1 + "," + systemKeyWords[i].KeyWord2 + "," + systemKeyWords[i].KeyWord3 + "," + systemKeyWords[i].KeyWord4 + "," + systemKeyWords[i].KeyWord5 + "," + systemKeyWords[i].KeyWord6;
                result.Add(a);
            }
            //两者对比,筛选数据相同的
            int           count    = 0;
            List <string> papersId = new List <string>();

            for (int i = 0; i < userkeyWords.Count; i++)
            {
                for (int j = 0; j < result.Count; j++)
                {
                    bool isContains = result[j].Trim().ToString().Contains(userkeyWords[i].Trim().ToString());
                    if (isContains)
                    {
                        papersId.Add(systemKeyWords[j].PaperId);
                        count++;
                        if (count > 2)
                        {
                            break;
                        }
                    }
                }
                break;
            }
            //获取对应文章
            Bll.PapersBll       papersBll = new Bll.PapersBll();
            List <Model.Papers> papers    = new List <Model.Papers>();

            //for (int i = 0; i < papersId.Count; i++)
            //{
            //    papers = papersBll.GetAllList().Where(m => );
            //}
            papers = papersBll.GetAllList().Where(m => papersId.Contains(m.Id)).ToList();
            //进行比较
            List <double> numbers  = new List <double>();
            List <string> numbers1 = new List <string>();

            MyDuplicateChecking.MyDuplicateChecking myDuplicateChecking = new MyDuplicateChecking.MyDuplicateChecking();
            for (int i = 0; i < papers.Count; i++)
            {
                var path = papers[i].Url.Trim().ToString();
                var str  = commentMethods.GetAll(path);
                numbers1.Add(myDuplicateChecking.SumCosine(content, str));
                string asd = myDuplicateChecking.SumCosine(content, str);
                double s   = double.Parse(asd);
                numbers.Add(s);
            }

            //做一个冒泡排序
            for (int i = 0; i < numbers.Count - 1; i++)
            {
                for (int j = 0; j < numbers.Count - i - 1; j++)
                {
                    // 临时变量,用于元素两两交换
                    double temp = 0;
                    if (numbers[j] > numbers[j + 1])
                    {
                        temp           = numbers[j];
                        numbers[j]     = numbers[j + 1];
                        numbers[j + 1] = temp;
                    }
                }
            }

            var checkMaxNum = numbers[numbers.Count - 1];



            //提取该片文章中的高频词
            //根据高频词去查询数据库中对应文章
            //根据查询出来的结果进行比较
            //结果合格被平台收录
            //Bll.AuthorBll authorBll = new Bll.AuthorBll();
            //Model.Author author = new Model.Author();
            //author.Id = Guid.NewGuid().ToString();
            //author.Name = authorName;
            //author.Email = "";
            //author.Adress = "";
            //if (authorBll.Add(author))
            //{
            //    try
            //    {
            //        Bll.PapersBll papersBll = new Bll.PapersBll();
            //        var paper = new Model.Papers()
            //        {
            //            Id = Guid.NewGuid().ToString(),
            //            Name = articleName,
            //            Title = "",
            //            Url = (string)context.Session["systemPaperPath"],
            //            AuthorId = author.Id
            //        };
            //        if (papersBll.Add(paper))
            //        {
            //            var keyWord = new Model.KeyWords()
            //            {
            //                Id = Guid.NewGuid().ToString(),
            //                PaperId = paper.Id,
            //                KeyWord1 = keyWords[0].Trim().ToString(),
            //                KeyWord2 = keyWords[1].Trim().ToString(),
            //                KeyWord3 = keyWords[2].Trim().ToString(),
            //                KeyWord4 = keyWords[3].Trim().ToString(),
            //                KeyWord5 = keyWords[4].Trim().ToString(),
            //                KeyWord6 = keyWords[5].Trim().ToString(),
            //            };
            //            new Bll.KeyWordsBll().Add(keyWord);
            //        }
            //        else
            //        {

            //        }



            //    }
            //    catch (Exception ex)
            //    {

            //        throw ex;
            //    }

            //}
        }