예제 #1
0
        private List <CodeCheckResult> ExcuteCodeCheck(List <string> Files, double MinRange, ref double MaxScore, ref int MaxIndex1, ref int MaxIndex2)
        {
            List <CodeCheckResult> OutputExcel = new List <CodeCheckResult>();

            TOKEN     GenerateToken     = new TOKEN();
            Sim       CalculateSimScore = new Sim();
            DFA       CalculateDFAScore = new DFA();
            Winnowing CalculateWinScore = new Winnowing();
            WinText   GenerateWinText   = new WinText();

            BeginProgress();

            int total = ((Files.Count() - 1) * Files.Count()) / 2;
            int Counter = 0, Bar = 0;

            List <string>         WinFiles = new List <string>();
            List <List <VN> >     VNFiles = new List <List <VN> >();
            List <List <string> > SimFiles = new List <List <string> >();

            for (int i = 0; i < Files.Count(); ++i)
            {
                List <VN> MF = new List <VN>();
                CalculateDFAScore.Get_VN(Files[i], MF);
                VNFiles.Add(MF);

                List <string> SF = GenerateToken.Read_file(Files[i]);
                SimFiles.Add(SF);

                WinFiles.Add(GenerateWinText.FileFilter(Files[i]));
            }

            for (int i = 0; i < Files.Count(); ++i)
            {
                for (int j = i + 1; j < Files.Count(); ++j)
                {
                    double SimScore = CalculateSimScore.Sim_Run(SimFiles[i], SimFiles[j]);
                    double DFAScore = CalculateDFAScore.GetVarSim(VNFiles[i], VNFiles[j]);
                    double WinScore = CalculateWinScore.TextSimilarity(WinFiles[i], WinFiles[j]);

                    double TotalScore = DFAScore * 0.3 + SimScore * 0.5 + WinScore * 0.2;
                    //double TotalScore = SimScore * 1.0;
                    if (TotalScore > MaxScore)
                    {
                        MaxIndex1 = i;
                        MaxIndex2 = j;
                        MaxScore  = TotalScore;
                    }
                    // System.Diagnostics.Debug.WriteLine(TotalScore.ToString());

                    Bar = (Counter) * 100 / total;
                    Counter++;
                    SetProgress(Bar);
                    System.Threading.Thread.Sleep(10);

                    //System.Diagnostics.Debug.WriteLine(Bar.ToString());
                    if (TotalScore < MinRange)
                    {
                        continue;
                    }

                    OutputExcel.Add(
                        new CodeCheckResult(Files[i].Substring(Files[i].LastIndexOf('\\') + 1)
                                            , Files[j].Substring(Files[j].LastIndexOf('\\') + 1)
                                            , TotalScore.ToString() + "%"));
                }
            }
            FinishProgress();

            return(OutputExcel);
        }
예제 #2
0
        protected void Bt_excute_Click(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo DirInfo = new System.IO.DirectoryInfo(Server.MapPath("../SingleFile/"));
            if (!DirInfo.Exists)
            {
                return;
            }

            System.IO.DirectoryInfo[] Dirs = DirInfo.GetDirectories();

            //获取对应语言文件路径集合

            FileInfo[] Paths = DirInfo.GetFiles("*." + Request.Form["lang"].ToString());

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


            //循环Paths 将每个文件信息放入List里
            foreach (FileInfo filepath in Paths)
            {
                files.Add(filepath.FullName);
            }
            if (Paths.Count() <= 1)
            {
                Response.Write("<script>alert('对应类型的文件数少于两个')</script>");
            }
            else
            {
                TOKEN     GenerateToken     = new TOKEN();
                Sim       CalculateSimScore = new Sim();
                DFA       CalculateDFAScore = new DFA();
                List <VN> MarkFile1         = new List <VN>();
                List <VN> MarkFile2         = new List <VN>();
                Winnowing Win             = new Winnowing();
                WinText   GenerateWinText = new WinText();

                CalculateDFAScore.Get_VN(files[0], MarkFile1);
                CalculateDFAScore.Get_VN(files[1], MarkFile2);

                //System.Diagnostics.Debug.WriteLine(Markfile1.Count().ToString());

                string WinText1 = GenerateWinText.FileFilter(files[0]);
                string WinText2 = GenerateWinText.FileFilter(files[1]);

                double WinScore = Win.TextSimilarity(WinText1, WinText2);
                double SimScore = CalculateSimScore.Sim_Run(GenerateToken.Read_file(files[0]), GenerateToken.Read_file(files[1]));
                double DFAScore = CalculateDFAScore.GetVarSim(MarkFile1, MarkFile2);

                double TotalScore = DFAScore * 0.3 + SimScore * 0.5 + WinScore * 0.2;

                string FileName1 = files[0].Substring(files[0].LastIndexOf('\\') + 1);
                string FileName2 = files[1].Substring(files[1].LastIndexOf('\\') + 1);

                Excute_info.Text = FileName1 + " " + FileName2 + "  代码相似度:" + TotalScore.ToString() + "%";

                Label3.Text   = FileName1;
                Label2.Text   = FileName2;
                Literal1.Text = "<textarea name=\"code\" class=\"" + GetHighlightLang(Request.Form["lang"].ToString()) + "\" rows=\"15\" cols=\"100\"> "
                                + CommonFunction.GetFileContent(files[0]) + "</textarea>";
                Literal2.Text = "<textarea name=\"code\" class=\"" + GetHighlightLang(Request.Form["lang"].ToString()) + "\" rows=\"15\" cols=\"100\"> "
                                + CommonFunction.GetFileContent(files[1]) + "</textarea>";

                Upload_info.Text = "";
                for (int i = 0; i < files.Count; ++i)
                {
                    if (System.IO.File.Exists(files[i]))
                    {
                        System.IO.File.Delete(files[i]);
                    }
                }
            }
        }