Skip to content

Commit c03f241

Browse files
committed
New translator for National Library of Belarus
1 parent 1300e7a commit c03f241

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

National Library of Belarus.js

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"translatorID": "89592f50-6ae8-491e-8988-969002012b1b",
3+
"label": "National Library of Belarus",
4+
"creator": "Philipp Zumstein",
5+
"target": "https?://www\\.nlb\\.by/portal/page/portal/index/resources/(basicsearch|expandedsearch|anothersearch|authoritet|newdoc|top100)",
6+
"minVersion": "3.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsibv",
12+
"lastUpdated": "2014-09-25 20:54:14"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
Copyright © 2014 Philipp Zumstein
19+
20+
This file is part of Zotero.
21+
22+
Zotero is free software: you can redistribute it and/or modify
23+
it under the terms of the GNU Affero General Public License as published by
24+
the Free Software Foundation, either version 3 of the License, or
25+
(at your option) any later version.
26+
27+
Zotero is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
GNU Affero General Public License for more details.
31+
32+
You should have received a copy of the GNU Affero General Public License
33+
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
34+
35+
***** END LICENSE BLOCK *****
36+
*/
37+
38+
39+
function detectWeb(doc, url) {
40+
if (url.indexOf('strutsAction=biblinfoaction.do') != -1 && getMarcNode(doc).length>0 ) {//single item
41+
return "book";
42+
} else if (getSearchResults(doc, true)) {
43+
return "multiple";
44+
}
45+
}
46+
47+
48+
//for testing in detectWeb use true for checkOnly
49+
//for the items in doWeb use false for checkOnly
50+
//then the items will be an object containing the href/title pairs
51+
function getSearchResults(doc, checkOnly) {
52+
var items = {};
53+
var found = false;
54+
var rows = ZU.xpath(doc, '//div[@id="search_result" or @id="expandedsearchView"]//td[contains(@class, "link")]//a' );
55+
for (var i=0; i<rows.length; i++) {
56+
var href = rows[i].href;
57+
var title = ZU.trimInternal(rows[i].textContent);
58+
if (!href || !title) continue;
59+
if (title != "") {
60+
if (checkOnly) return true;
61+
found = true;
62+
items[href] = title;
63+
}
64+
}
65+
return found ? items : false;
66+
}
67+
68+
function getMarcNode(doc) {//the node in the DOM contains the BELMARC data
69+
return ZU.xpath(doc, '//div[contains(@id, "belmarc")]//td[not(contains(@class, "fon_gray"))]/font[contains(@class, "tekst")]');
70+
}
71+
72+
function doWeb(doc, url) {
73+
if (detectWeb(doc, url) == "multiple") {
74+
75+
Zotero.selectItems(getSearchResults(doc, false), function (items) {
76+
if (!items) {
77+
return true;
78+
}
79+
var articles = new Array();
80+
for (var i in items) {
81+
articles.push(i);
82+
}
83+
ZU.processDocuments(articles, scrape);
84+
});
85+
} else {
86+
scrape(doc, url);
87+
}
88+
}
89+
90+
91+
function scrape(doc, url) {
92+
var children = getMarcNode(doc)[0].childNodes;
93+
var lines = [];
94+
for (var i=0; i<children.length; i++) {
95+
if (children[i].nodeType == 3) {//ignore <br> nodes, only textNodes
96+
var text = ZU.trimInternal(children[i].textContent) ;
97+
if (text.length>0) {
98+
lines.push(text);
99+
}
100+
}
101+
}
102+
//Z.debug(lines);
103+
104+
//call MARC translator
105+
var translator = Zotero.loadTranslator("import");
106+
107+
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
108+
translator.getTranslatorObject(function (marc) {
109+
110+
var record = new marc.record();
111+
var newItem = new Zotero.Item();
112+
record.leader = lines[0];
113+
for (var j=1; j<lines.length; j++) {
114+
var currentLine = lines[j];
115+
var fieldTag = currentLine.substr(0,3);
116+
var indicators;
117+
var fieldContent;
118+
if (fieldTag.substr(0,2) == "00") {
119+
indicators = "";
120+
fieldContent = currentLine.substr(4);
121+
} else {
122+
indicators = currentLine.substr(4,2);
123+
fieldContent = currentLine.substr(7).replace(/\$(\w)\s*/g, marc.subfieldDelimiter+"$1");
124+
}
125+
126+
record.addField( fieldTag, indicators, fieldContent);
127+
}
128+
129+
record.translate(newItem);
130+
131+
record._associateDBField(newItem, 899, "p", "callNumber");
132+
record._associateDBField(newItem, 215, "a", "numPages");//this field may contain more information about the extent of a book, therefore we do here on porpuse no more cleaning of the number only (has to be done manually)
133+
record._associateTags(newItem, 606, "a");
134+
135+
newItem.complete();
136+
});
137+
138+
139+
}/** BEGIN TEST CASES **/
140+
var testCases = [
141+
{
142+
"type": "web",
143+
"url": "http://www.nlb.by/portal/page/portal/index/resources/expandedsearch?classId=B33E739B22884D82AACAC24EBFB1DA89&submitR=empty&_piref73_180746_73_34794_34794.biId=386521&_piref73_180746_73_34794_34794.strutsAction=biblinfoaction.do&lang=en",
144+
"items": [
145+
{
146+
"itemType": "book",
147+
"title": "Vibrational states in deformed nuclei.Chaos,order and individual nature of nuclei",
148+
"creators": [
149+
{
150+
"firstName": "V. G. V. G.",
151+
"lastName": "Soloviev ",
152+
"creatorType": "author"
153+
}
154+
],
155+
"date": "1993",
156+
"callNumber": "1Ок25736(ДХ)",
157+
"language": "eng",
158+
"libraryCatalog": "National Library of Belarus",
159+
"numPages": "20p",
160+
"place": "Dubna",
161+
"series": "Prepr",
162+
"seriesNumber": "E4-93-223--",
163+
"attachments": [],
164+
"tags": [],
165+
"notes": [],
166+
"seeAlso": []
167+
}
168+
]
169+
}
170+
]
171+
/** END TEST CASES **/

0 commit comments

Comments
 (0)