Skip to content

Commit d0b1b6a

Browse files
Greatkaijackwener
andauthored
feat(pubmed): revive public eutils adapter (#819)
Co-authored-by: jackwener <jakevingoo@gmail.com> Co-authored-by: Greatkai <4587517+Greatkai@users.noreply.github.com>
1 parent f1a8a2f commit d0b1b6a

12 files changed

Lines changed: 1237 additions & 0 deletions

File tree

README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ npm link
271271
| **devto** | `top` `tag` `user` | 公开 |
272272
| **dictionary** | `search` `synonyms` `examples` | 公开 |
273273
| **arxiv** | `search` `paper` | 公开 |
274+
| **pubmed** | `search` `article` `author` `citations` `related` | 公开 |
274275
| **openreview** | `search` `venue` `paper` `reviews` | 公开 |
275276
| **paperreview** | `submit` `review` `feedback` | 公开 |
276277
| **wikipedia** | `search` `summary` `random` `trending` | 公开 |

cli-manifest.json

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15181,6 +15181,329 @@
1518115181
"modulePath": "producthunt/today.js",
1518215182
"sourceFile": "producthunt/today.js"
1518315183
},
15184+
{
15185+
"site": "pubmed",
15186+
"name": "article",
15187+
"aliases": [
15188+
"paper",
15189+
"read"
15190+
],
15191+
"description": "Get detailed information for a PubMed article by PMID",
15192+
"access": "read",
15193+
"domain": "pubmed.ncbi.nlm.nih.gov",
15194+
"strategy": "public",
15195+
"browser": false,
15196+
"args": [
15197+
{
15198+
"name": "pmid",
15199+
"type": "str",
15200+
"required": true,
15201+
"positional": true,
15202+
"help": "PubMed ID, e.g. 37780221"
15203+
},
15204+
{
15205+
"name": "full-abstract",
15206+
"type": "boolean",
15207+
"default": false,
15208+
"required": false,
15209+
"help": "Do not truncate the abstract in table output"
15210+
}
15211+
],
15212+
"columns": [
15213+
"field",
15214+
"value"
15215+
],
15216+
"type": "js",
15217+
"modulePath": "pubmed/article.js",
15218+
"sourceFile": "pubmed/article.js"
15219+
},
15220+
{
15221+
"site": "pubmed",
15222+
"name": "author",
15223+
"description": "Search PubMed articles by author name and optional affiliation",
15224+
"access": "read",
15225+
"domain": "pubmed.ncbi.nlm.nih.gov",
15226+
"strategy": "public",
15227+
"browser": false,
15228+
"args": [
15229+
{
15230+
"name": "name",
15231+
"type": "str",
15232+
"required": true,
15233+
"positional": true,
15234+
"help": "Author name, e.g. \"Smith J\""
15235+
},
15236+
{
15237+
"name": "limit",
15238+
"type": "int",
15239+
"default": 20,
15240+
"required": false,
15241+
"help": "Max results (1-100)"
15242+
},
15243+
{
15244+
"name": "affiliation",
15245+
"type": "str",
15246+
"required": false,
15247+
"help": "Filter by author affiliation"
15248+
},
15249+
{
15250+
"name": "position",
15251+
"type": "str",
15252+
"default": "any",
15253+
"required": false,
15254+
"help": "Author position: any, first, or last",
15255+
"choices": [
15256+
"any",
15257+
"first",
15258+
"last"
15259+
]
15260+
},
15261+
{
15262+
"name": "year-from",
15263+
"type": "int",
15264+
"required": false,
15265+
"help": "Filter publication year from"
15266+
},
15267+
{
15268+
"name": "year-to",
15269+
"type": "int",
15270+
"required": false,
15271+
"help": "Filter publication year to"
15272+
},
15273+
{
15274+
"name": "sort",
15275+
"type": "str",
15276+
"default": "date",
15277+
"required": false,
15278+
"help": "Sort by date or relevance",
15279+
"choices": [
15280+
"date",
15281+
"relevance"
15282+
]
15283+
}
15284+
],
15285+
"columns": [
15286+
"rank",
15287+
"pmid",
15288+
"title",
15289+
"authors",
15290+
"journal",
15291+
"year",
15292+
"article_type",
15293+
"doi",
15294+
"url"
15295+
],
15296+
"type": "js",
15297+
"modulePath": "pubmed/author.js",
15298+
"sourceFile": "pubmed/author.js"
15299+
},
15300+
{
15301+
"site": "pubmed",
15302+
"name": "citations",
15303+
"description": "Get PubMed citation relationships for an article",
15304+
"access": "read",
15305+
"domain": "pubmed.ncbi.nlm.nih.gov",
15306+
"strategy": "public",
15307+
"browser": false,
15308+
"args": [
15309+
{
15310+
"name": "pmid",
15311+
"type": "str",
15312+
"required": true,
15313+
"positional": true,
15314+
"help": "PubMed ID, e.g. 37780221"
15315+
},
15316+
{
15317+
"name": "direction",
15318+
"type": "str",
15319+
"default": "citedby",
15320+
"required": false,
15321+
"help": "citedby or references",
15322+
"choices": [
15323+
"citedby",
15324+
"references"
15325+
]
15326+
},
15327+
{
15328+
"name": "limit",
15329+
"type": "int",
15330+
"default": 20,
15331+
"required": false,
15332+
"help": "Max results (1-100)"
15333+
}
15334+
],
15335+
"columns": [
15336+
"rank",
15337+
"pmid",
15338+
"title",
15339+
"authors",
15340+
"journal",
15341+
"year",
15342+
"article_type",
15343+
"doi",
15344+
"url"
15345+
],
15346+
"type": "js",
15347+
"modulePath": "pubmed/citations.js",
15348+
"sourceFile": "pubmed/citations.js"
15349+
},
15350+
{
15351+
"site": "pubmed",
15352+
"name": "related",
15353+
"description": "Find articles related to a PubMed article",
15354+
"access": "read",
15355+
"domain": "pubmed.ncbi.nlm.nih.gov",
15356+
"strategy": "public",
15357+
"browser": false,
15358+
"args": [
15359+
{
15360+
"name": "pmid",
15361+
"type": "str",
15362+
"required": true,
15363+
"positional": true,
15364+
"help": "PubMed ID, e.g. 37780221"
15365+
},
15366+
{
15367+
"name": "limit",
15368+
"type": "int",
15369+
"default": 20,
15370+
"required": false,
15371+
"help": "Max results (1-100)"
15372+
},
15373+
{
15374+
"name": "score",
15375+
"type": "boolean",
15376+
"default": false,
15377+
"required": false,
15378+
"help": "Show similarity scores when available"
15379+
}
15380+
],
15381+
"columns": [
15382+
"rank",
15383+
"pmid",
15384+
"title",
15385+
"authors",
15386+
"journal",
15387+
"year",
15388+
"article_type",
15389+
"score",
15390+
"doi",
15391+
"url"
15392+
],
15393+
"type": "js",
15394+
"modulePath": "pubmed/related.js",
15395+
"sourceFile": "pubmed/related.js"
15396+
},
15397+
{
15398+
"site": "pubmed",
15399+
"name": "search",
15400+
"description": "Search PubMed articles with advanced filters",
15401+
"access": "read",
15402+
"domain": "pubmed.ncbi.nlm.nih.gov",
15403+
"strategy": "public",
15404+
"browser": false,
15405+
"args": [
15406+
{
15407+
"name": "query",
15408+
"type": "str",
15409+
"required": true,
15410+
"positional": true,
15411+
"help": "Search query, e.g. \"machine learning cancer\""
15412+
},
15413+
{
15414+
"name": "limit",
15415+
"type": "int",
15416+
"default": 20,
15417+
"required": false,
15418+
"help": "Max results (1-100)"
15419+
},
15420+
{
15421+
"name": "author",
15422+
"type": "str",
15423+
"required": false,
15424+
"help": "Filter by author name"
15425+
},
15426+
{
15427+
"name": "journal",
15428+
"type": "str",
15429+
"required": false,
15430+
"help": "Filter by journal name"
15431+
},
15432+
{
15433+
"name": "year-from",
15434+
"type": "int",
15435+
"required": false,
15436+
"help": "Filter publication year from"
15437+
},
15438+
{
15439+
"name": "year-to",
15440+
"type": "int",
15441+
"required": false,
15442+
"help": "Filter publication year to"
15443+
},
15444+
{
15445+
"name": "article-type",
15446+
"type": "str",
15447+
"required": false,
15448+
"help": "Filter by publication type, e.g. Review or Clinical Trial"
15449+
},
15450+
{
15451+
"name": "has-abstract",
15452+
"type": "boolean",
15453+
"default": false,
15454+
"required": false,
15455+
"help": "Only include articles with abstracts"
15456+
},
15457+
{
15458+
"name": "free-full-text",
15459+
"type": "boolean",
15460+
"default": false,
15461+
"required": false,
15462+
"help": "Only include free full text articles"
15463+
},
15464+
{
15465+
"name": "humans-only",
15466+
"type": "boolean",
15467+
"default": false,
15468+
"required": false,
15469+
"help": "Only include human studies"
15470+
},
15471+
{
15472+
"name": "english-only",
15473+
"type": "boolean",
15474+
"default": false,
15475+
"required": false,
15476+
"help": "Only include English articles"
15477+
},
15478+
{
15479+
"name": "sort",
15480+
"type": "str",
15481+
"default": "relevance",
15482+
"required": false,
15483+
"help": "Sort by relevance, date, author, or journal",
15484+
"choices": [
15485+
"relevance",
15486+
"date",
15487+
"author",
15488+
"journal"
15489+
]
15490+
}
15491+
],
15492+
"columns": [
15493+
"rank",
15494+
"pmid",
15495+
"title",
15496+
"authors",
15497+
"journal",
15498+
"year",
15499+
"article_type",
15500+
"doi",
15501+
"url"
15502+
],
15503+
"type": "js",
15504+
"modulePath": "pubmed/search.js",
15505+
"sourceFile": "pubmed/search.js"
15506+
},
1518415507
{
1518515508
"site": "quark",
1518615509
"name": "ls",

clis/pubmed/article.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { cli, Strategy } from '@jackwener/opencli/registry';
2+
import { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
3+
import { eutilsFetch, parseArticleXml, requirePmid, truncateText } from './utils.js';
4+
5+
cli({
6+
site: 'pubmed',
7+
name: 'article',
8+
aliases: ['paper', 'read'],
9+
access: 'read',
10+
description: 'Get detailed information for a PubMed article by PMID',
11+
domain: 'pubmed.ncbi.nlm.nih.gov',
12+
strategy: Strategy.PUBLIC,
13+
browser: false,
14+
args: [
15+
{ name: 'pmid', positional: true, required: true, help: 'PubMed ID, e.g. 37780221' },
16+
{ name: 'full-abstract', type: 'boolean', default: false, help: 'Do not truncate the abstract in table output' },
17+
],
18+
columns: ['field', 'value'],
19+
func: async (args) => {
20+
const pmid = requirePmid(args.pmid);
21+
const xml = await eutilsFetch('efetch', {
22+
id: pmid,
23+
rettype: 'abstract',
24+
}, { retmode: 'xml', label: 'pubmed article' });
25+
const article = parseArticleXml(xml, pmid);
26+
if (!article) {
27+
throw new EmptyResultError('pubmed article', `No article found for PMID ${pmid}.`);
28+
}
29+
if (!article.title) {
30+
throw new CommandExecutionError(`pubmed article ${pmid} did not include a title`, 'PubMed EFetch response shape may have changed.');
31+
}
32+
const abstract = args['full-abstract'] ? article.abstract : truncateText(article.abstract, 500);
33+
return [
34+
{ field: 'PMID', value: article.pmid },
35+
{ field: 'Title', value: article.title },
36+
{ field: 'Authors', value: article.authors.join(', ') },
37+
{ field: 'Journal', value: article.journal },
38+
{ field: 'Year', value: article.year },
39+
{ field: 'Date', value: article.date },
40+
{ field: 'Article Type', value: article.article_type },
41+
{ field: 'Language', value: article.language },
42+
{ field: 'DOI', value: article.doi || null },
43+
{ field: 'PMC ID', value: article.pmc || null },
44+
{ field: 'MeSH Terms', value: article.mesh_terms || null },
45+
{ field: 'Keywords', value: article.keywords || null },
46+
{ field: 'Abstract', value: abstract || null },
47+
{ field: 'URL', value: article.url },
48+
];
49+
},
50+
});

0 commit comments

Comments
 (0)