Add arXiv identifier support (#1486)
This commit is contained in:
parent
8beda5eed4
commit
fa0576a4dd
|
@ -2624,6 +2624,12 @@ Zotero.Translate.Search.prototype.setIdentifier = function (identifier) {
|
||||||
contextObject: "rft_id=info:pmid/" + identifier.PMID
|
contextObject: "rft_id=info:pmid/" + identifier.PMID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else if (identifier.arXiv) {
|
||||||
|
search = {
|
||||||
|
itemType: "journalArticle",
|
||||||
|
arXiv: identifier.arXiv
|
||||||
|
};
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error("Unrecognized identifier");
|
throw new Error("Unrecognized identifier");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// Finally try for PMID
|
||||||
if (!identifiers.length) {
|
if (!identifiers.length) {
|
||||||
// PMID; right now, the longest PMIDs are 8 digits, so it doesn't seem like we'll
|
// PMID; right now, the longest PMIDs are 8 digits, so it doesn't seem like we'll
|
||||||
|
|
|
@ -153,5 +153,18 @@ describe("Zotero.Utilities.Internal", function () {
|
||||||
assert.lengthOf(Object.keys(identifiers[0]), 1);
|
assert.lengthOf(Object.keys(identifiers[0]), 1);
|
||||||
assert.propertyVal(identifiers[0], "PMID", id);
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user