Skip to content

Commit

Permalink
Fix: article lang validation (#713)
Browse files Browse the repository at this point in the history
* Adiciona 'full_tag'

* Adiciona condição para verificar se existe o título

* Adiciona identificação do elemento pai

* Adapta os testes

* Refatora validação

* Adapta e adiciona testes

* Insere verificação para obtenção de resposta

* Refatora validação de idiomas

* Adapta testes

* Corrige 'validate_article_lang'

* Adapta os testes
  • Loading branch information
Rossi-Luciano authored Dec 16, 2024
1 parent 1d56277 commit cc0f396
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 1,102 deletions.
4 changes: 3 additions & 1 deletion packtools/sps/models/article_and_subarticles.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def data(self):
"article_id": None,
"line_number": self.main_line_number,
"subject": self.main_subject,
"parent_name": "article",
})

for sub_article in self.xmltree.xpath(".//sub-article"):
Expand All @@ -65,6 +66,7 @@ def data(self):
"article_type": sub_article.get('article-type'),
"article_id": sub_article.get('id'),
"line_number": sub_article.sourceline,
"subject": subject.text if subject is not None else None
"subject": subject.text if subject is not None else None,
"parent_name": "sub-article",
})
return _data
96 changes: 50 additions & 46 deletions packtools/sps/models/article_titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,53 @@ def article_title_list(self):

@property
def article_title_dict(self):
return {
item['lang']: item['text']
for item in self.article_title_list
}
resp = {}
for item in self.article_title_list:
if item and item.get('lang'):
resp[item['lang']] = item
return resp

@property
def article_title(self):
for node_with_lang in xml_utils.get_nodes_with_lang(
self.xmltree,
".", ".//article-meta//article-title"):
return {
"parent_name": "article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
)
}
if node_with_lang["node"] is not None:
return {
"parent_name": "article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
)
}

@property
def trans_titles(self):
_titles = []
for node_with_lang in xml_utils.get_nodes_with_lang(
self.xmltree,
".//article-meta//trans-title-group", "trans-title"):
_title = {
"parent_name": "article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
)
}
_titles.append(_title)
if node_with_lang["node"] is not None:
_title = {
"parent_name": "article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
)
}
_titles.append(_title)
return _titles

@property
Expand All @@ -82,19 +85,20 @@ def sub_article_titles(self):
self.xmltree,
".//sub-article[@article-type='translation']",
".//front-stub//article-title"):
_title = {
"parent_name": "sub-article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
),
"id": node_with_lang["id"]
}
_titles.append(_title)
if node_with_lang["node"] is not None:
_title = {
"parent_name": "sub-article",
"lang": node_with_lang["lang"],
"text": xml_utils.node_text_without_xref(node_with_lang["node"]),
"plain_text": xml_utils.node_plain_text(node_with_lang["node"]),
"html_text": xml_utils.process_subtags(
node_with_lang["node"],
tags_to_keep=self.tags_to_keep,
tags_to_keep_with_content=self.tags_to_keep_with_content,
tags_to_remove_with_content=self.tags_to_remove_with_content,
tags_to_convert_to_html=self.tags_to_convert_to_html
),
"id": node_with_lang["id"]
}
_titles.append(_title)
return _titles
Loading

0 comments on commit cc0f396

Please sign in to comment.