Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
70 changes: 41 additions & 29 deletions packtools/sps/formats/pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,47 @@ def get_authors(xml_tree):


def add_first_name(author_reg, author_tag):
author_first_name = author_reg.get("contrib_name", {}).get("given-names")
contrib_name = author_reg.get("contrib_name", {})
# A DTD do PubMed exige FirstName e LastName juntos (nenhum dos dois é
# opcional isoladamente). Quando o XML fonte só tem um dos dois campos
# (autores sem <surname>, por exemplo), duplicamos o valor disponível
# em ambos para gerar um Author válido em vez de descartar o autor.
author_first_name = contrib_name.get("given-names") or contrib_name.get("surname")
if author_first_name:
first = ET.Element("FirstName")
first.text = author_first_name
author_tag.append(first)


def add_last_name(author_reg, author_tag):
author_last_name = author_reg.get("contrib_name", {}).get("surname")
contrib_name = author_reg.get("contrib_name", {})
author_last_name = contrib_name.get("surname") or contrib_name.get("given-names")
if author_last_name:
last = ET.Element("LastName")
last.text = author_last_name
author_tag.append(last)


def add_suffix(author_reg, author_tag):
author_suffix = author_reg.get("contrib_name", {}).get("suffix")
if author_suffix:
suffix = ET.Element("Suffix")
suffix.text = author_suffix
author_tag.append(suffix)


def add_collective_name(author_reg, author_tag):
collab = author_reg.get("collab")
if collab:
collective_name = ET.Element("CollectiveName")
collective_name.text = collab
author_tag.append(collective_name)


def get_affiliations(author_reg, xml_tree):
affiliations = aff.AffiliationExtractor(xml_tree).get_affiliation_dict(subtag=False)
affiliation_list = []
for item in author_reg.get("affs"):
for item in author_reg.get("affs") or []:
affiliation_list.append(
affiliations.get(item.get("id"), {}).get("institution", {})[0].get("original")
)
Expand Down Expand Up @@ -342,33 +364,23 @@ def xml_pubmed_author_list(xml_pubmed, xml_tree):
author_list_tag = ET.Element("AuthorList")
for author_reg in authors:
author_tag = ET.Element("Author")
add_first_name(author_reg, author_tag)

# TODO
# add_middle_name(author_reg, author_tag)
# The Author’s full middle name, or initial if the full name is not available.
# Multiple names are allowed in this tag.
# There is no example of using this value in the files.

add_last_name(author_reg, author_tag)

# TODO
# add_suffix(author_reg, author_tag)
# The Author's suffix, if any, e.g. "Jr", "Sr", "II", "IV". Do not include honorific titles,
# e.g. "M.D.", "Ph.D.".
# There is no example of using this value in the files

# TODO
# add_collective_name(author_reg, author_tag)
# The name of the authoring committee or organization. The CollectiveName tag should be placed within
# an Author tag. Omit extraneous text like, “on behalf of.”
# Please see the following example:
# <AuthorList>
# <Author>
# <CollectiveName>Plastic Surgery Educational Foundation DATA Committee</CollectiveName>
# </Author>
# </AuthorList>
# There is no example of using this value in the files
# A DTD do PubMed exige que Author tenha nome pessoal
# (FirstName/MiddleName/LastName/Suffix) OU CollectiveName,
# nunca os dois ao mesmo tempo.
if author_reg.get("collab"):
add_collective_name(author_reg, author_tag)
else:
add_first_name(author_reg, author_tag)

# TODO
# add_middle_name(author_reg, author_tag)
# The Author’s full middle name, or initial if the full name is not available.
# Multiple names are allowed in this tag.
# There is no example of using this value in the files.

add_last_name(author_reg, author_tag)
add_suffix(author_reg, author_tag)

affiliations = get_affiliations(author_reg, xml_tree)
add_affiliations(affiliations, author_tag)
Expand Down
123 changes: 123 additions & 0 deletions tests/sps/formats/test_pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,129 @@ def test_xml_pubmed_author_list_without_author(self):

self.assertEqual(obtained, expected)

def test_xml_pubmed_author_list_with_suffix(self):
expected = (
'<Article>'
'<AuthorList>'
'<Author>'
'<FirstName>Rogerio</FirstName>'
'<LastName>Meneghini</LastName>'
'<Suffix>Junior</Suffix>'
'<Affiliation>Some University</Affiliation>'
'</Author>'
'</AuthorList>'
'</Article>'
)
xml_pubmed = ET.fromstring(
'<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>'
'<contrib-group>'
'<contrib contrib-type="author">'
'<name>'
'<surname>Meneghini</surname>'
'<given-names>Rogerio</given-names>'
'<suffix>Junior</suffix>'
'</name>'
'<xref ref-type="aff" rid="aff1">1</xref>'
'</contrib>'
'</contrib-group>'
'<aff id="aff1">'
'<institution content-type="original">Some University</institution>'
'</aff>'
'</article-meta>'
'</front>'
'</article>'
)

xml_pubmed_author_list(xml_pubmed, xml_tree)

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

self.assertEqual(obtained, expected)

def test_xml_pubmed_author_list_without_surname_duplicates_given_names(self):
# A DTD do PubMed exige FirstName e LastName juntos; quando o XML
# fonte só tem <given-names> (sem <surname>), duplicamos o valor
# em ambos os campos em vez de gerar um Author inválido.
expected = (
'<Article>'
'<AuthorList>'
'<Author>'
'<FirstName>Viviana Alder</FirstName>'
'<LastName>Viviana Alder</LastName>'
'</Author>'
'</AuthorList>'
'</Article>'
)
xml_pubmed = ET.fromstring(
'<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>'
'<contrib-group>'
'<contrib contrib-type="author">'
'<name>'
'<given-names>Viviana Alder</given-names>'
'</name>'
'</contrib>'
'</contrib-group>'
'</article-meta>'
'</front>'
'</article>'
)

xml_pubmed_author_list(xml_pubmed, xml_tree)

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

self.assertEqual(obtained, expected)

def test_xml_pubmed_author_list_with_collective_name(self):
expected = (
'<Article>'
'<AuthorList>'
'<Author>'
'<CollectiveName>The SciELO Group</CollectiveName>'
'</Author>'
'</AuthorList>'
'</Article>'
)
xml_pubmed = ET.fromstring(
'<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>'
'<contrib-group>'
'<contrib contrib-type="author" id="collab">'
'<collab>The SciELO Group</collab>'
'<xref ref-type="author-notes" rid="fn1">1</xref>'
'</contrib>'
'</contrib-group>'
'</article-meta>'
'</front>'
'</article>'
)

xml_pubmed_author_list(xml_pubmed, xml_tree)

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

self.assertEqual(obtained, expected)

def test_xml_pubmed_publication_type(self):
# TODO
# Originalmente, espera-se que o valor da tag <PublicationType> seja Journal Article
Expand Down