-
Notifications
You must be signed in to change notification settings - Fork 4
767_count_domens #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vovanbravin
wants to merge
3
commits into
dev
Choose a base branch
from
767_count_domens
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
767_count_domens #788
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import re | ||
| from http.cookiejar import domain_match | ||
|
|
||
| from .style_check_settings import StyleCheckSettings | ||
| from ..base_check import BaseReportCriterion, answer | ||
| from collections import Counter | ||
|
|
@@ -9,11 +11,14 @@ class ReferencesToLiteratureCheck(BaseReportCriterion): | |
| _description = '' | ||
| id = 'literature_references' | ||
|
|
||
| def __init__(self, file_info, min_ref=1, max_ref=1000, headers_map=None): | ||
| def __init__(self, file_info, min_ref=1, max_ref=1000, max_count_domains = 5,headers_map=None): | ||
| super().__init__(file_info) | ||
| self.headers = [] | ||
| self.domain_pattern = r'(?:https?|ftp)?://([^/\s?#]+)' | ||
| self.literature_header = None | ||
| self.literature_reference_text = [] | ||
| self.literature_domains = [] | ||
| self.max_count_domains = max_count_domains | ||
| self.name_pattern = r'список[ \t]*(использованных|использованной|)[ \t]*(источников|литературы)' | ||
| if headers_map: | ||
| self.config = headers_map | ||
|
|
@@ -59,7 +64,8 @@ def check(self): | |
| return answer(False, | ||
| f'В Списке использованных источников не найдено ни одного источника.<br><br>Проверьте корректность использования нумированного списка.') | ||
|
|
||
| duplicates = self.checking_duplicate_sources() | ||
| duplicates_ref = self.checking_duplicate_sources(self.literature_reference_text) | ||
| duplicates_domains = self.checking_duplicate_sources(self.literature_domains, self.max_count_domains) | ||
| references, ref_sequence = self.search_references(start_literature_par) | ||
| all_numbers = set(range(1, number_of_sources + 1)) | ||
| if len(references.symmetric_difference(all_numbers)) == 0: | ||
|
|
@@ -68,7 +74,7 @@ def check(self): | |
| elif ref_sequence: | ||
| result_str += f"Источники должны нумероваться в порядке упоминания в тексте. Неправильные последовательности: {'; '.join(num for num in ref_sequence)}" | ||
| return answer(False, result_str) | ||
| elif not duplicates: | ||
| elif not duplicates_ref and not duplicates_domains: | ||
| return answer(True, f"Пройдена!") | ||
| elif len(references.difference(all_numbers)): | ||
| if len(all_numbers.difference(references)) == 0: | ||
|
|
@@ -82,14 +88,24 @@ def check(self): | |
| all_numbers -= references | ||
| result_str = f'Упомянуты не все источники из списка.<br>Список источников без упоминания: {", ".join(str(num) for num in sorted(all_numbers))} <br> Всего источников: {number_of_sources}<br><br>' | ||
|
|
||
| if duplicates: | ||
| if duplicates_ref: | ||
| message = '' | ||
| for duplicate in duplicates: | ||
| for duplicate in duplicates_ref: | ||
| message += f'<li>Источники с номерами: {duplicate[1]} ссылаются на один и тот же источник: {duplicate[0]};</li>\n' | ||
| result_str += (f'Повторяющиеся источники:' | ||
| f'<ul>\n' | ||
| f'{message}' | ||
| f'</ul>') | ||
|
|
||
| if duplicates_domains: | ||
| message = '' | ||
| for duplicate in duplicates_domains: | ||
| message += f'<li>Источники с номерами: {duplicate[1]} ссылаются на один и тот же домен: {duplicate[0]};</li>\n' | ||
| result_str += (f'Повторяющиеся домены, максимум на один домен могут ссылаться не более {self.max_count_domains} источников:' | ||
| f'<ul>\n' | ||
| f'{message}' | ||
| f'</ul>') | ||
|
|
||
| result_str += ''' | ||
| Если возникли проблемы, попробуйте сделать следующее: | ||
| <ul> | ||
|
|
@@ -158,22 +174,16 @@ def add_references(self, k, prev_ref, array_of_references, ref_sequence): | |
| array_of_references.add(k) | ||
| return prev_ref | ||
|
|
||
| def checking_duplicate_sources(self) -> list: | ||
| """Функция нахождения дубликатов в источниках""" | ||
| counter = Counter([text.lower() for text in self.literature_reference_text]) | ||
|
|
||
| duplicates = [] | ||
| for text, count in counter.items(): | ||
| if count >= 2: | ||
| positions_duplicates = [i + 1 for i, text_in_ref in enumerate(self.literature_reference_text) if text == text_in_ref.lower()] | ||
| def checking_duplicate_sources(self, sources: list, max_count: int=2) -> list: | ||
| """Функция нахождения дубликатов в определенных позициях""" | ||
| domain_to_numbers = {} | ||
|
|
||
| if positions_duplicates: | ||
| duplicates.append(( | ||
| self.literature_reference_text[positions_duplicates[0] - 1], | ||
| positions_duplicates | ||
| )) | ||
| for number, domain in sources: | ||
| if domain not in domain_to_numbers: | ||
| domain_to_numbers[domain] = [] | ||
| domain_to_numbers[domain].append(number) | ||
|
Comment on lines
+181
to
+184
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. достаточно сделать for number, domain in sources:
domain_to_numbers.setdefault(domain, []).append(number) |
||
|
|
||
| return duplicates | ||
| return [(domain, numbers) for domain, numbers in domain_to_numbers.items() if len(numbers) >= max_count] | ||
|
|
||
|
|
||
| def find_start_paragraph(self): | ||
|
|
@@ -194,7 +204,12 @@ def count_sources_vkr(self, header): | |
| break | ||
| # if re.search(f"дата обращения", child["text"].lower()): | ||
| literature_counter += 1 | ||
| self.literature_reference_text.append(child["text"]) | ||
| self.literature_reference_text.append((literature_counter, child["text"])) | ||
| domain_match = re.search(self.domain_pattern, child["text"], re.IGNORECASE) | ||
|
|
||
| if domain_match and domain_match.group(1): | ||
| self.literature_domains.append((literature_counter, domain_match.group(1))) | ||
|
|
||
| return literature_counter | ||
|
|
||
| def count_sources(self): | ||
|
|
@@ -218,7 +233,11 @@ def count_sources(self): | |
| for ind in range(first_string + 1, last_string): | ||
| if re.match(f"{literature_counter + 1}.", one_page[ind]): | ||
| literature_counter += 1 | ||
| self.literature_reference_text.append(one_page[ind]) | ||
| self.literature_reference_text.append((literature_counter, one_page[ind])) | ||
| domain_match = re.search(self.domain_pattern, one_page[ind]) | ||
| if domain_match and domain_match.group(1): | ||
| self.literature_domains.append((literature_counter, domain_match.group(1))) | ||
|
|
||
| return literature_counter | ||
|
|
||
| def search_literature_start_pdf(self): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделайте логику ниже единой и непрерываемой на середине