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

Refatoração do processamento XML PMC para melhorar o tratamento de elementos <aff> e ampliar a cobertura de testes #677

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
24 changes: 20 additions & 4 deletions packtools/sps/formats/pmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,29 @@ def xml_pmc_aff(xml_tree):
"""
affs = xml_tree.findall(".//aff")
for aff in affs:
aff_institution = aff.find("./institution[@content-type='original']").text
original_institution = aff.find("./institution[@content-type='original']")
if original_institution is not None:
aff_institution = original_institution.text
else:
aff_with_address = []
aff_with_address.append(aff.find("./institution[@content-type='orgname']").text)

addr_line = aff.find("./addr-line")
if addr_line is not None:
named_contents = addr_line.findall(".//named-content")
Copy link
Member

Choose a reason for hiding this comment

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

No lugar de named_contents = addr_line.findall(".//named-content"), use named_contents = addr_line.xpath(".//named-content | .//state | .//city")

aff_with_address.extend([named_content.text for named_content in named_contents])
Copy link
Member

Choose a reason for hiding this comment

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

@samuelveigarangel algumas versões tem city e state no lugar de named-content. Então, você tem que considerá-los para completar aff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok.


country = aff.find("./country")
Copy link
Member

Choose a reason for hiding this comment

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

@samuelveigarangel pode adicionar o country no xpath

if country is not None:
aff_with_address.append(country.text)
aff_institution = ", ".join(aff_with_address)


for institution in aff.findall(".//institution"):
aff.remove(institution)

aff.remove(aff.find("./addr-line"))

aff.remove(aff.find("./country"))
for element in [aff.find("./addr-line"), aff.find("./country")]:
aff.remove(element)

node_label = aff.find("./label")

Expand Down Expand Up @@ -154,3 +169,4 @@ def xml_pmc_ref(xml_tree):
refs = xml_tree.findall(".//ref")
for ref in refs:
ref.remove(ref.find("./mixed-citation"))

71 changes: 71 additions & 0 deletions tests/sps/formats/test_pmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,77 @@ def test_xml_pmc_ref(self):

self.assertEqual(obtained, expected)

def test_xml_pmc_without_original(self):
self.maxDiff = None
expected = (
'<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" dtd-version="1.1" specific-use="sps-1.9" xml:lang="en">'
'<front>'
'<article-meta>'
'<article-id specific-use="scielo-v3" pub-id-type="publisher-id">ZwzqmpTpbhTmtwR9GfDzP7c</article-id>'
'<article-id specific-use="scielo-v2" pub-id-type="publisher-id">S0080-62342022000100445</article-id>'
'<article-id pub-id-type="doi">10.1590/1980-220X-REEUSP-2021-0569en</article-id>'
'<article-id pub-id-type="other">00445</article-id>'
'<contrib-group>'
'<contrib contrib-type="author">'
'<contrib-id contrib-id-type="orcid">0000-0003-0843-6485</contrib-id>'
'<name>'
'<surname>Boni</surname>'
'<given-names>Fernanda Guarilha</given-names>'
'</name>'
'<xref ref-type="aff" rid="aff1">'
'<sup>1</sup>'
'</xref>'
'</contrib>'
'</contrib-group>'
'<aff id="aff1">'
'Universidade Federal do Rio Grande do Sul, Porto Alegre, RS, Brazil'
'</aff>'
'</article-meta>'
'</front>'
'</article>'

)
xml_tree = ET.fromstring(
'<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" dtd-version="1.1" specific-use="sps-1.9" xml:lang="en">'
'<front>'
'<article-meta>'
'<article-id specific-use="scielo-v3" pub-id-type="publisher-id">ZwzqmpTpbhTmtwR9GfDzP7c</article-id>'
'<article-id specific-use="scielo-v2" pub-id-type="publisher-id">S0080-62342022000100445</article-id>'
'<article-id pub-id-type="doi">10.1590/1980-220X-REEUSP-2021-0569en</article-id>'
'<article-id pub-id-type="other">00445</article-id>'
'<contrib-group>'
'<contrib contrib-type="author">'
'<contrib-id contrib-id-type="orcid">0000-0003-0843-6485</contrib-id>'
'<name>'
'<surname>Boni</surname>'
'<given-names>Fernanda Guarilha</given-names>'
'</name>'
'<xref ref-type="aff" rid="aff1">'
'<sup>1</sup>'
'</xref>'
'</contrib>'
'</contrib-group>'
'<aff id="aff1">'
'<institution content-type="orgname">Universidade Federal do Rio Grande do Sul</institution>'
'<institution content-type="orgdiv1">Escola de Enfermagem</institution>'
'<institution content-type="orgdiv2">Programa de Pós-Graduação em Enfermagem</institution>'
'<addr-line>'
'<named-content content-type="city">Porto Alegre</named-content>'
'<named-content content-type="state">RS</named-content>'
'</addr-line>'
'<country country="BR">Brazil</country>'
'</aff>'
'</article-meta>'
'</front>'
'</article>'
)

xml_pmc_aff(xml_tree)

obtained = ET.tostring(xml_tree, encoding="utf-8").decode("utf-8")

self.assertEqual(obtained, expected)


if __name__ == '__main__':
unittest.main()