Skip to content
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

Refactor: table wrap validation #765

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a4ee1c0
Adiciona níveis de erro para 'table-wrap'
Rossi-Luciano Nov 26, 2024
5764ab3
Remove código obsoleto
Rossi-Luciano Nov 26, 2024
e892f5d
Adiciona classe
Rossi-Luciano Nov 26, 2024
1574f8b
Adiciona construtor com tratamento de exceções para cada parâmetro
Rossi-Luciano Nov 26, 2024
f67a1c5
Adiciona função de validação
Rossi-Luciano Nov 26, 2024
29e803d
Verifica se não há tabelas no artigo
Rossi-Luciano Nov 26, 2024
dda73ac
Valida cada tabela encontrada
Rossi-Luciano Nov 26, 2024
0752a97
Remove código obsoleto
Rossi-Luciano Nov 26, 2024
975c88d
Adiciona classe para validação de cada tabela individualmente
Rossi-Luciano Nov 26, 2024
607e943
Adiciona construtor com tratamento de exceção para 'data'
Rossi-Luciano Nov 26, 2024
efcf989
Adiciona função para validar os atributos individualmente
Rossi-Luciano Nov 26, 2024
c828c0c
Adiciona validação de atributos
Rossi-Luciano Nov 26, 2024
65a62ec
Atualiza importações
Rossi-Luciano Nov 26, 2024
c474cb4
Adiciona teste para ausência de tabela
Rossi-Luciano Nov 26, 2024
471de20
Adiciona teste para validação de 'id'
Rossi-Luciano Nov 26, 2024
fbe39d0
Adiciona teste para validação de 'label'
Rossi-Luciano Nov 26, 2024
7fc2e55
Adiciona teste para a validação de 'caption'
Rossi-Luciano Nov 26, 2024
da7488b
Corrige chave do dicionário
Rossi-Luciano Nov 27, 2024
e259282
Adiciona 'title'
Rossi-Luciano Nov 27, 2024
b0c7854
Adapta teste
Rossi-Luciano Nov 27, 2024
6fa5770
Corrige para o uso de lxml
Rossi-Luciano Dec 7, 2024
6eef98e
Adiciona 'table' e 'graphic'
Rossi-Luciano Dec 7, 2024
b51679c
Complementa os dados
Rossi-Luciano Dec 7, 2024
15b8329
Simplifica os exemplos de teste e adiciona 'table' e 'graphic'
Rossi-Luciano Dec 7, 2024
bbff647
Individualiza as chamadas para as validações
Rossi-Luciano Dec 7, 2024
6a8ae19
Individualiza as validações
Rossi-Luciano Dec 7, 2024
4758356
Complementa 'tablewrap.json'
Rossi-Luciano Dec 7, 2024
eb0c5bc
Adapta e adiciona testes
Rossi-Luciano Dec 7, 2024
e11048c
Aplica formatação (black)
Rossi-Luciano Dec 7, 2024
0d4890b
Atualiza importações
Rossi-Luciano Dec 22, 2024
4fa154a
Remove funções obsoletas
Rossi-Luciano Dec 22, 2024
473c894
Adiciona 'table_wrap_foot'
Rossi-Luciano Dec 22, 2024
1189d3d
Corrige retorno da função
Rossi-Luciano Dec 22, 2024
89ce1a1
Atualiza 'data'
Rossi-Luciano Dec 22, 2024
9e0ed08
Adiciona exemplo mais real
Rossi-Luciano Dec 22, 2024
27bc861
Corrige nome dos atributos
Rossi-Luciano Dec 22, 2024
0965c5e
Adequa nome de atributo
Rossi-Luciano Dec 22, 2024
7c1c09b
Adequa nome de atributo
Rossi-Luciano Dec 22, 2024
d7203b4
Adequa nome de atributo
Rossi-Luciano Dec 22, 2024
58cad6d
Adiciona exemplo mais real
Rossi-Luciano Dec 22, 2024
4849aff
Adequa nome de atributo
Rossi-Luciano Dec 22, 2024
4cefeb8
Modifica para lista de 'footnotes'
Rossi-Luciano Dec 22, 2024
6f71ae1
Modifica validação de 'alternatives'
Rossi-Luciano Dec 22, 2024
1308c13
Adequa testes de validação
Rossi-Luciano Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 48 additions & 30 deletions packtools/sps/models/tablewrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import xml.etree.ElementTree as ET
from packtools.sps.utils.xml_utils import put_parent_context, node_plain_text, tostring
import lxml.etree as ET

