Repository navigation
feat(literature): ArticleClient.get_related_articles - #409
Merged
Merged
Conversation
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>
|
Warning Review limit reachedYou'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. View limit details
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. |
Codecov Report❌ Patch coverage is
@@ 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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #396.
Adds
ArticleClient.get_related_articles(source, article_id, ...).Europe PMC has no similar-articles endpoint:
/{source}/{id}/similarand/relatedreturn 404, andSIMILAR:/RELATED:are not query fields (checked against the live API). The method therefore builds a search from what the article is indexed with:Humans,Animals,Male,Female, age groups,Mice,Ratsand a few more), or its author keywords (basis="mesh" | "keywords" | "auto").MESH:("a" OR "b" OR "c") AND NOT (EXT_ID:<id> AND SRC:<source>);match="all"joins the terms with AND.SearchClient.search():page_size,cursor_mark,result_type,sort, extra parameters. It returns{query, terms, hitCount, nextCursorMark, results}with records parsed assearch_and_parse()does. Passing the returnedterms(andnextCursorMark) to the next call fetches the next page without re-reading the article.One thing worth knowing: Europe PMC evaluates
MESH:"a" OR MESH:"b"asMESH:"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
tests/article/unit/test_article_related.py: query construction, term selection, paging, no-terms, validation and failed requests.mcp1.30.0 where the lock pins 2.3.0, which errors inmcp/server.py, a file not touched here).docs/api/article-client.md; CHANGELOG underAdded.This branch is cut from
main, so it is independent of #407 and #408; the three touch different parts ofarticle.py.🤖 Generated with Claude Code