From 933352db30ff284417b224f9d36da5516c7fdc57 Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 3 Jun 2024 17:22:05 +0300 Subject: [PATCH 1/4] check for sequence is added --- .../report_checks/literature_references.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/main/checks/report_checks/literature_references.py b/app/main/checks/report_checks/literature_references.py index e271ba4c..889c9a8c 100644 --- a/app/main/checks/report_checks/literature_references.py +++ b/app/main/checks/report_checks/literature_references.py @@ -45,13 +45,16 @@ def check(self): if not number_of_sources: return answer(False, f'В Списке использованных источников не найдено ни одного источника.

Проверьте корректность использования нумированного списка.') - references = self.search_references(start_literature_par) + references, ref_sequence = self.search_references(start_literature_par) all_numbers = set() for i in range(1, number_of_sources + 1): all_numbers.add(i) if len(references.symmetric_difference(all_numbers)) == 0: if not self.min_ref <= number_of_sources <= self.max_ref: return answer(False, f'Список источников оформлен верно, однако их количество ({number_of_sources}) не удовлетворяет необходимому критерию.
Количество источников должно быть от {self.min_ref} до {self.max_ref}.') + elif ref_sequence: + result_str += f"Источники должны нумероваться в порядке упоминания в тексте. Неправильная последовательность: [{'], ['.join(num for num in ref_sequence)}]" + return answer(False, result_str) else: return answer(True, f"Пройдена!") elif len(references.difference(all_numbers)): @@ -76,6 +79,8 @@ def check(self): return answer(False, result_str) def search_references(self, start_par): + prev_ref = 0 + ref_sequence = [] array_of_references = set() for i in range(0, start_par): if isinstance(self.file.paragraphs[i], str): @@ -89,9 +94,16 @@ def search_references(self, start_par): start, end = re.split(r'[ -]+', one_part) for k in range(int(start), int(end) + 1): array_of_references.add(k) + if int(k) - prev_ref != 1: + ref_sequence.append(str(k)) + prev_ref = int(k) elif one_part != '': array_of_references.add(int(one_part)) - return array_of_references + if int(one_part) - prev_ref != 1: + ref_sequence.append(str(one_part)) + prev_ref = int(one_part) + print(array_of_references, ref_sequence) + return array_of_references, ref_sequence def find_start_paragraph(self): start_index = 0 From 08ab6f3b44a4833c2186b6bef75d6c2d897db42e Mon Sep 17 00:00:00 2001 From: Marina Date: Mon, 3 Jun 2024 20:10:30 +0300 Subject: [PATCH 2/4] view of result_string is changed --- app/main/checks/report_checks/literature_references.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/main/checks/report_checks/literature_references.py b/app/main/checks/report_checks/literature_references.py index 889c9a8c..d5e77c76 100644 --- a/app/main/checks/report_checks/literature_references.py +++ b/app/main/checks/report_checks/literature_references.py @@ -53,7 +53,7 @@ def check(self): if not self.min_ref <= number_of_sources <= self.max_ref: return answer(False, f'Список источников оформлен верно, однако их количество ({number_of_sources}) не удовлетворяет необходимому критерию.
Количество источников должно быть от {self.min_ref} до {self.max_ref}.') elif ref_sequence: - result_str += f"Источники должны нумероваться в порядке упоминания в тексте. Неправильная последовательность: [{'], ['.join(num for num in ref_sequence)}]" + result_str += f"Источники должны нумероваться в порядке упоминания в тексте. Неправильные последовательности: {'; '.join(num for num in ref_sequence)}" return answer(False, result_str) else: return answer(True, f"Пройдена!") @@ -95,14 +95,15 @@ def search_references(self, start_par): for k in range(int(start), int(end) + 1): array_of_references.add(k) if int(k) - prev_ref != 1: - ref_sequence.append(str(k)) + ref_sequence.append(f'[{prev_ref}], [{k}]') prev_ref = int(k) elif one_part != '': array_of_references.add(int(one_part)) if int(one_part) - prev_ref != 1: - ref_sequence.append(str(one_part)) + ref_sequence.append(f'[{prev_ref}], [{one_part}]') prev_ref = int(one_part) - print(array_of_references, ref_sequence) + if ref_sequence[0][1] == '0': + ref_sequence[0] = ref_sequence[0].replace('[0],', '') return array_of_references, ref_sequence def find_start_paragraph(self): From c6e00a9e7278f7de87bf5ef8b6985125524af104 Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 4 Jun 2024 14:47:46 +0300 Subject: [PATCH 3/4] logic of lit_sequence is changed: now only first mention of literature references is counts --- .../report_checks/literature_references.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/main/checks/report_checks/literature_references.py b/app/main/checks/report_checks/literature_references.py index d5e77c76..c439a3bc 100644 --- a/app/main/checks/report_checks/literature_references.py +++ b/app/main/checks/report_checks/literature_references.py @@ -93,17 +93,26 @@ def search_references(self, start_par): if re.match(r'\d+[ \-]+\d+', one_part): start, end = re.split(r'[ -]+', one_part) for k in range(int(start), int(end) + 1): + if k not in array_of_references: + if int(k) - prev_ref != 1: + ref_sequence.append(f'[{prev_ref}], [{k}]') + prev_ref = int(k) + else: + if int(k) - prev_ref == 1: + prev_ref = int(k) array_of_references.add(k) - if int(k) - prev_ref != 1: - ref_sequence.append(f'[{prev_ref}], [{k}]') - prev_ref = int(k) elif one_part != '': + if int(one_part) not in array_of_references: + if int(one_part) - prev_ref != 1: + ref_sequence.append(f'[{prev_ref}], [{one_part}]') + prev_ref = int(one_part) + else: + if int(one_part) - prev_ref == 1: + prev_ref = int(one_part) array_of_references.add(int(one_part)) - if int(one_part) - prev_ref != 1: - ref_sequence.append(f'[{prev_ref}], [{one_part}]') - prev_ref = int(one_part) - if ref_sequence[0][1] == '0': - ref_sequence[0] = ref_sequence[0].replace('[0],', '') + if ref_sequence: + if ref_sequence[0][1] == '0': + ref_sequence[0] = ref_sequence[0].replace('[0],', '') return array_of_references, ref_sequence def find_start_paragraph(self): From 5a2f0ef86bba581962c2bbdc473f6834d2bb5f16 Mon Sep 17 00:00:00 2001 From: Marina Date: Wed, 5 Jun 2024 10:41:30 +0300 Subject: [PATCH 4/4] rided of dublicate parts in code --- .../report_checks/literature_references.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/main/checks/report_checks/literature_references.py b/app/main/checks/report_checks/literature_references.py index c439a3bc..6a606884 100644 --- a/app/main/checks/report_checks/literature_references.py +++ b/app/main/checks/report_checks/literature_references.py @@ -93,28 +93,25 @@ def search_references(self, start_par): if re.match(r'\d+[ \-]+\d+', one_part): start, end = re.split(r'[ -]+', one_part) for k in range(int(start), int(end) + 1): - if k not in array_of_references: - if int(k) - prev_ref != 1: - ref_sequence.append(f'[{prev_ref}], [{k}]') - prev_ref = int(k) - else: - if int(k) - prev_ref == 1: - prev_ref = int(k) - array_of_references.add(k) + prev_ref = self.add_references(k, prev_ref, array_of_references, ref_sequence) elif one_part != '': - if int(one_part) not in array_of_references: - if int(one_part) - prev_ref != 1: - ref_sequence.append(f'[{prev_ref}], [{one_part}]') - prev_ref = int(one_part) - else: - if int(one_part) - prev_ref == 1: - prev_ref = int(one_part) - array_of_references.add(int(one_part)) + prev_ref = self.add_references(int(one_part), prev_ref, array_of_references, ref_sequence) if ref_sequence: if ref_sequence[0][1] == '0': ref_sequence[0] = ref_sequence[0].replace('[0],', '') return array_of_references, ref_sequence + def add_references(self, k, prev_ref, array_of_references, ref_sequence): + if k not in array_of_references: + if k - prev_ref != 1: + ref_sequence.append(f'[{prev_ref}], [{k}]') + prev_ref = k + else: + if k - prev_ref == 1: + prev_ref = k + array_of_references.add(k) + return prev_ref + def find_start_paragraph(self): start_index = 0 for i in range(len(self.file.paragraphs)):