@yeyuan98/opencode-bioresearcher-plugin 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,7 @@ export declare const parse_pubmed_articleSet: {
|
|
|
7
7
|
outputMode: z.ZodDefault<z.ZodEnum<{
|
|
8
8
|
single: "single";
|
|
9
9
|
individual: "individual";
|
|
10
|
+
excel: "excel";
|
|
10
11
|
}>>;
|
|
11
12
|
outputFileName: z.ZodOptional<z.ZodString>;
|
|
12
13
|
outputDir: z.ZodOptional<z.ZodString>;
|
|
@@ -14,7 +15,7 @@ export declare const parse_pubmed_articleSet: {
|
|
|
14
15
|
};
|
|
15
16
|
execute(args: {
|
|
16
17
|
filePath: string;
|
|
17
|
-
outputMode: "single" | "individual";
|
|
18
|
+
outputMode: "single" | "individual" | "excel";
|
|
18
19
|
verbose: boolean;
|
|
19
20
|
outputFileName?: string | undefined;
|
|
20
21
|
outputDir?: string | undefined;
|
|
@@ -4,7 +4,7 @@ import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
|
|
|
4
4
|
import { gunzipSync } from 'zlib';
|
|
5
5
|
import { join, resolve } from 'path';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { toArray, extractAllFields, generateArticleMarkdown } from './utils.js';
|
|
7
|
+
import { toArray, extractAllFields, generateArticleMarkdown, generateExcelFile } from './utils.js';
|
|
8
8
|
function formatError(error) {
|
|
9
9
|
const message = error instanceof Error ? error.message : String(error);
|
|
10
10
|
return JSON.stringify({ error: message }, null, 2);
|
|
@@ -114,7 +114,18 @@ function processArticles(articleXmls, outputPath, mode, outputFileName, verbose
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
ensureDir(outputPath);
|
|
117
|
-
if (mode === '
|
|
117
|
+
if (mode === 'excel') {
|
|
118
|
+
const fileName = outputFileName || 'pubmed_articles.xlsx';
|
|
119
|
+
const filePath = join(outputPath, fileName);
|
|
120
|
+
generateExcelFile(parsedArticles, filePath);
|
|
121
|
+
if (verbose)
|
|
122
|
+
console.log(`Wrote Excel file: ${filePath}`);
|
|
123
|
+
return {
|
|
124
|
+
filePath,
|
|
125
|
+
stats: { total: articleXmls.length, successful: successCount, failed: failCount }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else if (mode === 'single') {
|
|
118
129
|
const fileName = outputFileName || 'pubmed_articles.md';
|
|
119
130
|
const filePath = join(outputPath, fileName);
|
|
120
131
|
const allMarkdown = parsedArticles
|
|
@@ -145,13 +156,13 @@ function processArticles(articleXmls, outputPath, mode, outputFileName, verbose
|
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
158
|
export const parse_pubmed_articleSet = tool({
|
|
148
|
-
description: 'Parse PubMed XML file and convert to markdown format. Supports both .xml and .xml.gz files.
|
|
159
|
+
description: 'Parse PubMed XML file and convert to markdown or Excel format. Supports both .xml and .xml.gz files. Output modes: single markdown file, individual markdown files, or single Excel file.',
|
|
149
160
|
args: {
|
|
150
161
|
filePath: z.string()
|
|
151
162
|
.describe('Path to XML PubMed file (.xml or .xml.gz)'),
|
|
152
|
-
outputMode: z.enum(['single', 'individual'])
|
|
163
|
+
outputMode: z.enum(['single', 'individual', 'excel'])
|
|
153
164
|
.default('single')
|
|
154
|
-
.describe('Output mode: single file
|
|
165
|
+
.describe('Output mode: single markdown file, individual markdown files, or single Excel file'),
|
|
155
166
|
outputFileName: z.string()
|
|
156
167
|
.optional()
|
|
157
168
|
.describe('Custom output file/directory name (default: pubmed_articles)'),
|
|
@@ -101,3 +101,14 @@ export interface ProcessingStats {
|
|
|
101
101
|
successful: number;
|
|
102
102
|
failed: number;
|
|
103
103
|
}
|
|
104
|
+
export interface ExcelRow {
|
|
105
|
+
PMID: string;
|
|
106
|
+
Title: string;
|
|
107
|
+
PublicationDate: string;
|
|
108
|
+
Authors: string;
|
|
109
|
+
Journal: string;
|
|
110
|
+
DOI: string;
|
|
111
|
+
Abstract: string;
|
|
112
|
+
Keywords: string;
|
|
113
|
+
Error: string;
|
|
114
|
+
}
|
|
@@ -11,3 +11,4 @@ export declare function extractKeywords(article: PubmedArticle): string[];
|
|
|
11
11
|
export declare function extractPublicationDate(article: PubmedArticle): string | undefined;
|
|
12
12
|
export declare function extractAllFields(article: PubmedArticle): ParsedArticle;
|
|
13
13
|
export declare function generateArticleMarkdown(data: ParsedArticle): string;
|
|
14
|
+
export declare function generateExcelFile(articles: ParsedArticle[], outputFilePath: string): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import XLSX from 'xlsx';
|
|
1
2
|
export function getText(obj) {
|
|
2
3
|
if (obj === null || obj === undefined)
|
|
3
4
|
return null;
|
|
@@ -156,3 +157,20 @@ export function generateArticleMarkdown(data) {
|
|
|
156
157
|
}
|
|
157
158
|
return markdown;
|
|
158
159
|
}
|
|
160
|
+
export function generateExcelFile(articles, outputFilePath) {
|
|
161
|
+
const excelRows = articles.map(article => ({
|
|
162
|
+
PMID: article.error ? `[ERROR] ${article.PMID}` : article.PMID,
|
|
163
|
+
Title: article.title,
|
|
164
|
+
PublicationDate: article.publicationDate || '',
|
|
165
|
+
Authors: article.authors.join(', '),
|
|
166
|
+
Journal: article.journal,
|
|
167
|
+
DOI: article.doi || '',
|
|
168
|
+
Abstract: article.abstract || '',
|
|
169
|
+
Keywords: article.keywords.join(', '),
|
|
170
|
+
Error: article.error || ''
|
|
171
|
+
}));
|
|
172
|
+
const workbook = XLSX.utils.book_new();
|
|
173
|
+
const worksheet = XLSX.utils.json_to_sheet(excelRows);
|
|
174
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, 'PubMed Articles');
|
|
175
|
+
XLSX.writeFile(workbook, outputFilePath);
|
|
176
|
+
}
|