commit fa0576a4dd04cbe795c626c2ed55fb1105ba9caf
parent 8beda5eed401430fa711e865a2a100df6f6317fb
Author: Martynas Bagdonas <martbgd@gmail.com>
Date: Wed, 18 Apr 2018 20:03:10 +0300
Add arXiv identifier support (#1486)
Diffstat:
3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -2624,6 +2624,12 @@ Zotero.Translate.Search.prototype.setIdentifier = function (identifier) {
contextObject: "rft_id=info:pmid/" + identifier.PMID
};
}
+ else if (identifier.arXiv) {
+ search = {
+ itemType: "journalArticle",
+ arXiv: identifier.arXiv
+ };
+ }
else {
throw new Error("Unrecognized identifier");
}
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -896,6 +896,22 @@ Zotero.Utilities.Internal = {
}
}
+ // Next try arXiv
+ if (!identifiers.length) {
+ // arXiv identifiers are extracted without version number
+ // i.e. 0706.0044v1 is extracted as 0706.0044,
+ // because arXiv OAI API doesn't allow to access individual versions
+ let arXiv_RE = /((?:[^A-Za-z]|^)([\-A-Za-z\.]+\/\d{7})(?:(v[0-9]+)|)(?!\d))|((?:\D|^)(\d{4}.\d{4,5})(?:(v[0-9]+)|)(?!\d))/g;
+ let m;
+ while ((m = arXiv_RE.exec(text))) {
+ let arXiv = m[2] || m[5];
+ if (arXiv && !foundIDs.has(arXiv)) {
+ identifiers.push({arXiv: arXiv});
+ foundIDs.add(arXiv);
+ }
+ }
+ }
+
// Finally try for PMID
if (!identifiers.length) {
// PMID; right now, the longest PMIDs are 8 digits, so it doesn't seem like we'll
diff --git a/test/tests/utilities_internalTest.js b/test/tests/utilities_internalTest.js
@@ -153,5 +153,18 @@ describe("Zotero.Utilities.Internal", function () {
assert.lengthOf(Object.keys(identifiers[0]), 1);
assert.propertyVal(identifiers[0], "PMID", id);
});
+
+ it("should extract multiple old and new style arXivs", async function () {
+ var identifiers = ZUI.extractIdentifiers("0706.0044 arXiv:0706.00441v1,hep-ex/9809001v1, math.GT/0309135.");
+ assert.lengthOf(identifiers, 4);
+ assert.lengthOf(Object.keys(identifiers[0]), 1);
+ assert.lengthOf(Object.keys(identifiers[1]), 1);
+ assert.lengthOf(Object.keys(identifiers[2]), 1);
+ assert.lengthOf(Object.keys(identifiers[3]), 1);
+ assert.propertyVal(identifiers[0], "arXiv", "0706.0044");
+ assert.propertyVal(identifiers[1], "arXiv", "0706.00441");
+ assert.propertyVal(identifiers[2], "arXiv", "hep-ex/9809001");
+ assert.propertyVal(identifiers[3], "arXiv", "math.GT/0309135");
+ });
});
})