|
| 1 | +# Pull Request: Add PubMed Adapter |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +This PR adds comprehensive PubMed academic literature search capabilities to OpenCLI, enabling researchers and clinicians to access the PubMed database directly from the command line. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +### New Commands (6 total) |
| 10 | + |
| 11 | +| Command | Description | |
| 12 | +|---------|-------------| |
| 13 | +| `pubmed search` | Advanced article search with multiple filters | |
| 14 | +| `pubmed article` | Detailed article metadata retrieval | |
| 15 | +| `pubmed author` | Search by author name and affiliation | |
| 16 | +| `pubmed citations` | Get citation relationships | |
| 17 | +| `pubmed related` | Find semantically similar articles | |
| 18 | +| `pubmed config` | Configure API key for higher rate limits | |
| 19 | + |
| 20 | +### Key Capabilities |
| 21 | + |
| 22 | +- **Advanced Search Filters**: date range, author, journal, article type, abstract availability, free full text, human studies, language |
| 23 | +- **Complete Author Information**: first author, corresponding author, all authors, affiliations |
| 24 | +- **Publication Metadata**: title, abstract, journal, volume, issue, pages, publication date |
| 25 | +- **Academic Identifiers**: PMID, DOI, PMC ID |
| 26 | +- **Classification**: MeSH terms, keywords, article type |
| 27 | +- **Citation Analysis**: find articles that cite a given article or articles cited by it |
| 28 | +- **Related Articles**: discover semantically similar articles using PubMed's algorithm |
| 29 | + |
| 30 | +## API Integration |
| 31 | + |
| 32 | +Uses NCBI E-utilities APIs: |
| 33 | +- **ESearch**: Search for articles and retrieve PMIDs |
| 34 | +- **ESummary**: Get summary information for PMIDs |
| 35 | +- **EFetch**: Retrieve full article details including abstracts |
| 36 | +- **ELink**: Get citation relationships and related articles |
| 37 | + |
| 38 | +## Technical Implementation |
| 39 | + |
| 40 | +- **Language**: TypeScript with full type safety |
| 41 | +- **Strategy**: `Strategy.PUBLIC` (PubMed E-utilities is a public API) |
| 42 | +- **Rate Limiting**: Automatic delays to respect NCBI limits (3 req/s public, 10 req/s with API key) |
| 43 | +- **Error Handling**: Consistent use of `CliError` for all error cases |
| 44 | +- **Code Quality**: Follows existing OpenCLI patterns (similar to arXiv adapter) |
| 45 | + |
| 46 | +## Files Added |
| 47 | + |
| 48 | +``` |
| 49 | +clis/pubmed/ |
| 50 | +├── utils.ts # Shared utilities for API calls and data parsing |
| 51 | +├── search.ts # Article search with advanced filters |
| 52 | +├── article.ts # Detailed article information |
| 53 | +├── author.ts # Author-based search |
| 54 | +├── citations.ts # Citation relationships |
| 55 | +├── related.ts # Related articles discovery |
| 56 | +└── config.ts # API key configuration for higher rate limits |
| 57 | +``` |
| 58 | + |
| 59 | +## Usage Examples |
| 60 | + |
| 61 | +```bash |
| 62 | +# Search with filters |
| 63 | +opencli pubmed search "machine learning cancer" --year-from 2023 --has-abstract |
| 64 | + |
| 65 | +# Get article details |
| 66 | +opencli pubmed article 37780221 --format json |
| 67 | + |
| 68 | +# Search by author |
| 69 | +opencli pubmed author "Smith J" --affiliation "Stanford" --position first |
| 70 | + |
| 71 | +# Citation analysis |
| 72 | +opencli pubmed citations 37780221 --direction citedby --limit 50 |
| 73 | + |
| 74 | +# Find related articles |
| 75 | +opencli pubmed related 37780221 --score |
| 76 | + |
| 77 | +# Configure API key for higher rate limits (10 req/s vs 3 req/s) |
| 78 | +opencli pubmed config set --key api-key --value YOUR_NCBI_API_KEY |
| 79 | + |
| 80 | +# View current configuration |
| 81 | +opencli pubmed config get |
| 82 | + |
| 83 | +# Remove API key |
| 84 | +opencli pubmed config remove --key api-key |
| 85 | +``` |
| 86 | + |
| 87 | +## Testing |
| 88 | + |
| 89 | +- [x] Built successfully with `npm run build` |
| 90 | +- [x] Manifest compiled: 260 entries (121 YAML, 139 TS) |
| 91 | +- [x] All TypeScript files compile without errors |
| 92 | +- [ ] Runtime testing (requires NCBI API access) |
| 93 | + |
| 94 | +## Documentation |
| 95 | + |
| 96 | +A comprehensive README is available in the contribution package with: |
| 97 | +- Installation instructions |
| 98 | +- Detailed usage examples |
| 99 | +- API reference |
| 100 | +- Rate limit information |
| 101 | +- File structure explanation |
| 102 | + |
| 103 | +## Rate Limits & API Key Configuration |
| 104 | + |
| 105 | +The adapter implements automatic rate limiting: |
| 106 | +- **Without API key**: 350ms delay between requests (≈3 req/s) |
| 107 | +- **With API key**: 100ms delay between requests (≈10 req/s) |
| 108 | + |
| 109 | +### Getting an API Key |
| 110 | + |
| 111 | +1. Create an NCBI account at https://www.ncbi.nlm.nih.gov/account/ |
| 112 | +2. Go to https://www.ncbi.nlm.nih.gov/account/settings/ |
| 113 | +3. Generate an API key |
| 114 | + |
| 115 | +### Configuring Your API Key |
| 116 | + |
| 117 | +```bash |
| 118 | +# Set your API key |
| 119 | +opencli pubmed config set --key api-key --value YOUR_API_KEY |
| 120 | + |
| 121 | +# Set your email (recommended for identification) |
| 122 | +opencli pubmed config set --key email --value your@email.com |
| 123 | + |
| 124 | +# View current configuration |
| 125 | +opencli pubmed config get |
| 126 | + |
| 127 | +# Remove configuration |
| 128 | +opencli pubmed config remove --key api-key |
| 129 | +``` |
| 130 | + |
| 131 | +Configuration is stored in `~/.opencli/pubmed-config.json`. |
| 132 | + |
| 133 | +### Environment Variables |
| 134 | + |
| 135 | +Alternatively, you can use environment variables: |
| 136 | +- `NCBI_API_KEY` - Your NCBI API key |
| 137 | +- `NCBI_EMAIL` - Your email address |
| 138 | + |
| 139 | +## Backwards Compatibility |
| 140 | + |
| 141 | +This is a new adapter with no impact on existing functionality. |
| 142 | + |
| 143 | +## Checklist |
| 144 | + |
| 145 | +- [x] Code follows OpenCLI conventions |
| 146 | +- [x] TypeScript types are properly defined |
| 147 | +- [x] Error handling uses CliError |
| 148 | +- [x] Rate limiting is implemented |
| 149 | +- [x] Build passes successfully |
| 150 | +- [x] No breaking changes to existing code |
| 151 | + |
| 152 | +## Author |
| 153 | + |
| 154 | +**WorkBuddy** - An AI assistant helping researchers access scientific literature more efficiently. |
| 155 | + |
| 156 | +## References |
| 157 | + |
| 158 | +- [NCBI E-utilities Documentation](https://www.ncbi.nlm.nih.gov/books/NBK25501/) |
| 159 | +- [PubMed](https://pubmed.ncbi.nlm.nih.gov/) |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +**Related Issue**: N/A (new feature) |
| 164 | + |
| 165 | +**Breaking Changes**: None |
| 166 | + |
| 167 | +**Dependencies**: None (uses native fetch API) |
0 commit comments