forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAI-Zenon.js
415 lines (383 loc) · 11.3 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
412
413
414
415
{
"translatorID": "16199bf0-a365-4aad-baeb-225019ae32dc",
"label": "DAI-Zenon",
"creator": "Philipp Zumstein",
"target": "https?://zenon\\.dainst\\.org/#(book|search|extendedSearch|bibliography|favorites)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsv",
"lastUpdated": "2014-09-07 13:07:37"
}
/*
***** 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("/#book") != -1 ) {//book, journalArticle or bookSection --> will be improved during scraping
return "book";
} else if (getSearchResults(doc).length>0) {
return "multiple";
}
}
function getSearchResults(doc) {
return ZU.xpath(doc, '//tr[contains(@class, "search-result")]/td/h5|//div[@id="user-favorites-listing"]//tr/td/a');
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var items = {};
var titles = getSearchResults(doc);
for (var i=0; i<titles.length; i++) {
var href;
var id = titles[i].parentNode.parentNode.id;
if (id != null) {
href = "/#book/"+encodeURIComponent(id);
} else {//favourites
href = titles[i].href;
}
var title = ZU.trimInternal(titles[i].textContent);
if (title != "") {
items[href] = title;
}
}
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
var articles = new Array();
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/#book/000300287"
var urlParts = url.split("/");
var id = urlParts[urlParts.length-1];
var jsonUrl = "http://zenon.dainst.org:8080/elwms-zenon/resource/" + encodeURIComponent(id) + "?format=marc21";
ZU.doGet(jsonUrl, function(text) {
var json = JSON.parse( text );
var rootElement = "data";
var fields = json[rootElement]["marc:datafield"];
//Z.debug(fields);
//call MARC translator
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
translator.getTranslatorObject(function (marc) {
var record = new marc.record();
var newItem = new Zotero.Item();
record.leader = json[rootElement]["marc:leader"];
//the control fields are not anyhow used in MARC translator, thus we do not import them
for (var j in fields) {
var fieldTag = fields[j]["@tag"];
var ind1 = fields[j]["@ind1"];
var ind2 = fields[j]["@ind2"];
//set fieldContent to an empty string (start value):
var fieldContent = "";
var subfields = fields[j]["marc:subfield"];
//force array always (also if there is only one subfield):
if ( Object.prototype.toString.call( subfields ) !== '[object Array]') {
subfields = [ subfields ];
}
for (var k in subfields) {
//Z.debug(subfields[0]);
var code = subfields[k]["@code"];
var subfieldContent = subfields[k]["#text"];
//concat all subfields in one datafield, with subfield delimiter and code between them
fieldContent = fieldContent + marc.subfieldDelimiter + code + subfieldContent;
}
//Z.debug(j + ";" +fieldTag + ";" + ind1 + ";" + ind2 + ";" + fieldContent);
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( json.data["marc: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/#book/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",
"fieldMode": true
},
{
"lastName": "Universität Mannheim",
"fieldMode": true
},
{
"lastName": "Archäologisches Seminar der Universität Mannheim",
"fieldMode": true
},
{
"lastName": "Deutscher Archäologen-Verband",
"fieldMode": true
},
{
"lastName": "Deutscher Archäologen-Verband",
"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/#book/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"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://zenon.dainst.org/#book/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/#search?q=mannheim",
"items": "multiple"
},
{
"type": "web",
"url": "http://zenon.dainst.org/#book/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/#book/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",
"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": [
"Divine kings and sacred spaces : power and religion in Hellenistic Syria (301-64 BC)",
"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",
"Münzen als Zeugnis",
"Prêtres des empereurs",
"The Emperor Cult",
"The imperial Cult",
"benannte Porträts",
"culte impérial civique",
"domus divina",
"sul culto imperiale",
"the Cult of Ptolemaic Queens",
"the Roman imperial cult"
],
"notes": [
{
"note": "Thesis (doctoral)--Universität Mannheim, 1980"
}
],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/