Skip to content

Commit a055d3f

Browse files
Adicionar argumentos advice_text e advice_params em build_response (#1080)
* Initial plan * Replace format_response with build_response in article_abstract.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in article_and_subarticles.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in article_license.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in article_xref.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in fig.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in journal_meta.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in metadata_langs.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Replace format_response with build_response in tablewrap.py Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> * Fix advice_text and advice_params parameterization in validation modules Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
1 parent cd58b79 commit a055d3f

9 files changed

Lines changed: 303 additions & 134 deletions

File tree

packtools/sps/validation/article_abstract.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from packtools.sps.models.v2.abstract import XMLAbstracts
2-
from packtools.sps.validation.utils import format_response, build_response
2+
from packtools.sps.validation.utils import build_response
33
import gettext
44

55
# Configuração de internacionalização
@@ -517,32 +517,42 @@ def validate_exists(self):
517517
error_level = self.params["default_error_level"]
518518
is_valid = True
519519
advice = None
520+
advice_text = None
521+
advice_params = {}
520522

521523
if self.article_type in self.params["article_type_requires"]:
522524
expected = f"Abstract is required"
523525
is_valid = bool(data)
524526
error_level = self.params["article_type_requires_abstract_error_level"]
525527
advice = f"Mark abstract which is required for {self.article_type}"
528+
advice_text = "Mark abstract which is required for {article_type}"
529+
advice_params = {"article_type": self.article_type}
526530
elif self.article_type in self.params["article_type_unexpects"]:
527531
expected = f"Abstract is unexpected"
528532
is_valid = not bool(data)
529533
error_level = self.params["article_type_unexpects_abstract_error_level"]
530534
advice = f"Abstract is not expected for {self.article_type}"
535+
advice_text = "Abstract is not expected for {article_type}"
536+
advice_params = {"article_type": self.article_type}
531537
elif self.article_type in self.params["article_type_neutral"]:
532538
is_valid = True
533539
expected = f"Abstract is optional"
534540
advice = None
541+
advice_text = None
542+
advice_params = {}
535543
else:
536544
raise ValueError(
537545
f"Unable to identify if abstract is required or unexpected or neutral for article-type '{self.article_type}'"
538546
)
539547

540-
return format_response(
548+
return build_response(
541549
title="abstract",
542-
parent="article",
543-
parent_id=None,
544-
parent_article_type=self.article_type,
545-
parent_lang=self.lang,
550+
parent={
551+
"parent": "article",
552+
"parent_id": None,
553+
"parent_article_type": self.article_type,
554+
"parent_lang": self.lang,
555+
},
546556
item="abstract",
547557
sub_item=None,
548558
validation_type="exist",
@@ -552,6 +562,8 @@ def validate_exists(self):
552562
advice=advice,
553563
data=data,
554564
error_level=error_level,
565+
advice_text=advice_text,
566+
advice_params=advice_params,
555567
)
556568

557569
def validate(self):

packtools/sps/validation/article_and_subarticles.py

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ValidationArticleAndSubArticlesSubjectsException,
88
)
99
from packtools.sps.validation.similarity_utils import most_similar, similarity
10-
from packtools.sps.validation.utils import build_response, format_response
10+
from packtools.sps.validation.utils import build_response
1111

1212

1313
class ArticleLangValidation:
@@ -93,17 +93,23 @@ def validate_language(self):
9393
if article_lang:
9494
xml = f'<{parent}{parent_id} xml:lang="{article_lang}">'
9595
advice = f'Replace {article_lang} in {xml} with one of {language_codes_list}'
96+
advice_text = 'Replace {lang} in {xml} with one of {lang_list}'
97+
advice_params = {"lang": article_lang, "xml": xml, "lang_list": str(language_codes_list)}
9698
else:
9799
xml = f'<{parent}{parent_id}>'
98100
xml2 = f'<{parent}{parent_id} xml:lang="VALUE">'
99101

100102
advice = f'Add xml:lang="VALUE" in {xml}: {xml2} and replace VALUE with one of {language_codes_list}'
101-
yield format_response(
103+
advice_text = 'Add xml:lang="VALUE" in {xml}: {xml2} and replace VALUE with one of {lang_list}'
104+
advice_params = {"xml": xml, "xml2": xml2, "lang_list": str(language_codes_list)}
105+
yield build_response(
102106
title=f"{name} language",
103-
parent=parent,
104-
parent_id=article_id,
105-
parent_article_type=article_type,
106-
parent_lang=article_lang,
107+
parent={
108+
"parent": parent,
109+
"parent_id": article_id,
110+
"parent_article_type": article_type,
111+
"parent_lang": article_lang,
112+
},
107113
item=parent,
108114
sub_item="@xml:lang",
109115
validation_type="value in list",
@@ -113,6 +119,8 @@ def validate_language(self):
113119
advice=advice,
114120
data=article,
115121
error_level=self.params["language_error_level"],
122+
advice_text=advice_text,
123+
advice_params=advice_params,
116124
)
117125

118126

@@ -163,12 +171,16 @@ def validate_article_type(self):
163171
name = article_id or parent
164172
xml = f'<{parent} article-type=""/>'
165173
advice = None if valid else f'Complete {name} article-type {xml} with valid value {article_type_list}'
166-
yield format_response(
174+
advice_text = None if valid else 'Complete {name} article-type {xml} with valid value {type_list}'
175+
advice_params = {} if valid else {"name": name, "xml": xml, "type_list": str(article_type_list)}
176+
yield build_response(
167177
title=f"{name} article-type",
168-
parent=parent,
169-
parent_id=article_id,
170-
parent_article_type=article_type,
171-
parent_lang=article_type,
178+
parent={
179+
"parent": parent,
180+
"parent_id": article_id,
181+
"parent_article_type": article_type,
182+
"parent_lang": article_type,
183+
},
172184
item=parent,
173185
sub_item="article-type",
174186
validation_type="value in list",
@@ -178,6 +190,8 @@ def validate_article_type(self):
178190
advice=advice,
179191
data=article,
180192
error_level=self.params["article_type_error_level"],
193+
advice_text=advice_text,
194+
advice_params=advice_params,
181195
)
182196

183197
def validate_article_type_vs_subject_similarity(self):
@@ -230,16 +244,28 @@ def validate_article_type_vs_subject_similarity(self):
230244
title = f"article type and table of contents section"
231245
choices = " | ".join(most_similar_article_type)
232246
advice = None
247+
advice_text = None
248+
advice_params = {}
233249
if not valid:
234250
advice = (
235251
f"Check {xml_article_type} and {xml_subject}. Other values for article-type seems to be more suitable: {choices}. "
236252
)
237-
yield format_response(
253+
advice_text = (
254+
"Check {xml_article_type} and {xml_subject}. Other values for article-type seems to be more suitable: {choices}. "
255+
)
256+
advice_params = {
257+
"xml_article_type": xml_article_type,
258+
"xml_subject": xml_subject,
259+
"choices": choices
260+
}
261+
yield build_response(
238262
title=title,
239-
parent="article",
240-
parent_article_type=self.articles.main_article_type,
241-
parent_lang=self.articles.main_lang,
242-
parent_id=None,
263+
parent={
264+
"parent": "article",
265+
"parent_id": None,
266+
"parent_article_type": self.articles.main_article_type,
267+
"parent_lang": self.articles.main_lang,
268+
},
243269
item="article",
244270
sub_item="@article-type",
245271
validation_type="similarity",
@@ -249,6 +275,8 @@ def validate_article_type_vs_subject_similarity(self):
249275
advice=advice,
250276
data=data,
251277
error_level=self.params["article_type_and_subject_expected_similarity_error_level"],
278+
advice_text=advice_text,
279+
advice_params=advice_params,
252280
)
253281

254282

@@ -339,12 +367,18 @@ def validate(self):
339367
expected_jats_versions = versions.get(sps_version) or []
340368

341369
advice = None
370+
advice_text = None
371+
advice_params = {}
342372
if not versions:
343373
advice = f'Complete SPS version <article specific-use=""/> with valid value: {list(versions.keys())}',
374+
advice_text = 'Complete SPS version <article specific-use=""/> with valid value: {versions}'
375+
advice_params = {"versions": str(list(versions.keys()))}
344376

345377
elif jats_version not in expected_jats_versions:
346378
xml = f'<article specific-use="" dtd-version=""/>'
347379
advice = f'Complete SPS (specific-use="") and JATS (dtd-version="") versions in {xml} with compatible values: {versions}'
380+
advice_text = 'Complete SPS (specific-use="") and JATS (dtd-version="") versions in {xml} with compatible values: {versions}'
381+
advice_params = {"xml": xml, "versions": str(versions)}
348382

349383
expected = expected_jats_versions or versions
350384
got = {
@@ -356,12 +390,14 @@ def validate(self):
356390
"dtd-version": jats_version,
357391
"expected values": expected,
358392
}
359-
yield format_response(
393+
yield build_response(
360394
title='SPS and JATS versions',
361-
parent="article",
362-
parent_id=None,
363-
parent_article_type=self.article_and_sub_articles.main_article_type,
364-
parent_lang=self.article_and_sub_articles.main_lang,
395+
parent={
396+
"parent": "article",
397+
"parent_id": None,
398+
"parent_article_type": self.article_and_sub_articles.main_article_type,
399+
"parent_lang": self.article_and_sub_articles.main_lang,
400+
},
365401
item="specific-use and dtd-version",
366402
sub_item=None,
367403
validation_type="match",
@@ -371,4 +407,6 @@ def validate(self):
371407
advice=advice,
372408
data=data,
373409
error_level=self.params["jats_and_dtd_version_error_level"],
410+
advice_text=advice_text,
411+
advice_params=advice_params,
374412
)

packtools/sps/validation/article_license.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ValidationLicenseException,
55
ValidationLicenseCodeException
66
)
7-
from packtools.sps.validation.utils import format_response
7+
from packtools.sps.validation.utils import build_response
88

99

1010
class ArticleLicenseValidation:
@@ -123,12 +123,14 @@ def validate_license(self, expected_value, error_level="ERROR"):
123123
is_valid = expected_license_p == obtained_license_p
124124
expected_value_msg = expected_value.get(
125125
lang) if is_valid else 'License data that matches the language {}'.format(lang)
126-
yield format_response(
126+
yield build_response(
127127
title='Article license validation',
128-
parent=data.get("parent"),
129-
parent_id=data.get("parent_id"),
130-
parent_article_type=data.get("parent_article_type"),
131-
parent_lang=data.get("parent_lang"),
128+
parent={
129+
"parent": data.get("parent"),
130+
"parent_id": data.get("parent_id"),
131+
"parent_article_type": data.get("parent_article_type"),
132+
"parent_lang": data.get("parent_lang"),
133+
},
132134
item="permissions",
133135
sub_item="license",
134136
validation_type="value",
@@ -141,6 +143,11 @@ def validate_license(self, expected_value, error_level="ERROR"):
141143
f'<license-p>{expected_license_p["license_p"]}</license-p></license>',
142144
data=obtained_license_p,
143145
error_level=error_level,
146+
advice_text=f'Mark license information with '
147+
f'<license license-type="open-access" xlink:href={{link}} '
148+
f'xml:lang={{lang}}>'
149+
f'<license-p>{{license_p}}</license-p></license>',
150+
advice_params=expected_license_p,
144151
)
145152

146153
def validate_license_code(self, expected_code, error_level="ERROR"):
@@ -202,12 +209,14 @@ def validate_license_code(self, expected_code, error_level="ERROR"):
202209
obtained_link = licenses.get('link')
203210
obtained_code = obtained_link.split('/')[4] if obtained_link else None
204211
is_valid = expected_code == obtained_code
205-
yield format_response(
212+
yield build_response(
206213
title='Article license code validation',
207-
parent=licenses.get("parent"),
208-
parent_id=licenses.get("parent_id"),
209-
parent_article_type=licenses.get("parent_article_type"),
210-
parent_lang=licenses.get("parent_lang"),
214+
parent={
215+
"parent": licenses.get("parent"),
216+
"parent_id": licenses.get("parent_id"),
217+
"parent_article_type": licenses.get("parent_article_type"),
218+
"parent_lang": licenses.get("parent_lang"),
219+
},
211220
item="permissions",
212221
sub_item="license",
213222
validation_type="value",
@@ -217,6 +226,8 @@ def validate_license_code(self, expected_code, error_level="ERROR"):
217226
advice=f'add <permissions><license xlink:href="http://creativecommons.org/licenses/VALUE/4.0/"> and replace VALUE with {expected_code}',
218227
data=licenses,
219228
error_level=error_level,
229+
advice_text='add <permissions><license xlink:href="http://creativecommons.org/licenses/VALUE/4.0/"> and replace VALUE with {code}',
230+
advice_params={"code": expected_code},
220231
)
221232

222233

packtools/sps/validation/article_xref.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from packtools.sps.models.v2.article_xref import XMLCrossReference
2-
from packtools.sps.validation.utils import format_response, build_response
2+
from packtools.sps.validation.utils import build_response
33

44

55
class ArticleXrefValidation:
@@ -70,14 +70,16 @@ def validate_xref_rid_has_corresponding_element_id(self):
7070
f'Found {xref.get("xml")}, but not found the corresponding {xref.get("elem_xml")}'
7171
)
7272

73-
yield format_response(
73+
yield build_response(
7474
title=f'<xref> is linked to {element_name}',
75-
parent="article",
76-
parent_id=None,
77-
parent_article_type=self.xml_tree.get("article-type"),
78-
parent_lang=self.xml_tree.get(
79-
"{http://www.w3.org/XML/1998/namespace}lang"
80-
),
75+
parent={
76+
"parent": "article",
77+
"parent_id": None,
78+
"parent_article_type": self.xml_tree.get("article-type"),
79+
"parent_lang": self.xml_tree.get(
80+
"{http://www.w3.org/XML/1998/namespace}lang"
81+
),
82+
},
8183
item="xref",
8284
sub_item="@rid",
8385
validation_type="match",
@@ -87,6 +89,8 @@ def validate_xref_rid_has_corresponding_element_id(self):
8789
advice=advice,
8890
data={"xref": xref, "element": element_data, "missing_xrefs": self.missing_xrefs, "missing_elems": self.missing_elems},
8991
error_level=self.params["xref_rid_error_level"],
92+
advice_text='Found {xml}, but not found the corresponding {elem_xml}',
93+
advice_params={"xml": xref.get("xml"), "elem_xml": xref.get("elem_xml")},
9094
)
9195

9296
def validate_element_id_has_corresponding_xref_rid(self):
@@ -119,17 +123,35 @@ def validate_element_id_has_corresponding_xref_rid(self):
119123
f'Found {tag_and_attribs}, but no corresponding {xref_xml} was found. '
120124
f'Mark {label}, mention to {tag_and_attribs}, with {xref_xml}'
121125
)
126+
advice_text = (
127+
'Found {tag_and_attribs}, but no corresponding {xref_xml} was found. '
128+
'Mark {label}, mention to {tag_and_attribs}, with {xref_xml}'
129+
)
130+
advice_params = {
131+
"tag_and_attribs": tag_and_attribs,
132+
"xref_xml": xref_xml,
133+
"label": label
134+
}
122135
else:
123136
advice = (
124137
f'Found {tag_and_attribs}, but no corresponding {xref_xml} was found. '
125138
)
139+
advice_text = (
140+
'Found {tag_and_attribs}, but no corresponding {xref_xml} was found. '
141+
)
142+
advice_params = {
143+
"tag_and_attribs": tag_and_attribs,
144+
"xref_xml": xref_xml
145+
}
126146

127-
yield format_response(
147+
yield build_response(
128148
title=f'{tag_and_attribs} is linked to <xref>',
129-
parent=elem_data.get("parent"),
130-
parent_id=elem_data.get("parent_id"),
131-
parent_article_type=elem_data.get("parent_article_type"),
132-
parent_lang=elem_data.get("parent_lang"),
149+
parent={
150+
"parent": elem_data.get("parent"),
151+
"parent_id": elem_data.get("parent_id"),
152+
"parent_article_type": elem_data.get("parent_article_type"),
153+
"parent_lang": elem_data.get("parent_lang"),
154+
},
133155
item=elem_data.get("tag"),
134156
sub_item="@id",
135157
validation_type="match",
@@ -139,6 +161,8 @@ def validate_element_id_has_corresponding_xref_rid(self):
139161
advice=advice,
140162
data={"element": elem_data, "xref": xrefs, "missing_xrefs": self.missing_xrefs, "missing_elems": self.missing_elems},
141163
error_level=error_level,
164+
advice_text=advice_text,
165+
advice_params=advice_params,
142166
)
143167

144168
def validate_attrib_name_and_value_has_corresponding_xref(self):

0 commit comments

Comments
 (0)