-
Notifications
You must be signed in to change notification settings - Fork 1
/
DAI-Zenon.js
411 lines (384 loc) · 11.7 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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{
"translatorID": "16199bf0-a365-4aad-baeb-225019ae32dc",
"label": "DAI-Zenon",
"creator": "Philipp Zumstein",
"target": "https?://zenon\\.dainst\\.org/(Record/|Search/)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsv",
"lastUpdated": "2016-10-21 18:52:26"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2014 Philipp Zumstein
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.indexOf("/Record") != -1 ) {//book, journalArticle or bookSection --> will be improved during scraping
return "book";
} else if (getSearchResults(doc, true)) {
return "multiple";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[contains(@class, "row")]//a[contains(@class, "title")]');
for (var 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 true;
}
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"
var urlParts = url.split("/");
var id = urlParts[urlParts.length-1];
//call MARC translator
ZU.doPost('http://zenon.dainst.org/Record/' + id + '/AjaxTab', 'tab=details', function(text) {
var parser = new DOMParser();
var xml = parser.parseFromString(text, "text/xml");
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 (var 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
record._associateTags(newItem, 999, "a");
newItem.tags = newItem.tags.filter( function( item, index, inputArray ) {
return inputArray.indexOf(item) == index;
});
//there is a special field 995 if the entry is a bookSection or journalArticle
record._associateDBField(newItem, 995, "n", "bookTitle");
if (newItem.bookTitle) {
//Z.debug(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": "http://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
},
{
"lastName": "Archäologisches Seminar der Universität Mannheim",
"creatorType": "editor",
"fieldMode": true
},
{
"lastName": "Deutscher Archäologen-Verband",
"creatorType": "editor",
"fieldMode": true
},
{
"lastName": "Deutscher Archäologen-Verband",
"creatorType": "editor",
"fieldMode": true
}
],
"date": "1981",
"callNumber": "DG223 .A8 1981",
"libraryCatalog": "DAI-Zenon",
"numPages": "197",
"place": "Mannheim",
"publisher": "Vorstand : Das Seminar",
"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": [
"Etrusker",
"Kongresse und Tagungen M",
"Kongreßschrift",
"Mannheim 1980"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://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": [
"Alpenländer (bis 1997)",
"Beziehungen",
"Culture in contatto. Etruschi, liguri, romani nella Valle del Serchio fra IV e II secolo a.C"
],
"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": "http://zenon.dainst.org/Record/000251127",
"items": [
{
"itemType": "book",
"title": "Das Bild des Augustus auf 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 frühen Reichsprägungen",
"attachments": [
{
"title": "DAI Zenon Entry",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
"Die kultische Verehrung des römischen Herrschers",
"Diva Faustina : coinage and cult in Rome and the provinces",
"Divine kings and sacred spaces : power and religion in Hellenistic Syria (301-64 BC)",
"Du prêtre du roi au prêtre de Rome et au grand prêtre d’Auguste : lamise en place du culte impérial civique",
"Ein Miniaturaltar der Arsinoë II",
"Emperor Worship",
"Herrscher",
"Herrscher- und Dynastiekulte im Ptolemäerreich",
"Herrscherkult",
"Imperial Cult",
"Imperial cult and imperial representation in Roman Cyprus",
"Kaiserverehrung und Kaiserkult in Alexandria und Ägypten von Augustus bis Caracalla",
"Les cultes des souverains hellénistiques",
"Les cultes des souverains hellénistiques après la disparition des dynasties : formes de survie et d’extinction d’une institution dans un contexte civique",
"Münzen als Zeugnis",
"Prêtres des empereurs",
"The Emperor Cult",
"The Near Eastern origins of Hellenistic ruler cult",
"The imperial Cult",
"Theoi sebastoi",
"Un culto imperiale \"provinciale\" in Achaia",
"benannte Porträts",
"culte impérial civique",
"domus divina",
"il culto degli imperatori romani",
"il culto degli imperatori romani in Grecia (Provincia Achaia) nel secondo secolo D.C",
"sul culto imperiale",
"the Cult of Ptolemaic Queens",
"the Roman imperial cult"
],
"notes": [
{
"note": "Thesis (doctoral)--Universität Mannheim, 1980"
}
],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/