Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#134 Parse version_id and version_date in parse_xml_web() #156

Merged
merged 2 commits into from
Sep 4, 2024
Merged
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
15 changes: 13 additions & 2 deletions pubmed_parser/pubmed_web_parser.py
nils-herrmann marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_pubmed_web_tree(tree):
'title', 'abstract', 'journal', 'affliation' (string of affiliation with ';' separated),
'authors' (string with ';' separated),
'keywords' (keywords and MeSH terms from an XML -- if MeSH term it will be 'MeSH descriptor':'MeSH name')
'doi', 'year'
'doi', 'pii', 'year', 'language', 'version_id', 'version_date'
"""
if len(tree.xpath("//articletitle")) != 0:
title = " ".join([title.text for title in tree.xpath("//articletitle")])
Expand Down Expand Up @@ -149,6 +149,13 @@ def parse_pubmed_web_tree(tree):
language = language[0].text
except IndexError:
language = None

medline_citation = tree.xpath('//medlinecitation')
try:
version_id = medline_citation[0].attrib.get('versionid')
version_date = medline_citation[0].attrib.get('versiondate')
except IndexError:
version_id, version_date = None, None

dict_out = {
"title": title,
Expand All @@ -160,7 +167,9 @@ def parse_pubmed_web_tree(tree):
"doi": doi,
"pii": pii,
"year": year,
"language": language
"language": language,
"version_id": version_id,
"version_date": version_date,
}
return dict_out

Expand Down Expand Up @@ -199,6 +208,8 @@ def parse_xml_web(pmid, sleep=None, save_xml=False):
'keywords': 'D000818:Animals;D005075:Biological Evolution;...',
'doi': '10.1126/science.1060852',
'year': '2001',
'version_id': None,
'version_date': None,
'pmid': '11360989'
}
"""
Expand Down
17 changes: 17 additions & 0 deletions tests/test_pubmed_web_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_pubmed_web_parser_all_fields_content():
"year": "2024",
"language": "ger",
"pmid": "38218666",
"version_id": None,
"version_date": None,
},
23340801: {
"title": "E. coli as an all-rounder: the thin line between commensalism and pathogenicity.",
Expand All @@ -32,6 +34,8 @@ def test_pubmed_web_parser_all_fields_content():
"year": "2013",
"language": "eng",
"pmid": "23340801",
"version_id": None,
"version_date": None,
},
}

Expand All @@ -54,6 +58,8 @@ def test_pubmed_web_parser_all_fields_existence():
"pii",
"year",
"language",
"version_id",
"version_date",
"pmid",
]
pubmed_dict = pp.parse_xml_web(random_id, save_xml=False)
Expand All @@ -80,3 +86,14 @@ def test_pii():
"""Test the correct parsing of the pii."""
pubmed_dict = pp.parse_xml_web("32145645", save_xml=False)
assert pubmed_dict['pii'] == "S0223-5234(20)30153-7"


def test_version():
"""Test the correct parsing of the version."""
xml_20029612 = pp.parse_xml_web('20029612')
assert xml_20029612['version_id'] == '4'
assert xml_20029612['version_date'] == '2011/01/03'

xml_21113338 = pp.parse_xml_web('21113338')
assert xml_21113338['version_id'] == '3'
assert xml_21113338['version_date'] is None
Loading