1.
我使用的zotero是官方绿色版,你其他那几个动作可以成功运行,但是这个“一键看文献”出错,zotero中总是找不到pdf,zotero报错如下
2.
运行过程中,
之前旧的VBA版本好像是获得的:
Li et al., 2022|zotero://select/items/1_W7LTGIDT
现在运行C#代码得到的是这样的字符:
Li et al., 2022|128373
不知道报错是否和这个有关?
3.
这种改变是因为在zotero中运行下面代码无法达到效果,所以改变的吗?
$$
let AttachID=Zotero.Items.get({ItemID}).getAttachments();
if(AttachID.length!=0){
let item=Zotero.Items.get(AttachID[0]);
Zotero.Reader.open(item.id);
} else {
ZoteroPane_Local.selectItem({ItemID});
alert("没找到PDF文件,但已定位到该文献条目!");
}
4.
如果我仍然想获得“Li et al., 2022|zotero://select/items/1_W7LTGIDT”这样的字符串,C#那里应该怎么改啊?(我觉得"W7LTGIDT这种8位随机字母数字混合的比较通用一些,不知道现在为什么是 “128373”这种纯数字)
谢谢解惑
刚才测试了一下,“一键看文献”又能用了,难道是昨天更新zotero到 v6.0.20 的原因
Ps.我这个绿色版是官方的那个,还挺好用,但是如果想要调用 zotero://select/items/ItemKey(key) 的话,需要往注册表写个键
// FieldCode为获取到的域代码
string FieldCode="ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"3FIW7gOp\",\"properties\":{\"formattedCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"plainCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"noteIndex\":0},\"citationItems\":[{\"id\":1558,\"uris\":[\"http://zotero.org/users/1817658/items/WAJ2XKB5\"],\"itemData\":{\"id\":1558,\"type\":\"article-journal\",\"collection-title\":\"7.116\",\"container-title\":\"Biology and Fertility of Soils\",\"DOI\":\"10.1007/s00374-018-01338-3\",\"issue\":\"2\",\"language\":\"en-US\",\"note\":\"ISBN: 1432-0789\\npublisher: Springer\\nCitation Key: fungo2019Biol.Fertil.Soils\",\"page\":\"135-148\",\"title\":\"Ammonia and nitrous oxide emissions from a field Ultisol amended with tithonia green manure, urea, and biochar\",\"volume\":\"55\",\"author\":[{\"family\":\"Fungo\",\"given\":\"Bernard\"},{\"family\":\"Lehmann\",\"given\":\"Johannes\"},{\"family\":\"Kalbitz\",\"given\":\"Karsten\"},{\"family\":\"Thionģo\",\"given\":\"Margaret\"},{\"family\":\"Tenywa\",\"given\":\"Moses\"},{\"family\":\"Okeyo\",\"given\":\"Irene\"},{\"family\":\"Neufeldt\",\"given\":\"Henry\"}],\"issued\":{\"date-parts\":[[\"2019\"]]}}},{\"id\":1514,\"uris\":[\"http://zotero.org/users/1817658/items/FPWETRUL\"],\"itemData\":{\"id\":1514,\"type\":\"article-journal\",\"abstract\":\"Climate change continues to have a great impact on rice production in China, especially in Northeast China (NEC). Historical climate observations from the China Meteorological Administration and statistical agricultural records at the county level were utilized to evaluate the spatial and temporal effects of both climatic and socioeconomic factors on rice production between 1980 and 2010 in NEC by using a linear regression model. The results showed that a 1% increase in the rice accumulated temperature (RAT) significantly increases rice production by approximately 0.728%. Rising RAT over the past three decades increased rice production by 4.44% (equal to a relative contribution of 0.87% to production growth) in NEC, while the majority of rice production growth (79.6%) resulted from increased agricultural inputs. Furthermore, rice production has increased significantly since 2000, and its geographic centroid shifted over 320 km northeastward during the past 30 years. Historical statistical and simulated rice production data for each county were used to quantify the spatial relocation of rice production due to single climatic factors. During 1980–2010, temperature had a significant and coherent influence on moving rice production. The impact of growing season precipitation was not significant, while sunshine had a significant but less spatially coherent influence. Our findings highlight the response of the rice production system to external driving factors, both climate and socioeconomics, to target further research and provide important insights into how a rice cropping system is likely to adapt in a mid-high-latitude region in the future.\",\"collection-title\":\"8.414\",\"container-title\":\"Environmental Research Letters\",\"DOI\":\"10.1088/1748-9326/aafa55\",\"ISSN\":\"1748-9326\",\"issue\":\"2\",\"journalAbbreviation\":\"Environ. Res. Lett.\",\"language\":\"en-US\",\"note\":\"publisher: IOP Publishing\\nCitation Key: hu2019Environ.Res.Lett.\",\"page\":\"024014\",\"source\":\"Institute of Physics\",\"title\":\"Rice production and climate change in Northeast China: evidence of adaptation through land use shifts\",\"title-short\":\"Rice production and climate change in Northeast China\",\"volume\":\"14\",\"author\":[{\"family\":\"Hu\",\"given\":\"Yanan\"},{\"family\":\"Fan\",\"given\":\"Lingling\"},{\"family\":\"Liu\",\"given\":\"Zhenhuan\"},{\"family\":\"Yu\",\"given\":\"Qiangyi\"},{\"family\":\"Liang\",\"given\":\"Shefang\"},{\"family\":\"Chen\",\"given\":\"Shi\"},{\"family\":\"You\",\"given\":\"Liangzhi\"},{\"family\":\"Wu\",\"given\":\"Wenbin\"},{\"family\":\"Yang\",\"given\":\"Peng\"}],\"issued\":{\"date-parts\":[[\"2019\",2]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"}";
// 转化为JSON对象
JObject jObj=JObject.Parse(FieldCode.Replace("ADDIN ZOTERO_ITEM CSL_CITATION",""));
// 转zotero uris链接为zotero://select链接
jObj.SelectTokens("citationItems[*].uris[0]").Select(x=>$"zotero://select/library/items/{Path.GetFileName((string)x)}");
获取到的结果为:
zotero://select/library/items/WAJ2XKB5
zotero://select/library/items/FPWETRUL
View PDF - 动作信息 - Quicker (getquicker.net) 这是浏览器打开PDF的动作,把最后一步改一下即可。
我反复尝试,还没搞定,卡在了获取ItemKey
这是运行C#代码那一段,能不能帮忙改一下,我想获得
zhang et al., 2012|128882|WAJ2XKB5
Wang et al., 2010|5986|WABCXLM8
这样的输出
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.InteropServices;
// Quicker将会调用的函数
public static string Exec(string paramValue)
{
string code = "";
var Word = (Microsoft.Office.Interop.Word.Application)Marshal.GetActiveObject("Word.Application");
var doc = Word.ActiveDocument;
Range rng;
foreach (Field mfield in Word.Selection.Paragraphs[1].Range.Fields) {
rng = mfield.Result;
rng.SetRange(rng.Start - 2 - mfield.Code.Text.Length, rng.End + 2);
if (Word.Selection.Range.InRange(rng)) {
code=mfield.Code.Text;
break;
}
}
if (string.IsNullOrEmpty(code)) return "请选择文献引用!";
JObject json = JObject.Parse(code.Replace("ADDIN ZOTERO_ITEM CSL_CITATION ", ""));
var itemdata = json["citationItems"].Select(
x => new {
id = (string)x["id"],
// uris1 = string.Join(",", uris), // //uris1 需要导出类似“WAJ2XKB5”8位字符(ItemKey),这个地方应该怎么改啊?
// uris1 = GetFileName((string)x),
// uris1 = json.SelectTokens("citationItems[*].uris[0]"),
author = (string.IsNullOrEmpty((string)x["itemData"]["author"][0]["family"]) ? ((string)x["itemData"]["author"][0]["literal"]) : ((string)x["itemData"]["author"][0]["family"])) + " et al., " +
(string)x["itemData"]["issued"]["date-parts"][0][0]
}).ToList();
var result = itemdata.Select(x => x.author + "|" + x.id + "|" + x.uris1).ToList(); //uris1 需要导出类似“WAJ2XKB5”8位字符(ItemKey)
return string.Join( "\n", result); //数组转为字符串
}
zotero里面肯定有,但是在这个串里面有PDF文件的 Itemkey吗?
// FieldCode为获取到的域代码
string FieldCode="ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"3FIW7gOp\",\"properties\":{\"formattedCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"plainCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"noteIndex\":0},\"citationItems\":[{\"id\":1558,\"uris\":[\"http://zotero.org/users/1817658/items/WAJ2XKB5\"],\"itemData\":{\"id\":1558,\"type\":\"article-journal\",\"collection-title\":\"7.116\",\"container-title\":\"Biology and Fertility of Soils\",\"DOI\":\"10.1007/s00374-018-01338-3\",\"issue\":\"2\",\"language\":\"en-US\",\"note\":\"ISBN: 1432-0789\\npublisher: Springer\\nCitation Key: fungo2019Biol.Fertil.Soils\",\"page\":\"135-148\",\"title\":\"Ammonia and nitrous oxide emissions from a field Ultisol amended with tithonia green manure, urea, and biochar\",\"volume\":\"55\",\"author\":[{\"family\":\"Fungo\",\"given\":\"Bernard\"},{\"family\":\"Lehmann\",\"given\":\"Johannes\"},{\"family\":\"Kalbitz\",\"given\":\"Karsten\"},{\"family\":\"Thionģo\",\"given\":\"Margaret\"},{\"family\":\"Tenywa\",\"given\":\"Moses\"},{\"family\":\"Okeyo\",\"given\":\"Irene\"},{\"family\":\"Neufeldt\",\"given\":\"Henry\"}],\"issued\":{\"date-parts\":[[\"2019\"]]}}},{\"id\":1514,\"uris\":[\"http://zotero.org/users/1817658/items/FPWETRUL\"],\"itemData\":{\"id\":1514,\"type\":\"article-journal\",\"abstract\":\"Climate change continues to have a great impact on rice production in China, especially in Northeast China (NEC). Historical climate observations from the China Meteorological Administration and statistical agricultural records at the county level were utilized to evaluate the spatial and temporal effects of both climatic and socioeconomic factors on rice production between 1980 and 2010 in NEC by using a linear regression model. The results showed that a 1% increase in the rice accumulated temperature (RAT) significantly increases rice production by approximately 0.728%. Rising RAT over the past three decades increased rice production by 4.44% (equal to a relative contribution of 0.87% to production growth) in NEC, while the majority of rice production growth (79.6%) resulted from increased agricultural inputs. Furthermore, rice production has increased significantly since 2000, and its geographic centroid shifted over 320 km northeastward during the past 30 years. Historical statistical and simulated rice production data for each county were used to quantify the spatial relocation of rice production due to single climatic factors. During 1980–2010, temperature had a significant and coherent influence on moving rice production. The impact of growing season precipitation was not significant, while sunshine had a significant but less spatially coherent influence. Our findings highlight the response of the rice production system to external driving factors, both climate and socioeconomics, to target further research and provide important insights into how a rice cropping system is likely to adapt in a mid-high-latitude region in the future.\",\"collection-title\":\"8.414\",\"container-title\":\"Environmental Research Letters\",\"DOI\":\"10.1088/1748-9326/aafa55\",\"ISSN\":\"1748-9326\",\"issue\":\"2\",\"journalAbbreviation\":\"Environ. Res. Lett.\",\"language\":\"en-US\",\"note\":\"publisher: IOP Publishing\\nCitation Key: hu2019Environ.Res.Lett.\",\"page\":\"024014\",\"source\":\"Institute of Physics\",\"title\":\"Rice production and climate change in Northeast China: evidence of adaptation through land use shifts\",\"title-short\":\"Rice production and climate change in Northeast China\",\"volume\":\"14\",\"author\":[{\"family\":\"Hu\",\"given\":\"Yanan\"},{\"family\":\"Fan\",\"given\":\"Lingling\"},{\"family\":\"Liu\",\"given\":\"Zhenhuan\"},{\"family\":\"Yu\",\"given\":\"Qiangyi\"},{\"family\":\"Liang\",\"given\":\"Shefang\"},{\"family\":\"Chen\",\"given\":\"Shi\"},{\"family\":\"You\",\"given\":\"Liangzhi\"},{\"family\":\"Wu\",\"given\":\"Wenbin\"},{\"family\":\"Yang\",\"given\":\"Peng\"}],\"issued\":{\"date-parts\":[[\"2019\",2]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"}";
好吧
目前打开PDF的顺序是 word->zotero->zotero 内置的阅读器或者外置的PDF阅读器,这个流程需要依赖zotero,并且对使用第三方PDF阅读器的用户不太友好
为了减少依赖性,我想到另外一个方法 word->外置的PDF阅读器,具体如下:
1. Word域代码中读取PDF文件所在文件夹(即8位随机Itemkey)
2. quicker遍历 目录 storage\8位随机Itemkey 文件夹下的PDF文件(应该只有一个),并打开这个PDF文件
前两天根据你的指导,完成了一部分,但是对Word中域代码这一块不太了解,目前只会获得zotero父条目的ItemKey,没有子PDF的ItemKey,所以“word->外置的PDF阅读器”这个流程暂时无法实现
PS。过于深究这些可能意义不大,仅仅是学习、优化
根据大家的要求,刚刚开发一个WPS版zotero插件,实现了word版本的全部功能https://getquicker.net/Sharedaction?code=e90100f6-7713-4241-ba6e-08db0423d7d9
若了解python的话,里面有很详细的代码。欢迎交流。