forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AMS MathSciNet (Legacy).js
313 lines (293 loc) · 8.53 KB
/
AMS MathSciNet (Legacy).js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
{
"translatorID": "a354331-981b-43de-a61-bc26dd1be3a9",
"label": "AMS MathSciNet (Legacy)",
"creator": "Simon Kornblith, Sebastian Karcher",
"target": "^https?://(mathscinet\\.)?ams\\.[^/]*/(mathscinet/2006/)?mathscinet(\\-getitem\\?|/search/(publications\\.html|publdoc\\.html))",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-07-06 17:03:34"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2015-2023 Simon Kornblith & Sebastian Karcher
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, _url) {
var itemType;
if (getSearchResults(doc, true)) {
return "multiple";
}
else if (ZU.xpathText(doc, '//div[@class="headlineMenu"]/*[last()-1]')) {
itemType = ZU.xpathText(doc, '//div[@class="headlineMenu"]/*[last()-1]');
switch (itemType.trim().toLowerCase()) {
case 'article':
return "journalArticle";
case 'book':
return "book";
case 'chapter':
return "bookSection";
}
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[@class="headlineText"]');
for (var i = 0; i < rows.length; i++) {
var href = ZU.xpathText(rows[i], './a[@class="mrnum"]/@href');
var title = ZU.xpathText(rows[i], './span[@class="title"]');
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) == 'multiple') {
let items = await Zotero.selectItems(getSearchResults(doc, false));
if (!items) return;
for (let url of Object.keys(items)) {
await scrape(await requestDocument(url));
}
}
else {
await scrape(doc, url);
}
}
async function scrape(doc, url = doc.location.href) {
var host = url.match(/^(.+)\/mathscinet/);
var pub = host[0] + "/search/publications.html?fmt=bibtex";
var MR = ZU.xpathText(doc, '//div[@id="content"]/div[@class="doc"]/div[@class="headline"]/strong[1]');
pub += "&pg1=MR&s1=" + MR.replace(/^MR0*/, "");
let text = await requestText(pub);
var preRE = /<pre>\s*([\s\S]*?)\s*<\/pre>/g;
var bibTeXString = "";
var m;
//eslint-disable-next-line no-cond-assign
while (m = preRE.exec(text)) {
bibTeXString += m[1] + '\n';
}
// import using BibTeX
let translator = Zotero.loadTranslator("import");
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
translator.setString(bibTeXString);
translator.setHandler("itemDone", function (obj, item) {
// Fix/fetch MR number
var mrnumber;
if (item.extra) {
item.extra = item.extra.replace(/^MR:\s*(?:MR)?(\d+).*/gm,
function (m, mr) {
mrnumber = mr;
return 'MR: ' + mr;
});
}
if (mrnumber) {
url = 'https://mathscinet.ams.org/mathscinet-getitem?mr=' + mrnumber;
}
item.attachments.push({ title: "MathSciNet Snapshot", document: doc });
item.url = url;
item.complete();
});
await translator.translate();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet/search/publications.html?pg4=AUCN&s4=Karcher&co4=AND&pg5=TI&s5=&co5=AND&pg6=PC&s6=&co6=AND&pg7=ALLF&s7=&co7=AND&Submit=Search&dr=all&yrop=eq&arg3=&yearRangeFirst=&yearRangeSecond=&pg8=ET&s8=All&review_format=html",
"items": "multiple"
},
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet/2006/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&pg4=MR&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&r=1&review_format=html&s4=3004573",
"items": [
{
"itemType": "journalArticle",
"title": "Extrapolation of stable random fields",
"creators": [
{
"firstName": "Wolfgang",
"lastName": "Karcher",
"creatorType": "author"
},
{
"firstName": "Elena",
"lastName": "Shmileva",
"creatorType": "author"
},
{
"firstName": "Evgeny",
"lastName": "Spodarev",
"creatorType": "author"
}
],
"date": "2013",
"DOI": "10.1016/j.jmva.2012.11.004",
"ISSN": "0047-259X",
"extra": "MR: 3004573",
"itemID": "MR3004573",
"journalAbbreviation": "J. Multivariate Anal.",
"libraryCatalog": "AMS MathSciNet (Legacy)",
"pages": "516–536",
"publicationTitle": "Journal of Multivariate Analysis",
"url": "https://mathscinet.ams.org/mathscinet-getitem?mr=3004573",
"volume": "115",
"attachments": [
{
"title": "MathSciNet Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet/search/publications.html?pg1=ISSI&s1=308850",
"items": "multiple"
},
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet/2006/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&pg4=MR&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&r=1&review_format=html&s4=2767535",
"items": [
{
"itemType": "bookSection",
"title": "On implementation of the Markov chain Monte Carlo stochastic approximation algorithm",
"creators": [
{
"firstName": "Yihua",
"lastName": "Jiang",
"creatorType": "author"
},
{
"firstName": "Peter",
"lastName": "Karcher",
"creatorType": "author"
},
{
"firstName": "Yuedong",
"lastName": "Wang",
"creatorType": "author"
}
],
"date": "2011",
"bookTitle": "Advances in directional and linear statistics",
"extra": "MR: 2767535\nDOI: 10.1007/978-3-7908-2628-9_7",
"itemID": "MR2767535",
"libraryCatalog": "AMS MathSciNet (Legacy)",
"pages": "97–111",
"publisher": "Physica-Verlag/Springer, Heidelberg",
"url": "https://mathscinet.ams.org/mathscinet-getitem?mr=2767535",
"attachments": [
{
"title": "MathSciNet Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet/2006/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&pg4=MR&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&r=1&review_format=html&s4=2663710",
"items": [
{
"itemType": "book",
"title": "Advances in directional and linear statistics",
"creators": [
{
"firstName": "Martin T.",
"lastName": "Wells",
"creatorType": "editor"
},
{
"firstName": "Ashis",
"lastName": "SenGupta",
"creatorType": "editor"
}
],
"date": "2011",
"ISBN": "9783790826272",
"extra": "MR: 2663710\nDOI: 10.1007/978-3-7908-2628-9",
"itemID": "MR2663710",
"libraryCatalog": "AMS MathSciNet (Legacy)",
"numPages": "xiv+321",
"publisher": "Physica-Verlag/Springer, Heidelberg",
"url": "https://mathscinet.ams.org/mathscinet-getitem?mr=2663710",
"attachments": [
{
"title": "MathSciNet Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [
{
"note": "<p>A Festschrift for Sreenivasa Rao Jammalamadaka</p>"
}
],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://mathscinet.ams.org/mathscinet-getitem?mr=1346201",
"items": [
{
"itemType": "journalArticle",
"title": "Sommation des séries divergentes",
"creators": [
{
"firstName": "Bernard",
"lastName": "Malgrange",
"creatorType": "author"
}
],
"date": "1995",
"ISSN": "0723-0869",
"extra": "MR: 1346201",
"issue": "2-3",
"itemID": "MR1346201",
"journalAbbreviation": "Exposition. Math.",
"libraryCatalog": "AMS MathSciNet",
"pages": "163–222",
"publicationTitle": "Expositiones Mathematicae. International Journal",
"url": "https://mathscinet.ams.org/mathscinet-getitem?mr=1346201",
"volume": "13",
"attachments": [
{
"title": "MathSciNet Snapshot"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/