77 ValidationArticleAndSubArticlesSubjectsException ,
88)
99from 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
1313class 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 )
0 commit comments