From 53a1acd2ba49a0a6a88b7a568559572c1221a960 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Mon, 28 Oct 2024 20:07:29 -0400 Subject: [PATCH] extract all affilations for each author --- pubmed_parser/medline_parser.py | 13 ++++++++----- tests/test_medline_parser.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pubmed_parser/medline_parser.py b/pubmed_parser/medline_parser.py index c465dd1..be74eb8 100644 --- a/pubmed_parser/medline_parser.py +++ b/pubmed_parser/medline_parser.py @@ -424,11 +424,14 @@ def parse_author_affiliation(medline): else: identifier = "" if author.find("AffiliationInfo/Affiliation") is not None: - affiliation = author.find("AffiliationInfo/Affiliation").text or "" - affiliation = affiliation.replace( - "For a full list of the authors' affiliations please see the Acknowledgements section.", - "", - ) + affiliation = list(chain(*([c.text] for c in author.findall("AffiliationInfo/Affiliation")))) or [] + affiliation = [ + c.replace( + "For a full list of the authors' affiliations please see the Acknowledgements section.", + "", + ) for c in affiliation + ] + affiliation = "|".join(affiliation) else: affiliation = "" authors.append( diff --git a/tests/test_medline_parser.py b/tests/test_medline_parser.py index 90779a7..696836d 100644 --- a/tests/test_medline_parser.py +++ b/tests/test_medline_parser.py @@ -34,7 +34,7 @@ def test_affiliations(): """This is a test for the affiliations field.""" affiliations_36400559 = 'Department of Neurological Surgery, The Ohio State Wexner Medical Center, 410 West 10th Street, Columbus, OH 43210, USA; The Ohio State University College of Medicine, 370 West 9th street, Columbus, OH 43210, USA.;Department of Neurological Surgery, The Ohio State Wexner Medical Center, 410 West 10th Street, Columbus, OH 43210, USA.;Department of Neurological Surgery, Baylor College of Medicine, 1 Baylor Plaza, Houston, TX 77030, USA.;Department of Neurological Surgery, The Ohio State Wexner Medical Center, 410 West 10th Street, Columbus, OH 43210, USA; Department of Neurological Surgery, Baylor College of Medicine, 1 Baylor Plaza, Houston, TX 77030, USA. Electronic address: David.xu@osumc.edu.' assert article_36400559['affiliations'] == affiliations_36400559 - affiliations_28786991 = 'Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.;Centers for Disease Control and Prevention, Division of Tuberculosis Elimination, Atlanta, Georgia, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.' + affiliations_28786991 = 'Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.|Global Health Sciences, University of California, San Francisco, San Francisco, California, United States of America.|The Consortium for the Assessment of Prevention Economics (CAPE), University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.|The Consortium for the Assessment of Prevention Economics (CAPE), University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.|The Consortium for the Assessment of Prevention Economics (CAPE), University of California, San Francisco, San Francisco, California, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.|Global Health Sciences, University of California, San Francisco, San Francisco, California, United States of America.|The Consortium for the Assessment of Prevention Economics (CAPE), University of California, San Francisco, San Francisco, California, United States of America.;Centers for Disease Control and Prevention, Division of Tuberculosis Elimination, Atlanta, Georgia, United States of America.;Phillip R. Lee Institute for Health Policy Studies, University of California, San Francisco, San Francisco, California, United States of America.|Global Health Sciences, University of California, San Francisco, San Francisco, California, United States of America.|The Consortium for the Assessment of Prevention Economics (CAPE), University of California, San Francisco, San Francisco, California, United States of America.' assert article_28786991['affiliations'] == affiliations_28786991