from packtools.sps.utils.xml_utils import put_parent_context, node_plain_text, tostring, process_subtags


class TableWrap:
Expand All @@ -13,7 +14,12 @@ def __str__(self):
return tostring(self.element, xml_declaration=False)

def xml(self, pretty_print=True):
return tostring(node=self.element, doctype=None, pretty_print=pretty_print, xml_declaration=False)
return tostring(
node=self.element,
doctype=None,
pretty_print=pretty_print,
xml_declaration=False,
)

@property
def table_wrap_id(self):
Expand All @@ -27,38 +33,48 @@ def label(self):
def caption(self):
caption_element = self.element.find(".//caption")
if caption_element is not None:
return ET.tostring(caption_element, encoding='unicode', method='text').strip()
return ET.tostring(
caption_element, encoding="unicode", method="text"
).strip()
return ""

@property
def footnote(self):
footnote_element = self.element.find('.//table-wrap-foot')
if footnote_element is not None:
return node_plain_text(footnote_element)
return ""
def table_wrap_foot(self):
table_wrap_foot_elem = self.element.find(".//table-wrap-foot")
if table_wrap_foot_elem is None:
return []

fns = []
for fn_elem in table_wrap_foot_elem.findall(".//fn"):
fns.append(
{
"text": node_plain_text(fn_elem),
"id": fn_elem.get("id"),
"label": fn_elem.findtext(".//label"),
}
)
return fns

@property
def footnote_id(self):
footnote_element = self.element.find('.//table-wrap-foot')
if footnote_element is not None:
fn_element = footnote_element.find('.//fn')
if fn_element is not None:
return fn_element.get("id")
return None
def alternative_elements(self):
alternative_elements = self.element.find(".//alternatives")
if alternative_elements is not None:
return [child.tag for child in alternative_elements]
return []

@property
def footnote_label(self):
footnote_element = self.element.find('.//table-wrap-foot')
if footnote_element is not None:
return footnote_element.findtext('.//fn//label')
def table(self):
table = self.element.find(".//table")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano table e graphic estão retornando table e graphic de quaisquer níveis. Deveria distinguir entre table logo abaixo de table-wrap de table dentro de alternatives. O mesmo vale para graphic

if table is not None:
return tostring(table, xml_declaration=False)
return None

@property
def alternative_elements(self):
alternative_elements = self.element.find('.//alternatives')
if alternative_elements is not None:
return [child.tag for child in alternative_elements]
return []
def graphic(self):
graphic = self.element.find(".//graphic")
if graphic is not None:
return graphic.get("{http://www.w3.org/1999/xlink}href")
return None

@property
def data(self):
Expand All @@ -67,10 +83,10 @@ def data(self):
"table_wrap_id": self.table_wrap_id,
"label": self.label,
"caption": self.caption,
"footnote": self.footnote,
"footnote_id": self.footnote_id,
"footnote_label": self.footnote_label,
"alternative_elements": self.alternative_elements
"footnotes": self.table_wrap_foot,
"alternative_elements": self.alternative_elements,
"table": self.table,
"graphic": self.graphic,
}


Expand Down Expand Up @@ -98,7 +114,9 @@ def table_wrappers(self):

for table in self.node.xpath(path):
data = TableWrap(table).data
yield put_parent_context(data, self.lang, self.article_type, self.parent, self.parent_id)
yield put_parent_context(
data, self.lang, self.article_type, self.parent, self.parent_id
)


class ArticleTableWrappers:
Expand Down
Loading