diff --git a/packtools/sps/formats/pdf/pipeline/xml.py b/packtools/sps/formats/pdf/pipeline/xml.py index d0db5d2e7..9a6af1a48 100644 --- a/packtools/sps/formats/pdf/pipeline/xml.py +++ b/packtools/sps/formats/pdf/pipeline/xml.py @@ -109,11 +109,14 @@ def extract_contrib_data(xml_tree): affiliations = [] corresponding_author = '' - contrib_group = xml_tree.find('.//contrib-group') + article_meta = xml_tree.find('./front/article-meta') + metadata_scope = article_meta if article_meta is not None else xml_tree + contrib_group = metadata_scope.find('.//contrib-group') if contrib_group is not None: aff_mapping = {} + affs = metadata_scope.findall('.//aff') - for aff in xml_tree.findall('.//aff'): + for aff in affs: aff_id = aff.get('id') label = aff.find('label').text if aff.find('label') is not None else '' institution = aff.find('institution[@content-type="original"]') @@ -140,12 +143,12 @@ def extract_contrib_data(xml_tree): full_name += label full_name += corresp_mark authors_names.append(full_name) - - for aff in xml_tree.findall('.//aff'): + + for aff in affs: label = aff.find('label').text if aff.find('label') is not None else '' institution = aff.find('institution[@content-type="original"]') institution_name = institution.text if institution is not None else '' - + if institution_name: aff_info = f"{label}[^] {institution_name}" affiliations.append(aff_info) diff --git a/tests/sps/formats/pdf/pipeline/test_xml.py b/tests/sps/formats/pdf/pipeline/test_xml.py index 774630aae..6939b05f2 100644 --- a/tests/sps/formats/pdf/pipeline/test_xml.py +++ b/tests/sps/formats/pdf/pipeline/test_xml.py @@ -644,6 +644,121 @@ def test_extract_contrib_data_missing_label(self): self.assertEqual(result['authors_names'], ['John Smith[^]']) self.assertEqual(result['affiliations'], ['[^] University X']) + def test_subarticle_affiliation_is_not_printed(self): + # Regression: translated affiliations in a sub-article must not be + # included in the affiliation list of the main article. + xml = etree.fromstring(""" +
+ + + + + + Smith + John + + + + + + + University A + + + + + + + + + Smith + John + + + + + + + Universidade A + + + +
+ """) + result = xml_pipe.extract_contrib_data(xml) + self.assertEqual(result['affiliations'], ['I[^] University A']) + + def test_main_article_affiliations_are_kept_regardless_of_id_pattern(self): + xml = etree.fromstring(""" +
+ + + + + + Smith + John + + + + + + Doe + Jane + + + + + + + University A + + + + University B + + + +
+ """) + result = xml_pipe.extract_contrib_data(xml) + self.assertEqual( + result['affiliations'], + ['1[^] University A', '2[^] University B'], + ) + + def test_main_article_affiliation_without_xref_is_printed(self): + xml = etree.fromstring(""" +
+ + + + + + Smith + John + + + + + + University A + + + + + + + + Universidade A + + + +
+ """) + result = xml_pipe.extract_contrib_data(xml) + self.assertEqual(result['affiliations'], ['1[^] University A']) + class TestExtractDOI(unittest.TestCase):