perf(pmid): derive abstract from the single article-XML fetch#58
Conversation
Addresses the deferred note 2 from PR #57 review. Previously fetch() made two efetch calls per PMID: one for the abstract (rettype=abstract, text) and one for the article XML (MeSH terms + publication types). The article XML already contains the abstract, so parse it from there and drop the second call along with its rate-limit sleep. - New _parse_abstract reconstructs prose from Abstract/AbstractText, preserving structured-section labels (e.g. "METHODS:"); replaces the now-removed _fetch_abstract. - content is now the abstract prose only, without the citation-header boilerplate the text fetch used to prepend. Supporting-text validation matches claims against abstract/full-text prose, not headers, so this is neutral-to-cleaner; a record with no abstract now correctly yields no content instead of a header-only stub. Tests: structured/unstructured/absent/empty abstract parsing, plus a fetch() test asserting exactly one efetch call backs all three fields. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Claude finished @caufieldjh's task in 1m 30s —— View job Review:
|
Follow-up to #57, addressing the review's deferred note 2 ("still two efetch calls per PMID").
What changed
PMIDSource.fetch()used to make two NCBI efetch calls per PMID:rettype="abstract", retmode="text"→ the abstractrettype="xml"→ the article XML (MeSH terms + publication types)The article XML already contains the abstract, so this parses it from there and drops the second call (and its
rate_limit_delaysleep). One fewer round-trip to NCBI per PMID._parse_abstract(soup)reconstructs the abstract prose fromAbstract/AbstractText, preserving structured-section labels (e.g.METHODS:,RESULTS:), mirroring how PubMed renders structured abstracts as text. Replaces the now-removed_fetch_abstract.Behavior note (why this was deferred, and why it's safe)
contentis now the abstract prose only, without the citation-header boilerplate (title/authors/journal/PMID/DOI) that the old text-mode fetch prepended. This is safe — and arguably cleaner:content; the real/e2e validation tests use cached fixtures, not live fetches.content_type"unavailable"/"summary") instead of a header-only stub that was misleadingly taggedabstract_only.Live verification
lookup PMID:33301246now reconstructs the structured abstract from a single efetch:Testing
New unit tests: structured / unstructured / absent / empty abstract parsing, plus a
fetch()test asserting exactly oneEntrez.efetchcall backs all three fields (abstract, MeSH, publication types). Doctests on_parse_abstract.Full
just testgreen: 625 passed, mypy + ruff clean.🤖 Generated with Claude Code