-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathDAI-Zenon.js
392 lines (368 loc) · 10.4 KB
/
DAI-Zenon.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
{
"translatorID": "16199bf0-a365-4aad-baeb-225019ae32dc",
"label": "DAI-Zenon",
"creator": "Philipp Zumstein, Sebastian Karcher",
"target": "^https?://zenon\\.dainst\\.org/(Record/|Search/)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2020-10-13 15:24:32"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2014-2020 Philipp Zumstein and 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) {
// return "bookSection"; // activate for testing
// return "journalArticle"; // activate for testing
if (url.includes("/Record")) { // book, journalArticle or bookSection --> will be improved during scraping
return "book";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[contains(@class, "row")]//a[contains(@class, "title")]');
for (let i = 0; i < rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
}
else {
scrape(doc, url);
}
}
function scrape(doc, url) {
// e.g. url = "http://zenon.dainst.org/Record/000300287"
// remove anchor so this doesn't break https://zenon.dainst.org/Record/001275808#usercomments
var urlParts = url.replace(/#.*/, "").split("/");
var id = urlParts[urlParts.length - 1];
// call MARC translator
ZU.doGet('/Record/' + id + '/Details', function (text) {
var parser = new DOMParser();
var xml = parser.parseFromString(text, "text/html");
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
translator.getTranslatorObject(function (marc) {
var details = ZU.xpath(xml, '//tr');
var record = new marc.record();
var newItem = new Zotero.Item();
for (let i = 0; i < details.length; i++) {
var fieldTag = ZU.xpathText(details[i], './th');
// skip empty lines
if (!fieldTag) continue;
var values = ZU.xpath(details[i], './td');
if (values.length == 1) {
if (fieldTag == "LEADER") {
record.leader = ZU.xpathText(details[i], './td');
}
// the control fields are not anyhow used in MARC translator, thus we do not import them
}
if (values.length == 3) {
var ind1 = ZU.xpathText(details[i], './td[1]');
var ind2 = ZU.xpathText(details[i], './td[2]');
var fieldContent = ZU.xpathText(details[i], './td[3]', null, '').replace(/[\r\n\s]*\|/g, marc.subfieldDelimiter);
record.addField(fieldTag, ind1 + ind2, fieldContent);
}
}
record.translate(newItem);
// import tags from the 999 fields and filter out dublicate tags
// leaving this here in case it ever comes back, but doesn't exist as of October 2020
record._associateTags(newItem, 999, "a");
newItem.tags = newItem.tags.filter(function (item, index, inputArray) {
return inputArray.indexOf(item) == index;
});
// get container title from 773
record._associateDBField(newItem, 773, "t", "bookTitle");
// This used to be in 995 - not seeing this anymore in October 202 but
// leaving to make sure it doesn't break.
if (!newItem.bookTitle) {
record._associateDBField(newItem, 995, "n", "bookTitle");
}
if (newItem.bookTitle) {
if (record.leader.substr(6, 2) == "as") { // This seems to work good, but I don't know if is always working.
newItem.itemType = "journalArticle";
var regularExpression1 = /^(.*),\s?(\d+),\s?(\d+)\s?\(\d\d\d\d\)/; // e.g. Bulletin du Cercle d'Études Numismatiques, 44,2 (2007)
var regularExpression2 = /^(.*),\s?(\d+)\s?\(\d\d\d\d\)/; // e.g Mannheimer Geschichtsblätter, Neue Folge, 16 (2008)
var m;
if ((m = newItem.bookTitle.match(regularExpression1))) {
newItem.publicationTitle = m[1];
newItem.volume = m[2];
newItem.issue = m[3];
}
else if ((m = newItem.bookTitle.match(regularExpression2))) {
newItem.publicationTitle = m[1];
newItem.volume = m[2];
}
}
else {
newItem.itemType = "bookSection";
}
record._associateDBField(newItem, 300, "a", "pages");
delete newItem.numPages;
}
newItem.attachments.push({
url: url,
title: "DAI Zenon Entry",
mimeType: 'text/html',
snapshot: false
});
newItem.complete();
});
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://zenon.dainst.org/Record/000269027",
"items": [
{
"itemType": "book",
"title": "Die Aufnahme fremder Kultureinflüsse in Etrurien und das Problem des Retardierens in der etruskischen Kunst: Referate vom Symposion des Deutschen Archäologen-Verbandes: Mannheim 8.-10.2. 1980",
"creators": [
{
"lastName": "Deutscher Archäologen-Verband",
"creatorType": "editor",
"fieldMode": true
},
{
"lastName": "Universität Mannheim",
"creatorType": "editor",
"fieldMode": true
}
],
"date": "1981",
"callNumber": "DG223 .A8 1981",
"libraryCatalog": "DAI-Zenon",
"numPages": "197",
"place": "Mannheim",
"publisher": "Deutscher Archäologen-Verband",
"series": "Schriften des Deutschen Archäologen-Verbandes",
"seriesNumber": "5",
"shortTitle": "Die Aufnahme fremder Kultureinflüsse in Etrurien und das Problem des Retardierens in der etruskischen Kunst",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
{
"tag": "Etrusker"
},
{
"tag": "Kongreßschrift"
},
{
"tag": "Mannheim 1980"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://zenon.dainst.org/Record/000300287",
"items": [
{
"itemType": "bookSection",
"title": "Kulturbeziehungen zwischen dem eisenzeitlichen Etrurien und dem Ostalpenraum",
"creators": [
{
"firstName": "Luciana",
"lastName": "Aigner-Foresti",
"creatorType": "author"
}
],
"bookTitle": "Die Aufnahme fremder Kultureinflüsse in Etrurien und das Problem des Retardierens in der etruskischen Kunst, Mannheim 8.-10.2.1980",
"libraryCatalog": "DAI-Zenon",
"pages": "46-52, Abb",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
{
"tag": "Alpenländer (bis 1997)"
},
{
"tag": "Beziehungen"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://zenon.dainst.org/Record/001286369",
"items": [
{
"itemType": "journalArticle",
"title": "Zwischen Diesseits und Jenseits, fünf etruskische Urnen aus den Sammlungen der rem als Zeugen einer untergeganenen Kultur",
"creators": [
{
"firstName": "Alexandra",
"lastName": "Berend",
"creatorType": "author"
}
],
"date": "2008",
"libraryCatalog": "DAI-Zenon",
"pages": "100-107",
"publicationTitle": "Mannheimer Geschichtsblätter, Neue Folge",
"volume": "16",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
"Etrusker",
"Ikonographie",
"Impasto-Keramik",
"Mannheim, Reiss-Engelhorn-Museum",
"Urnenbestattungen",
"Villanova"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://zenon.dainst.org/Record/001279328",
"items": [
{
"itemType": "journalArticle",
"title": "Un bronze d'Elaia (Eolide) aux noms de Caius et Lucius César",
"creators": [
{
"firstName": "Jean-Marc",
"lastName": "Doyen",
"creatorType": "author"
}
],
"date": "2007",
"issue": "2",
"libraryCatalog": "DAI-Zenon",
"pages": "329-330",
"publicationTitle": "Bulletin du Cercle d'Études Numismatiques",
"volume": "44",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
"Caesar, Gaius Iulius <20 v. Chr.-4>",
"Caesar, Lucius Iulius",
"Elaia",
"Römische Münzen"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://zenon.dainst.org/Record/000251127",
"items": [
{
"itemType": "book",
"title": "Das Bild des Augustus auf den frühen Reichsprägungen: Studien zur Vergöttlichung des ersten Prinzeps",
"creators": [
{
"firstName": "Rainer",
"lastName": "Albert",
"creatorType": "author"
}
],
"date": "1981",
"language": "ger",
"libraryCatalog": "DAI-Zenon",
"numPages": "248",
"place": "Speyer",
"publisher": "Numismatische Gesellschaft",
"series": "Schriftenreihe der Numismatischen Gesellschaft Speyer",
"seriesNumber": "21",
"shortTitle": "Das Bild des Augustus auf den frühen Reichsprägungen",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
{
"tag": "Augustus"
},
{
"tag": "Herrscherkult"
},
{
"tag": "Münzen als Zeugnis"
}
],
"notes": [
{
"note": "Thesis (doctoral)--Universität Mannheim, 1980"
}
],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/