Skip to content

Take a whole-book PubMed record's title from its BookTitle - #167

Merged
cmungall merged 1 commit into
mainfrom
fix/book-title-fallback
Nov 11, 2026
Merged

cmungall merged 1 commit into
mainfrom
fix/book-title-fallback

Conversation

@cmungall

Copy link
Copy Markdown
Member

A PubMed record for a whole Bookshelf book, rather than a chapter, has an empty Title in its eSummary. PMIDSource therefore cached such references with no title, and anything downstream that compares or copies titles had nothing to work with.

PMID:23304742 (AHRQ Comparative Effectiveness Review 86) is an example. Its record is a PubmedBookArticle whose BookDocument has <BookTitle book="cer86">Treatment for Restless Legs Syndrome</BookTitle> and no ArticleTitle. Biopython's eSummary parser does not expose a BookTitle field at all, so the title can't come from the summary.

Change

PMIDSource.fetch already downloads and parses the article XML for the abstract. When the summary Title is empty, it now takes the title from that XML with a new static method, _parse_book_title: the chapter's ArticleTitle if present, otherwise Book/BookTitle. Journal articles and chapters always have a non-empty summary Title, so the fallback never runs for them.

Tests

  • Doctests on _parse_book_title cover a whole book, a chapter, and a non-book record.
  • test_whole_book_record_takes_its_title_from_book_title in tests/test_pmid_network.py runs the real Entrez transport and parser against the file's local HTTP server, with a summary/article pair shaped like PMID:23304742. Written first, it failed with '' == 'Treatment for Restless Legs Syndrome'; it passes with the change.
  • just test passes: 2,462 tests, mypy clean, ruff clean.
  • Live fetches against NCBI, comparing 0.4.0 with and without the change:
PMID Record Title before Title after Abstract
23304742 AHRQ CER 86 (whole book) '' Treatment for Restless Legs Syndrome unchanged
25695122 IOM report (whole book) '' Beyond Myalgic Encephalomyelitis/Chronic Fatigue Syndrome: Redefining an Illness unchanged
31909928 NICE guideline (whole book) '' Cannabis-based medicinal products unchanged
20301282 GeneReviews chapter Primary Trimethylaminuria. same unchanged
34081534 journal article Axonal Growth Abnormalities Underlying Ocular Cranial Nerve Disorders. same unchanged

Why now

monarch-initiative/dismech is about to make reference_title a required slot on evidence items. These three PMIDs are the only references it cites whose cache records no title, and it fills titles only by copying them from the cache, never by typing them.


Generated by Claude Code

PubMed's eSummary leaves Title empty for a record that is a whole
Bookshelf book rather than a chapter (PMID:23304742, AHRQ Comparative
Effectiveness Review 86, for example), so the cached reference had no
title. The article XML that fetch() already downloads for the abstract
still names the book in BookDocument/Book/BookTitle.

When the summary Title is empty, take the title from that XML: the
chapter's ArticleTitle if there is one, else the BookTitle. Journal
articles and chapters have a non-empty summary Title and are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UDqeWsdcTfKeW7LriK6a9f
@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 37s —— View job


PR review: Take a whole-book PubMed record's title from its BookTitle

  • Read the PR diff and the surrounding PMIDSource.fetch code
  • Review correctness, edge cases, tests, performance and security
  • Post feedback

Verdict: looks good to merge. The fix is small and well targeted, and the test was written first against the real transport. I found no blocking issues. The notes below are minor or optional.

What's good

  • Scoped fallback. It only runs when the summary Title is empty and the article XML is present (pmid.py:206), so journal articles and chapters behave exactly as before.
  • Safe for non-book records. _parse_book_title returns None unless there is a BookDocument. A journal article that happens to have an empty summary title stays empty instead of getting a wrong title.
  • No extra cost. It reuses the efetch XML that is already downloaded for the abstract, so there is no extra request to NCBI.
  • No new security risk. The XML comes from the same BeautifulSoup "xml" parse the module already uses.
  • Good tests. The doctests cover a whole book, a chapter, and a non-book record. The network test runs the real Entrez.read against the local server, which matters here because the bug comes from Biopython's eSummary parser not exposing BookTitle.

Minor suggestions (optional)

  1. Whitespace inside the title (pmid.py:528-529): get_text().strip() trims the ends but keeps any newlines or runs of spaces inside the title. PubMed XML is usually on one line, but " ".join(element.get_text().split()) would guard against wrapped titles. That matters if dismech compares titles as strings. The method also calls get_text() twice; you could store it in a variable.
  2. Recursive find: document.find("ArticleTitle") and document.find("BookTitle") search all descendants, not just direct children. Neither tag appears deeper inside BookDocument in the current DTD, so this is fine today. If you want to be strict, recursive=False on ArticleTitle, plus a document.find("Book") step for BookTitle, would make the intent explicit.
  3. Trailing period: summary titles for chapters and articles end with . (Primary Trimethylaminuria.), but BookTitle doesn't (Treatment for Restless Legs Syndrome). This is harmless, but worth knowing if downstream code normalises or compares titles.
  4. Old cache entries won't fix themselves: references already cached with an empty title keep it until they are fetched again. For the dismech change, the three PMIDs need a forced re-fetch or their cache files deleted. A sentence about this in the PR description or changelog would help.
  5. Test gap (nit): the network test covers the whole-book case. A second case with an empty summary Title but an ArticleTitle in the XML would exercise the ArticleTitle branch end to end, not just in the doctest. This is low priority because, as the PR says, chapters always have a summary title in practice.

Performance

No concern. It is one extra tree search, only on the rare empty-title path.

Not done

I couldn't run the tests in this environment: running pytest needs approval that this job doesn't have. The review is based on reading the code. The PR reports that just test passes.

@cmungall
cmungall merged commit 17297c4 into main Nov 11, 2026
7 checks passed
cmungall pushed a commit to monarch-initiative/dismech that referenced this pull request Nov 18, 2026
linkml-reference-validator 0.5.2rc1 reads a whole-book PubMed record's
title from its BookTitle (linkml/linkml-reference-validator#167). Before
that, these three records cached with no title: PMID:23304742 (AHRQ CER
86, restless legs syndrome treatment), PMID:25695122 (IOM ME/CFS report)
and PMID:31909928 (NICE cannabis-based medicinal products guideline).

Re-fetched with `just fetch-reference --force`; the abstract text is
unchanged (186/186 snippets in the citing entries still verify). The two
evidence items citing PMID:23304742 get their reference_title from the
cache via backfill_reference_titles.py, which takes the presence gate
to zero, report-only items included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UDqeWsdcTfKeW7LriK6a9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants