[Share] Extract Abstract Keywords #136
Replies: 6 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.
-
你好,运行该脚本没有报错,但是也没有提取出关键词是什么原因呢?PDF文件是使用Zotfile另存的,不是存在Zotero内部的,会有影响吗 |
Beta Was this translation helpful? Give feedback.
-
Zotero版本
在脚本中加入debug语句后发现未获取到条目, 但其他需要获取条目的脚本工作正常. 请问一下有没有解决办法? 另外, 能否将添加摘要的功能改成仅在没有摘要时添加来自PDF的摘要, 大概类似下面这个JS片段: if(item.getField("abstractNote") === null && data.abstract !== undefined){
item.setField("abstractNote", data.abstract);
} |
Beta Was this translation helpful? Give feedback.
-
I would like to follow-up on the |
Beta Was this translation helpful? Give feedback.
-
How do I use this template? How do I run an action script? |
Beta Was this translation helpful? Give feedback.
-
会提取到一些“Biochips · CAD tools · Euler tour · Graph matching · Testing”这样的关键词,需要对 |
Beta Was this translation helpful? Give feedback.
-
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