-
Notifications
You must be signed in to change notification settings - Fork 4
first try of count_lit_ref #564
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
MarinaProsche
wants to merge
6
commits into
dev
Choose a base branch
from
539_links_count_in_spec_chapter
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e522e11
first try of count_lit_ref
MarinaProsche e8203b7
structure of check is changed (need to improve results string)
MarinaProsche a92fd08
limits are added, structure is ready
MarinaProsche ad7002f
improving of html view
MarinaProsche db387f3
add annotation and fix
vovanbravin 34a143d
Merge branch 'dev' into 539_links_count_in_spec_chapter
HadronCollider 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
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
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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import re | ||
| from .style_check_settings import StyleCheckSettings | ||
| from ..base_check import BaseReportCriterion, answer | ||
|
|
||
|
|
||
| class LitRefInChapter(BaseReportCriterion): | ||
| label = "Проверка количества ссылок на источники в определенном разделе" | ||
| description = '' | ||
| id = 'references_in_chapter_check' | ||
|
|
||
| def __init__(self, file_info, min_ref_value=0.5, max_ref_value=1, headers_map=None): | ||
| super().__init__(file_info) | ||
| self.chapters_for_lit_ref = {} | ||
| self.lit_ref_count = {} | ||
| self.min_ref_value = min_ref_value | ||
| self.max_ref_value = max_ref_value | ||
| if headers_map: | ||
| self.config = headers_map | ||
| else: | ||
| self.config = 'VKR_HEADERS' if (self.file_type['report_type'] == 'VKR') else 'LR_HEADERS' | ||
|
|
||
| def late_init(self): | ||
| self.chapters = self.file.make_chapters(self.file_type['report_type']) | ||
| self.headers_main = self.file.get_main_headers(self.file_type['report_type']) | ||
| if self.headers_main in StyleCheckSettings.CONFIGS.get(self.config): | ||
| self.chapters_for_lit_ref = StyleCheckSettings.CONFIGS.get(self.config)[self.headers_main][ | ||
| 'chapters_for_lit_ref'] | ||
| else: | ||
| if 'any_header' in StyleCheckSettings.CONFIGS.get(self.config): | ||
| self.chapters_for_lit_ref = StyleCheckSettings.CONFIGS.get(self.config)['any_header'][ | ||
| 'chapters_for_lit_ref'] | ||
|
|
||
| def check(self): | ||
| if self.file.page_counter() < 4: | ||
| return answer(False, "В отчете недостаточно страниц. Нечего проверять.") | ||
| self.late_init() | ||
| if not self.chapters_for_lit_ref: | ||
| return answer(True, 'Для загруженной работы данная проверка не предусмотрена.') | ||
| result = [] | ||
| result_str = f'Пройдена!' | ||
| currant_head = '' | ||
| chapter_for_check = 0 | ||
| ref_in_annotation = False | ||
| for chapter in self.chapters: | ||
| header = chapter["text"].lower() | ||
| if currant_head: | ||
| self.lit_ref_count[currant_head].append(chapter['number']) | ||
| if currant_head in self.chapters_for_lit_ref: | ||
| chapter_for_check += 1 | ||
| ref_count = len(self.search_references(self.lit_ref_count[currant_head][0], | ||
| self.lit_ref_count[currant_head][1])) | ||
| if ref_count > self.chapters_for_lit_ref[currant_head][1] or ref_count < \ | ||
| self.chapters_for_lit_ref[currant_head][0]: | ||
| result.append(f'«{currant_head[0].upper() + currant_head[1:]}» : {ref_count}') | ||
| if currant_head == 'аннотация' or currant_head == 'annotation': | ||
| ref_in_annotation = True | ||
| self.lit_ref_count[header] = [chapter['number'], ] | ||
| currant_head = header | ||
| if result: | ||
| if chapter_for_check > 0: | ||
| ref_value = round((chapter_for_check - len(result)) / chapter_for_check, 2) | ||
| else: | ||
| ref_value = 1.0 | ||
| result_str = (f'Доля соответствия количества ссылок необходимому в требуемых разделах равна {ref_value}' | ||
| f'<br><b>Количество ссылок на источники не удовлетворяет допустимому в следующих разделах:</b> <br> {"<br>".join(res for res in result)}' | ||
| f'<br><b> Допустимые пороги количества ссылок:</b> <br>' | ||
| f'{"<br>".join(f"«{chapter.capitalize()}»: от {limit[0]} до {limit[1]}" for chapter, limit in self.chapters_for_lit_ref.items())}') | ||
| result_str += '<b>В аннотации не должно быть ссылок на литературу.</b>' if ref_in_annotation else '' | ||
| if ref_value >= self.max_ref_value and not ref_in_annotation: | ||
| return answer(1, f'Пройдена!') | ||
| elif ref_value >= self.min_ref_value and not ref_in_annotation: | ||
| return answer(ref_value, f'Частично пройдена! {result_str}') | ||
| else: | ||
| return answer(0, f'Не пройдена! {result_str}') | ||
| elif ref_in_annotation: | ||
| return answer(0, 'В аннотации не должно быть ссылок на литературу.') | ||
| else: | ||
| return answer(1, result_str) | ||
|
|
||
| def search_references(self, start_par, end_par): | ||
| array_of_references = [] | ||
| for i in range(start_par, end_par): | ||
| if isinstance(self.file.paragraphs[i], str): | ||
| detected_references = re.findall(r'\[[\d \-,]+\]', self.file.paragraphs[i]) | ||
| else: | ||
| detected_references = re.findall(r'\[[\d \-,]+\]', self.file.paragraphs[i].paragraph_text) | ||
| if detected_references: | ||
| for reference in detected_references: | ||
| for one_part in re.split(r'[\[\],]', reference): | ||
| if re.match(r'\d+[ \-]+\d+', one_part): | ||
| start, end = re.split(r'[ -]+', one_part) | ||
| for k in range(int(start), int(end) + 1): | ||
| array_of_references.append((k)) | ||
| elif one_part != '': | ||
| array_of_references.append(int(one_part)) | ||
| return array_of_references |
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
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.
Лучше не смешивать общую логику с логикой по аннотации, а разделить поведение критерия в целом (оставив возможность параметризации)
0) общая задача подсчет количества ссылок в конкретном разделе