[Share] Extract Abstract Keywords #136
MuiseDestiny
started this conversation in
Action Scripts
Replies: 2 comments 4 replies
-
The script will be executed for each selected item, and saving item is always called by plugin. So maybe just: /**
* Extract Abstract Keywords
* @author Polygon
* @link https://github.com/windingwind/zotero-actions-tags/discussions/136
*/
const window = require("window");
const console = window.console;
let n = 0;
if ((await item.getBestAttachmentState()).exists == false) {
return;
}
const pdfItem = await item.getBestAttachment();
if (!pdfItem) {
return;
}
const text = (await Zotero.PDFWorker.getFullText(pdfItem.id, 2, true)).text;
const res = text.match(/\n(Abstract[\s\S]+?)\nKeywords(.+)/i);
if (res && res.length == 3) {
const data = {
abstract: res[1]
.replace(/^abstract:?\s*/i, "")
.replace("\n", " ")
.replace(/\s+/, " "),
keywords: res[2]
.replace(/^\s*:\s*/, "")
.trim()
.split(/[;,]\s*/)
.map((i) => i.trim()),
};
console.log(data);
await Promise.all(
data.keywords.map(async (tag) => {
item.addTag(tag);
})
);
item.setField("abstractNote", data.abstract);
}
return "Extracted item keywords and abstract."; |
Beta Was this translation helpful? Give feedback.
0 replies
-
你好,运行该脚本没有报错,但是也没有提取出关键词是什么原因呢?PDF文件是使用Zotfile另存的,不是存在Zotero内部的,会有影响吗 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
PDF's
Abstract
-> Item'sAbstract Note
field.PDF's
Keywords
-> Item'sTags
.Event
Creat Item
Operation
Script
Data
Anything else
No response
Beta Was this translation helpful? Give feedback.
All reactions