示例#1
0
        /// <summary>
        /// Ищет совпадающие абзацы в двух текстах
        /// </summary>
        /// <param name="inputtext"></param>
        /// <param name="comptext"></param>
        /// <returns></returns>
        private string[] FindPlagiarism(string inputtext, string comptext)
        {
            var separator = new string[5];

            try
            {
                separator[0] = "\n";
                separator[1] = "\t";
                separator[2] = "!";
                separator[3] = "?";
                separator[4] = ".";
                var shift = 0;
                if (testbutton.Checked || _splitinputtext == null)
                {
                    _splitinputtext = inputtext.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                }
                var split2 = comptext.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                var result = new string[_splitinputtext.Length];
                foreach (string t in _splitinputtext)
                {
                    foreach (string t1 in split2.Where(t1 => !(Shingles.CompareStrings(t, t1, 2) <= 40)))
                    {
                        result[shift++] = t1;
                        break;
                    }
                }
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Определяет,был ли плагиат в исходном тексте
        /// </summary>
        /// /// <param name="filename"></param>
        /// <returns>Степень совпадения и сплагиаченные предложения</returns>
        private Results ShingleDetect(string filename)
        {
            const double similarityLow1Stage = 48;
            const double similarityLow2Stage = 5.641;
            string       compText;

            try
            {
                compText = ReadFile(filename);
            }
            catch
            {
                return(new Results(filename, 0, 0, "fail", false));
            }
            Monitor.Enter(_inputtextblock);
            var fulltext = _inputText;

            Monitor.Exit(_inputtextblock);
            var similarity = new double[2];
            var info       = new FileInfo(filename);

            similarity[0] = Shingles.CompareStrings(fulltext, compText, 1);
            Results results;

            string[] foundPlagiarism = null;
            var      fullResults     = showFullResults.Checked;

            if (fullResults)
            {
                foundPlagiarism = FindPlagiarism(fulltext, compText);
            }
            if (similarity[0] < similarityLow1Stage)
            {
                results = new Results(info.Name, similarity[0], 1, null, false);
                if (fullResults)
                {
                    results.PlagiarisedSentences = foundPlagiarism;
                }
                return(results);
            }
            similarity[1] = Shingles.CompareStrings(fulltext, compText, 3);
            if (similarity[1] < similarityLow2Stage)
            {
                results = new Results(info.Name, similarity[1], 2, null, false);
                if (fullResults)
                {
                    results.PlagiarisedSentences = foundPlagiarism;
                }
                return(results);
            }
            results = new Results(info.Name, similarity[1], 2, null, true);
            if (fullResults)
            {
                results.PlagiarisedSentences = foundPlagiarism;
            }
            return(results);
        }