From a43e891112b477f73d13ba1da0a76d5f37b4029a Mon Sep 17 00:00:00 2001 From: Rossi-Luciano Date: Fri, 3 Jul 2026 22:32:11 -0300 Subject: [PATCH] feat(pubmed): adicionar Object[@Type=grant] (financiamento) em ObjectList MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Estende xml_pubmed_object_list, que hoje só cobre Object[@Type=keyword], usando funding_group.FundingGroup.award_groups (já expõe funding-source e award-id por award-group). Para cada award-group: funding-source(s) viram Param[@Name="grantor"] (concatenados com "; " quando há mais de um, ex. "FAPESP; CAPES", já que o Object do PubMed só aceita um grantor por vez); cada award-id vira um Object[@Type=grant] próprio com Param[@Name="id"]. acronym e country não têm fonte nos dados SciELO, ficam de fora. De quebra, corrige um bug latente: xml_pubmed_object_list criava sempre que havia kwd_list, mesmo sem nenhuma keyword em inglês — podendo gerar vazio. Agora só anexa ObjectList se houver pelo menos um Object (keyword ou grant). Refs #1226, #1239 --- packtools/sps/formats/pubmed.py | 57 ++++++++++++--- tests/sps/formats/test_pubmed.py | 120 +++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 11 deletions(-) diff --git a/packtools/sps/formats/pubmed.py b/packtools/sps/formats/pubmed.py index f99b2651d..6db59b70e 100644 --- a/packtools/sps/formats/pubmed.py +++ b/packtools/sps/formats/pubmed.py @@ -11,6 +11,7 @@ article_titles, dates, front_articlemeta_issue, + funding_group, journal_meta, kwd_group, ) @@ -526,6 +527,45 @@ def get_keywords(xml_tree): return kwd_group.KwdGroup(xml_tree).extract_kwd_data_with_lang_text(subtag=False) +def get_award_groups(xml_tree): + return funding_group.FundingGroup(xml_tree).award_groups + + +def add_grant_objects(obj_list, xml_tree): + """ + + RO1DK561234 + National Institutes of Health + + """ + for award_group in get_award_groups(xml_tree): + funding_sources = [ + source for source in award_group.get("funding-source") or [] if source + ] + award_ids = [ + award_id for award_id in award_group.get("award-id") or [] if award_id + ] + grantor = "; ".join(funding_sources) or None + + # acronym e country não têm fonte nos dados SciELO, ficam de fora. + for award_id in award_ids or [None]: + if not award_id and not grantor: + continue + obj = ET.Element("Object") + obj.set("Type", "grant") + if award_id: + param = ET.Element("Param") + param.set("Name", "id") + param.text = award_id + obj.append(param) + if grantor: + param = ET.Element("Param") + param.set("Name", "grantor") + param.text = grantor + obj.append(param) + obj_list.append(obj) + + def xml_pubmed_object_list(xml_pubmed, xml_tree): """ @@ -553,11 +593,9 @@ def xml_pubmed_object_list(xml_pubmed, xml_tree): """ - kwd_list = get_keywords(xml_tree) - if not kwd_list: - return obj_list = ET.Element("ObjectList") - for kwd in kwd_list: + + for kwd in get_keywords(xml_tree): if kwd.get("lang") == "en": obj = ET.Element("Object") obj.set("Type", "keyword") @@ -566,14 +604,11 @@ def xml_pubmed_object_list(xml_pubmed, xml_tree): param.text = kwd.get("text") obj.append(param) obj_list.append(obj) - xml_pubmed.append(obj_list) - # TODO - # The Object tag includes the Type attribute, which may include only one of the following values - # for each identifier. - # Grant, Comment, Dataset, Erratum, Originalreport, Partialretraction, Patientsummary, - # Reprint, Republished, Retraction, Update. - # There is no example of using this value in the files. + add_grant_objects(obj_list, xml_tree) + + if len(obj_list): + xml_pubmed.append(obj_list) def xml_pubmed_title_reference_list(xml_pubmed, xml_tree): diff --git a/tests/sps/formats/test_pubmed.py b/tests/sps/formats/test_pubmed.py index a8afad598..20e0ec72c 100644 --- a/tests/sps/formats/test_pubmed.py +++ b/tests/sps/formats/test_pubmed.py @@ -1288,6 +1288,126 @@ def test_xml_pubmed_object_list_keyword(self): self.assertEqual(obtained, expected) + def test_xml_pubmed_object_list_grant(self): + expected = ( + '
' + '' + '' + '04/08142-0' + 'Fundação de Amparo à Pesquisa do Estado de São Paulo (FAPESP)' + '' + '' + '05/07183-0' + 'FAPESP; CAPES' + '' + '' + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + '' + 'Fundação de Amparo à Pesquisa do Estado de São Paulo (FAPESP)' + '04/08142-0' + '' + '' + 'FAPESP' + 'CAPES' + '05/07183-0' + '' + '' + '' + '' + '
' + ) + + xml_pubmed_object_list(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + + def test_xml_pubmed_object_list_keyword_and_grant(self): + expected = ( + '
' + '' + '' + 'Arteries Dissection' + '' + '' + '04/08142-0' + 'FAPESP' + '' + '' + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + 'Dissecção das Artérias' + '' + '' + '' + 'FAPESP' + '04/08142-0' + '' + '' + '' + '' + '' + '' + '' + 'Arteries Dissection' + '' + '' + '' + '
' + ) + + xml_pubmed_object_list(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + + def test_xml_pubmed_object_list_without_keyword_or_grant(self): + expected = ( + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + '' + '
' + ) + + xml_pubmed_object_list(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + def test_xml_pubmed_title_reference_list(self): expected = ( '
'