Skip to content

Commit

Permalink
#119 Requested changes: Clean up the elif convolute
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-herrmann committed May 23, 2024
1 parent 0bd12bf commit a73fa7a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pubmed_parser/pubmed_oa_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ def parse_pubmed_xml(path, include_path=False, nxml=False):
return dict_out


def get_reference(reference):
"""Get reference from one of the three possible positions."""
for tag in ["mixed-citation", "element-citation", "citation"]:
ref = reference.find(tag)
if ref is not None:
return ref
return None


def parse_pubmed_references(path):
"""
Given path to xml file, parse references articles
Expand All @@ -260,15 +269,7 @@ def parse_pubmed_references(path):
for reference in references:
ref_id = reference.attrib["id"]

if reference.find("mixed-citation") is not None:
ref = reference.find("mixed-citation")
elif reference.find("element-citation") is not None:
ref = reference.find("element-citation")
elif reference.find("citation") is not None:
ref = reference.find("citation")
else:
ref = None

ref = get_reference(reference)
if ref is not None:
ref_types = ["citation-type", "publication-type"]
if any(ref_type in ref_types for ref_type in ref.attrib.keys()):
Expand Down

0 comments on commit a73fa7a

Please sign in to comment.