@@ -203,6 +203,10 @@ def fetch(
203203 # A failed refresh must not overwrite useful cached text with just
204204 # summary metadata. None also enables ReferenceFetcher's stale fallback.
205205 return None
206+ if not title .strip () and article_xml :
207+ # A whole-book record (an AHRQ evidence report, say) has an empty
208+ # summary Title; its title is the BookDocument's BookTitle.
209+ title = self ._parse_book_title (article_xml ) or ""
206210 abstract = self ._parse_abstract (article_xml ) if article_xml else None
207211 keywords = self ._parse_mesh_terms (article_xml ) if article_xml else None
208212 publication_types = (
@@ -487,6 +491,44 @@ def _fetch_pubmed_xml(
487491 # for str.
488492 return BeautifulSoup (xml_content , "xml" )
489493
494+ @staticmethod
495+ def _parse_book_title (soup : BeautifulSoup ) -> Optional [str ]:
496+ """Return the title of a Bookshelf record from its PubMed XML.
497+
498+ PubMed's summary leaves ``Title`` empty for a record that is a whole
499+ book rather than a chapter. The article XML still names it: a chapter
500+ by its ``ArticleTitle``, a whole book by ``Book/BookTitle``.
501+
502+ Args:
503+ soup: Parsed PubMed article XML
504+
505+ Returns:
506+ The record's title, or None if this is not a Bookshelf record
507+
508+ Examples:
509+ >>> from bs4 import BeautifulSoup
510+ >>> xml = '''<PubmedBookArticle><BookDocument>
511+ ... <Book><BookTitle book="cer86">Treatment for Restless Legs Syndrome</BookTitle></Book>
512+ ... </BookDocument></PubmedBookArticle>'''
513+ >>> PMIDSource._parse_book_title(BeautifulSoup(xml, "xml"))
514+ 'Treatment for Restless Legs Syndrome'
515+ >>> xml = '''<PubmedBookArticle><BookDocument>
516+ ... <Book><BookTitle book="gene">GeneReviews</BookTitle></Book>
517+ ... <ArticleTitle book="gene" part="men1">Multiple Endocrine Neoplasia Type 1</ArticleTitle>
518+ ... </BookDocument></PubmedBookArticle>'''
519+ >>> PMIDSource._parse_book_title(BeautifulSoup(xml, "xml"))
520+ 'Multiple Endocrine Neoplasia Type 1'
521+ >>> PMIDSource._parse_book_title(BeautifulSoup("<PubmedArticle/>", "xml")) is None
522+ True
523+ """
524+ document = soup .find ("BookDocument" )
525+ if document is None :
526+ return None
527+ for element in (document .find ("ArticleTitle" ), document .find ("BookTitle" )):
528+ if element is not None and element .get_text ().strip ():
529+ return element .get_text ().strip ()
530+ return None
531+
490532 @staticmethod
491533 def _parse_bookshelf_chapter (soup : BeautifulSoup ) -> Optional [tuple [str , str ]]:
492534 """Return ``(NBK accession, "<book>/<part>")`` for a Bookshelf chapter.
0 commit comments