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

Feat: footnotes validation #702

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
21 changes: 17 additions & 4 deletions packtools/sps/models/v2/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ def data(self):

class BaseNoteGroups:
def __init__(self, article_or_sub_article_node, fn_parent_tag_name, NoteGroupClass):
self.article_or_sub_article_node = article_or_sub_article_node
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 estava correto antes... A instanciação deveria ocorrer antes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

self.fn_parent_tag_name = fn_parent_tag_name
self.parent = article_or_sub_article_node.tag
self.parent_id = article_or_sub_article_node.get("id")
self.parent_lang = article_or_sub_article_node.get("{http://www.w3.org/XML/1998/namespace}lang")
self.parent_article_type = article_or_sub_article_node.get("article-type")
self.NoteGroupClass = NoteGroupClass
self.article_or_sub_article_node = article_or_sub_article_node \
if self.parent == "sub-article" else article_or_sub_article_node.find("./")
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 só vai pegar o front

In [27]: from lxml import etree

In [28]: root = etree.fromstring(xml)

In [29]: x = root.find('.').find("./")

In [30]: x
Out[30]: <Element front at 0x1125c6340>

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 No método items, faça:

if self.article_or_sub_article_node == "article":
    xpath = f".//front//{self.fn_parent_tag_name} | .//body//{self.fn_parent_tag_name} | .//back//{self.fn_parent_tag_name}"
else:
    xpath = f".//{self.fn_parent_tag_name}"

for fn_parent_node in self.article_or_sub_article_node.xpath(xpath):
    data = self.NoteGroupClass(fn_parent_node).data
    yield put_parent_context(data, self.parent_lang, self.parent_article_type, self.parent, self.parent_id)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


@property
def items(self):
Expand All @@ -45,6 +46,7 @@ def __init__(self, node):
self.label = self.node.findtext("label")
self.text = process_subtags(self.node)
self.bold = self.node.findtext("bold")
self.title = self.node.findtext("title")

@property
def data(self):
Expand All @@ -53,7 +55,8 @@ def data(self):
"fn_type": self.type,
"fn_label": self.label,
"fn_text": self.text,
"fn_bold": self.bold
"fn_bold": self.bold,
"fn_title": self.title
}


Expand Down Expand Up @@ -91,13 +94,23 @@ def corresp(self):
def corresp_label(self):
return process_subtags(self.fn_parent_node.find("corresp/label"))

@property
def corresp_title(self):
return process_subtags(self.fn_parent_node.find("corresp/title"))

@property
def corresp_bold(self):
return process_subtags(self.fn_parent_node.find("corresp/bold"))

@property
def data(self):
return {
**super().data,
"corresp": self.corresp,
"corresp_label": self.corresp_label
}
"corresp_label": self.corresp_label,
"corresp_title": self.corresp_title,
"corresp_bold": self.corresp_bold
}


class AuthorNotes(BaseNoteGroups):
Expand Down