forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DBLP Computer Science Bibliography.js
270 lines (227 loc) · 7.12 KB
/
DBLP Computer Science Bibliography.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
{
"translatorID": "625c6435-e235-4402-a48f-3095a9c1a09c",
"label": "DBLP Computer Science Bibliography",
"creator": "Adam Crymble",
"target": "^https?://(www\\.)?dblp\\.org",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcs",
"lastUpdated": "2012-01-30 22:51:13"
}
function detectWeb(doc, url) {
if (doc.title.match("journals")) {
return "journalArticle";
} else if (doc.title.match("conf")) {
return "conferencePaper";
} else if (doc.title.match("DBLP entry")) {
return "bookSection";
}
}
//DBLP Computer Science Database Translator. Code by Adam Crymble.
//Doesn't work for multiple entries. Site uses a different URL for the search and single entry. Multiple code attached as comment.
function associateData (newItem, dataTags, field, zoteroField) {
if (dataTags[field]) {
newItem[zoteroField] = dataTags[field];
}
}
function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
} : null;
var dataTags = new Object();
var mediaType = detectWeb(doc, url);
if (mediaType == "bookSection") {
var newItem = new Zotero.Item("bookSection");
} else if (mediaType == "conferencePaper") {
var newItem = new Zotero.Item("conferencePaper");
} else if (mediaType == "journalArticle") {
var newItem = new Zotero.Item("journalArticle");
}
var xPathAllData = doc.evaluate('//pre', doc, nsResolver, XPathResult.ANY_TYPE, null);
var allData = xPathAllData.iterateNext().textContent.split("},");
var cleanFirstEntry = allData[0].indexOf(",");
allData[0] = allData[0].substr(cleanFirstEntry);
var headers = new Array();
var content = new Array();
var splitAllData;
for (var i = 0; i < allData.length-2; i++) {
splitAllData = allData[i].split("=");
headers.push(splitAllData[0].replace(/^\s*|\s*$|\W*/g, ''));
content.push(splitAllData[1].replace(/^\s*|\s*$|\{*/g, ''));
fieldTitle = headers[i].replace(",", '');
if (fieldTitle == "author") {
var authors = content[i].split("and");
for (var j =0; j<authors.length; j++) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authors[j], "author"));
}
} else if (fieldTitle == "editor") {
var editors = content[i].split("and");
for (var j =0; j<editors.length; j++) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(editors[j], "editor"));
}
} else {
dataTags[fieldTitle] = content[i];
}
}
if (mediaType == "conferencePaper") {
associateData (newItem, dataTags, "booktitle", "conferenceName");
} else {
associateData (newItem, dataTags, "booktitle", "bookTitle");
}
newItem.url = doc.location.href;
associateData (newItem, dataTags, "year", "date");
associateData (newItem, dataTags, "pages", "pages");
associateData (newItem, dataTags, "title", "title");
associateData (newItem, dataTags, "publisher", "publisher");
associateData (newItem, dataTags, "volume", "volume");
associateData (newItem, dataTags, "isbn", "ISBN");
associateData (newItem, dataTags, "series", "series");
associateData (newItem, dataTags, "journal", "publicationTitle");
associateData (newItem, dataTags, "number", "issue");
newItem.complete();
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var articles = new Array();
/* Multiple code doesn't work due to Permission denied to get property HTMLDocument.documentElement error.
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
//newer interface xPaths
if (doc.title.match("DEMO")) {
var titles = doc.evaluate('//a/font', doc, nsResolver, XPathResult.ANY_TYPE, null);
var links = doc.evaluate('//dt/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_title;
while (next_title = titles.iterateNext()) {
items[links.iterateNext().href] = next_title.textContent;
}
//older interface xPaths
} else {
var titles = doc.evaluate('//td[3]', doc, nsResolver, XPathResult.ANY_TYPE, null);
var links = doc.evaluate('//td[1]/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_title;
var split1;
var split2;
while (next_title = titles.iterateNext()) {
split1 = next_title.textContent.indexOf(":");
var title = next_title.textContent.substr(split1+2);
split2 = title.indexOf(".");
title = title.substr(0, split2);
items[links.iterateNext().href] = title;
}
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
} else {
*/
articles = [url];
//}
Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
Zotero.wait();
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.dblp.org/rec/bibtex/journals/cssc/XuY12",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"firstName": "Jianwen",
"lastName": "Xu",
"creatorType": "author"
},
{
"firstName": "Hu",
"lastName": "Yang",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"url": "http://www.dblp.org/rec/bibtex/journals/cssc/XuY12",
"date": "2012",
"pages": "327-341",
"title": "On the Preliminary Test Backfitting and Speckman Estimators\n in Partially Linear Models and Numerical Comparisons",
"volume": "41",
"publicationTitle": "Communications in Statistics - Simulation and Computation",
"issue": "3",
"libraryCatalog": "DBLP Computer Science Bibliography",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://www.dblp.org/rec/bibtex/conf/ats/KochteZBIWHCP10",
"items": [
{
"itemType": "conferencePaper",
"creators": [
{
"firstName": "Michael A.",
"lastName": "Kochte",
"creatorType": "author"
},
{
"firstName": "Christian G.",
"lastName": "Zoellin",
"creatorType": "author"
},
{
"firstName": "Rafal",
"lastName": "Baranowski",
"creatorType": "author"
},
{
"firstName": "Michael E.",
"lastName": "Imhof",
"creatorType": "author"
},
{
"firstName": "Hans-Joachim",
"lastName": "Wunderlich",
"creatorType": "author"
},
{
"firstName": "Nadereh",
"lastName": "Hatami",
"creatorType": "author"
},
{
"firstName": "Stefano Di",
"lastName": "Carlo",
"creatorType": "author"
},
{
"firstName": "Paolo",
"lastName": "Prinetto",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"conferenceName": "Asian Test Symposium",
"url": "http://www.dblp.org/rec/bibtex/conf/ats/KochteZBIWHCP10",
"date": "2010",
"pages": "3-8",
"title": "Efficient Simulation of Structural Faults for the Reliability\n Evaluation at System-Level",
"libraryCatalog": "DBLP Computer Science Bibliography",
"accessDate": "CURRENT_TIMESTAMP"
}
]
}
]
/** END TEST CASES **/