Skip to content

feat(literature): ArticleClient.get_related_articles - #409

Merged
JonasHeinickeBio merged 1 commit into
mainfrom
feat/related-articles
Nov 7, 2026
Merged

JonasHeinickeBio merged 1 commit into
mainfrom
feat/related-articles

Conversation

@JonasHeinickeBio

Copy link
Copy Markdown
Owner

Summary

Closes #396.

Adds ArticleClient.get_related_articles(source, article_id, ...).

Europe PMC has no similar-articles endpoint: /{source}/{id}/similar and /related return 404, and SIMILAR: / RELATED: are not query fields (checked against the live API). The method therefore builds a search from what the article is indexed with:

  • Terms are the article's MeSH headings, major topics first and without the headings nearly every article carries (Humans, Animals, Male, Female, age groups, Mice, Rats and a few more), or its author keywords (basis="mesh" | "keywords" | "auto").
  • The query is MESH:("a" OR "b" OR "c") AND NOT (EXT_ID:<id> AND SRC:<source>); match="all" joins the terms with AND.
  • Pagination and result types follow SearchClient.search(): page_size, cursor_mark, result_type, sort, extra parameters. It returns {query, terms, hitCount, nextCursorMark, results} with records parsed as search_and_parse() does. Passing the returned terms (and nextCursorMark) to the next call fetches the next page without re-reading the article.
  • An article with no usable terms gives an empty page and no search.

One thing worth knowing: Europe PMC evaluates MESH:"a" OR MESH:"b" as MESH:"b" alone, so the field is named once and the terms grouped. A test pins that.

The result is a ranking by shared subject headings, not PubMed's "similar articles"; the docs say so.

Testing

  • 25 new hermetic tests in tests/article/unit/test_article_related.py: query construction, term selection, paging, no-terms, validation and failed requests.
  • Tried live against Europe PMC: related articles of PMID 23087375 in three modes, paging with the returned cursor (no overlap between pages), keywords, and the empty case.
  • Full non-slow suite passes; ruff 0.17.3 and mypy on the module are clean. The local mypy hook was skipped for the commit (the shared venv has mcp 1.30.0 where the lock pins 2.3.0, which errors in mcp/server.py, a file not touched here).
  • Docs: docs/api/article-client.md; CHANGELOG under Added.

This branch is cut from main, so it is independent of #407 and #408; the three touch different parts of article.py.

🤖 Generated with Claude Code

Europe PMC's REST API has no similar-articles endpoint, so the method searches on the article's
MeSH headings (or keywords): major topics first, without generic headings such as Humans, the
article itself left out. It pages like SearchClient.search (page_size, cursor_mark, result_type,
sort) and returns the query, terms, hitCount, nextCursorMark and the parsed records. The field is
named once with the terms grouped, because Europe PMC evaluates MESH:"a" OR MESH:"b" as
MESH:"b" alone.

Closes #396

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests labels Nov 7, 2026
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f52ebf9b-2c01-475d-add6-85477d951bc5
Commits

Reviewing files that changed from the base of the PR and between 034b655 and 2de38ee.

Files selected for processing: 4

  • CHANGELOG.md
  • docs/api/article-client.md
  • src/pyeuropepmc/features/literature/article.py
  • tests/article/unit/test_article_related.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyeuropepmc/features/literature/article.py 92.00% 4 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
+ Coverage   82.91%   82.93%   +0.01%     
==========================================
  Files         220      220              
  Lines       33628    33678      +50     
  Branches     6055     6060       +5     
==========================================
+ Hits        27883    27931      +48     
- Misses       4460     4463       +3     
+ Partials     1285     1284       -1     
Files with missing lines Coverage Δ
src/pyeuropepmc/features/literature/article.py 82.67% <92.00%> (+2.01%) ⬆️

@JonasHeinickeBio
JonasHeinickeBio merged commit 3fed427 into main Nov 7, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add high-level similar-article and related-content retrieval

1 participant