Skip to content
Open
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
13 changes: 11 additions & 2 deletions pubmed_parser/medline_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,17 @@ def parse_medline_xml(
------
An iterator of dictionary containing information about articles in NLM format.
see `parse_article_info`). Articles that have been deleted will be
added with no information other than the field `delete` being `True`
added with no information other than the fields `delete` being `True`,
and `pmid`.

Examples
--------
>>> article_iterator = pubmed_parser.parse_medline_xml('data/pubmed20n0014.xml.gz')
>>> for article in article_iterator:
... print(article['title'])
... if article.get('delete'):
... print(f"Deleted PMID: {article['pmid']}")
... else:
... print(article['title'])
"""
with gzip.open(path, "rb") as f:
for event, element in etree.iterparse(f, events=("end",)):
Expand All @@ -762,3 +766,8 @@ def parse_medline_xml(
res['grant_ids'] = parse_grant_id(element)
element.clear()
yield res

elif element.tag == "DeleteCitation":
for pmid_elem in element.iterchildren(tag="PMID"):
yield {"pmid": pmid_elem.text, "delete": True}
element.clear()
Loading