-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathNational Diet Library Catalogue.js
333 lines (311 loc) · 8.85 KB
/
National Diet Library Catalogue.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
{
"translatorID": "5978580d-c58c-46c8-9755-9481a3e20f3f",
"label": "National Diet Library Catalogue",
"creator": "Philipp Zumstein",
"target": "^https?://iss\\.ndl\\.go\\.jp/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2015-08-15 16:07:22"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2015 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) {
if (url.indexOf('/books/')>-1) {
var type = ZU.xpathText(doc, '//div[@id="thumbnail"]');
return getItemType(type);
} else if (url.indexOf('books?')>-1 && getSearchResults(doc, true)) {
return "multiple";
}
}
function getItemType(type) {
//http://www.ndl.go.jp/jp/aboutus/standards/meta/2011/12/ndl-type.rdf
if (type) {
switch (type.trim()) {
case "録音図書": //Audio Book
case "録音図書(CD・DVD)": //Audio Book In Sound Disc
case "録音図書(カセットテープ)": //Audio Book In Sound Tape
case "カセットテープ": //Cassette Tape
case "CD": //CD
case "視覚障害者向け資料": //Materials For Visually Handicapped People
case "音楽": //Music
case "レコード": //Record
case "音声再生用ディスク": //Sound Disc
case "音声再生用テープ": //Sound Tape
return "audioRecording";
break;
case "雑誌記事": //Article
case "記事・論文":
return "journalArticle";
break;
case "人工物": //Artifact
case "博物資料": //Museum Material
case "自然物": //Naturally Occurring Object
case "絵画": //Painting
case "写真": //Photograph
case "絵葉書": //Picture Postcard
case "ポスター": //Poster
return "artwork";
break;
case "CD-ROM": //CD-ROM
case "コンピュータディスク": //Computer Disc
case "コンピュータ・プログラム": //Computer Program
case "フォント": //Font
case "ゲーム": //Game
case "磁気ディスク": //Magnetic Disk
return "computerProgram";
break;
case "文書データ": //Document
case "手稿および書写資料": //Manuscript
return "manuscript";
break;
case "地図": //Map
return "map";
break;
case "スライド": //Slide
return "presentation";
break;
case "書誌データ": //Bibliographic Data
case "カード式資料": //Card Form
case "政府刊行物": //Government Publication
case "地方公共団体刊行物": //Local Publication
case "官公庁刊行物": //National Publication
case "国立国会図書館刊行物": //NDL Publication
case "数値データ": //Numeric Data
case "テクニカルリポート": //Technical Report
return "report";
break;
case "立法情報": //Legislative Information
case "レーザーディスク" : //LD
return "statute";
break;
case "博士論文": //Doctoral Dissertation
return "thesis";
break;
case "ブルーレイディスク": //Blu-ray Disc
case "DVD": //DVD
case "ビデオカセット": //Video Cassette
case "ビデオディスク": //Video Disc
return "videoRecording";
break;
case "パッケージ系電子資料": //Electronic Resource
case "オンライン資料": //Online Resource
case "オンラインジャーナル": //Online Journal
return "webpage";
break;
default:
return "book";
}
} else {
return "book";
}
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//li[contains(@class, "item_result")]//h3/a');
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 = 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://iss.ndl.go.jp/books/R100000039-I001424605-00?locale=en&ar=4e1f
// urlJSON = http://iss.ndl.go.jp/books/R100000039-I001424605-00.json
var m = url.match(/\/books\/([A-Z\d\-]+)/);
var urlJSON = m[0] + ".json";
ZU.doGet(urlJSON, function(text) {
var json = JSON.parse(text);
//Z.debug(json);
var type = getItemType( json.materialType[0] );
var newItem = new Zotero.Item(type);
newItem.title = json.title[0].value;
if (json.issued) {
newItem.date = json.issued[0];
}
if (json.publisher) {
newItem.publisher = json.publisher[0].name;
newItem.place = json.publisher[0].location;
}
if (json.extent && /\d+/.test( json.extent[0] )) {
newItem.numPages = json.extent[0].match(/\d+/)[0];
}
if (json.publicationName) {
newItem.publicationTitle = json.publicationName.value;
newItem.volume = json.publicationName.number;
newItem.pages = json.publicationName.pageRange;
}
//language is not in the json output
var lang = ZU.xpathText(doc, '//tr[ th[contains(text(), "ISO639-2")] ]/td');
if (lang) {
newItem.language = lang.replace(/[^a-z]/g, "");
}
if (json.identifier && json.identifier.DOI) {
newItem.DOI = json.identifier.DOI;
}
var creatorList = json.creator || json.dc_creator;
if (creatorList) {
for (var i=0; i<creatorList.length; i++) {
var name = creatorList[i].name.replace(/,\s*\d{4}-\d{4}\s*$/, "");
newItem.creators.push( ZU.cleanAuthor(name, "author") );
}
}
if (json.subject && json.subject.value) {
var tagList = json.subject.value;
for (var i=0; i<tagList.length; i++) {
newItem.tags.push( tagList[i] );
}
}
newItem.attachments.push({
title: "NDL Catalogue",
url: json.link,
mimeType: "text/html",
snapshot: false
});
newItem.complete();
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://iss.ndl.go.jp/books/R000000004-I023161505-00",
"items": [
{
"itemType": "journalArticle",
"title": "21年度社会保障給付費 過去最高の99.9兆円 : 国民所得割合は29.4%に上昇",
"creators": [],
"date": "2011-11-00",
"language": "jpn",
"libraryCatalog": "National Diet Library Catalogue",
"pages": "25-27",
"publicationTitle": "健保ニュース",
"shortTitle": "21年度社会保障給付費 過去最高の99.9兆円",
"volume": "1950",
"attachments": [
{
"title": "NDL Catalogue",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://iss.ndl.go.jp/books/R100000039-I001424605-00?locale=en&ar=4e1f",
"items": [
{
"itemType": "book",
"title": "栄養之合理化",
"creators": [
{
"firstName": "佐伯",
"lastName": "矩",
"creatorType": "author"
},
{
"firstName": "佐伯矩",
"lastName": "[述",
"creatorType": "author"
}
],
"date": "1930",
"language": "jpn",
"libraryCatalog": "National Diet Library Catalogue",
"numPages": "26",
"place": "名古屋",
"publisher": "愛知標準精米普及期成会",
"attachments": [
{
"title": "NDL Catalogue",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://iss.ndl.go.jp/books/R100000002-I000006426972-00",
"items": [
{
"itemType": "book",
"title": "Die Bildungsfrage als sociales Problem. Von Prof. Dr. Mannheimer ..",
"creators": [
{
"firstName": "Mannheimer",
"lastName": "Adolf",
"creatorType": "author"
}
],
"date": "1901",
"language": "ger",
"libraryCatalog": "National Diet Library Catalogue",
"numPages": "156",
"place": "Jena",
"publisher": "G. Fischer",
"attachments": [
{
"title": "NDL Catalogue",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [
"Education",
"University extension"
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/