private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { // Загружаем все данные. DataController data = new DataController(openFileDialog.FileName); // Нормализируем все данные. WorkModel clearedManuscript = new WorkModel(DataController.Manuscript.AuthorName, TextNormalisation.ClearText(DataController.Manuscript.Text)); List<WorkModel> clearedBooks = new List<WorkModel>(); foreach (WorkModel book in DataController.Books) clearedBooks.Add(new WorkModel(book.AuthorName, TextNormalisation.ClearText(book.Text))); // Сравниваем тексты. TextComparison textComparison = new TextComparison(clearedManuscript, clearedBooks); List<CopiedFragmentModel> copiedFragments = textComparison.CopiedText; // Выводим денормализированные данные. ReportSaver.SaveReport(copiedFragments, DataController.Manuscript.AuthorName); } this.Close(); }
/// <summary> /// Загружает указанный файл /// </summary> /// <param name="path"></param> /// <returns></returns> public WorkModel LoadText(string path) { using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding(1251))) { WorkModel courseWork = new WorkModel(); int position = path.LastIndexOf("\\"); string fileName = path.Substring(position + 1); courseWork.Text = sr.ReadToEnd(); courseWork.AuthorName = fileName.Substring(0, fileName.Length - 4); return courseWork; } }
/// <summary> /// /// </summary> /// <param name="newFile">Проверяемый файл.</param> /// <param name="text">Один из новых текстов.</param> public TextComparison(WorkModel clearedManuscript, List<WorkModel> clearedBooks) { CopiedText = new List<CopiedFragmentModel>(); int j = 0; foreach (WorkModel clearedBook in clearedBooks) { List<string> CopiedFragments = new List<string>(); List<long> manuscriptHash = GetHashShiling(clearedManuscript.Text.Split(' ').ToList()); List<long> bookHash = GetHashShiling(clearedBook.Text.Split(' ').ToList()); double simularity = Compair(manuscriptHash,bookHash); List<Result> tempResult = GetEqualsPeace(manuscriptHash, bookHash); CopiedFragments = TextDenormalisation.CreateFullText(TextDenormalisation.СonformityPeace(DataController.Books[j].Text, clearedBook.Text),tempResult , DataController.Books[j].Text, SHILING_LEN); if (CopiedFragments != null && CopiedFragments.Count > 0) { CopiedText.Add(new CopiedFragmentModel(clearedBook.AuthorName, simularity, CopiedFragments)); Results.Add(tempResult); } j++; } }