forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBLP Computer Science Bibliography.js
241 lines (220 loc) · 6.53 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
{
"translatorID": "625c6435-e235-4402-a48f-3095a9c1a09c",
"label": "DBLP Computer Science Bibliography",
"creator": "Adam Crymble, Sebastian Karcher",
"target": "^https?://(www\\.)?(dblp(\\.org|\\.uni-trier\\.de/)|informatik\\.uni-trier\\.de/\\~ley//)",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcs",
"lastUpdated": "2012-04-04 12:53:51"
}
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";
}
else if (url.match(/\/db\/(journals|conf|series|books|reference)/) && !url.match(/index\.html/)){
return "multiple"
}
}
//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 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, null, 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) {
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var articles = new Array();
var rows = ZU.xpath(doc, '//ul/li')
for (i in rows){
var title = ZU.xpathText(rows[i], './b');
var link = ZU.xpathText(rows[i], './a[contains(@href, "rec/bibtex") and not(contains(@href, ".xml"))]/@href');
items[link] = title;
}
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
articles.push(i);
}
Zotero.Utilities.processDocuments(articles, scrape, function () {
Zotero.done();
});
Zotero.wait();
});
} else {
scrape(doc, url);
}
}/** 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"
}
]
},
{
"type": "web",
"url": "http://www.informatik.uni-trier.de/~ley/db/journals/tois/tois25.html",
"items": "multiple"
},
{
"type": "web",
"url": "http://dblp.uni-trier.de/db/journals/tods/tods31.html",
"items": "multiple"
}
]
/** END TEST CASES **/