summaryrefslogtreecommitdiff
path: root/Theory of Computing.js
blob: 6db9a7cc9bd6151c105782dcf87fcdb6e13e98fc (plain)
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
{
	"translatorID": "558babe7-5fca-47ea-af0f-2d9bb5bc5e53",
	"label": "Theory of Computing",
	"creator": "Piyush Srivastava",
	"target": "^https?://(theoryofcomputing\\.org|toc\\.cse\\.iitk\\.ac\\.in|cs\\.anu\\.edu\\.au/publications/toc|toc\\.ilab\\.sztaki\\.hu|toc\\.nada\\.kth\\.se|tocmirror\\.cs\\.tau\\.ac\\.il)/articles/[vg].*(/|html?)$",
	"minVersion": "1.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcv",
	"lastUpdated": "2013-11-19 08:23:18"
}

/*****
   Copyright 2013, Piyush Srivastava.

   This program 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.

   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

*****/




/*****
  Theory of Computing translator 
  *****************************


 The Theory of Computing journal has mirror sites located at the following
 domains:

 1) theoryofcomputing.org
 2) toc.cse.iitk.ac.in
 3) toc.nada.kth.se
 4) toc.ilab.sztaki.hu
 5) tocmirror.cs.tau.ac.il
 6) cs.anu.edu.au

 It has two kinds of articles, "Graduate Surveys", which their provided BibTeX
 classes regard as "books" and regular "Journal Articles".  The structure of the
 URL for the graduate survey looks like

 DOMAIN/articles/gs[0-9]{3}/

 while that of the articles looks like

 DOMAIN/articles/v[0-9]{3}a{0-9]{3}/. 

 These formats are used by detectWeb to find out whether we are looking at a
 graduate survey ("Book") or a journal article.

 The theory of computing journal provides the PDF file for a given article (say
 gs001) at the url DOMAIN/article/gs001/gs001.pdf.

 ******/




//A Regexp for extracting the Domain

var surveyRegexp = new RegExp("articles/(gs[^/]+)");
var journalRegexp = new RegExp("articles/(v[^/]+)");

function detectWeb(doc, url){
	if (surveyRegexp.test(url))
		return "book";
	else
		return "journalArticle";
}

function doWeb(doc, url){
	var typeRegExp;
	var type = detectWeb(doc, url);

	//Select the right regexp according to the article type
	if (type == "journalArticle")
		typeRegExp = journalRegexp;
	else
		typeRegExp = surveyRegexp;

	var urlData = typeRegExp.exec(url);
	//urlData is an Array of three elements, with the element at index 1 containg the
	//base domain of the mirror being accesses, and the element at index 2
	//containing the article ID.

	var articleID = urlData[1];

	//We now start constructing the Zoetro item
	var newItem = new Zotero.Item(type);

	//Store the snapshot and the PDF file
	newItem.attachments.push({
		title: "Theory of Computing Snapshot",
		document: doc});
	var pdfLink = articleID + ".pdf";
	newItem.attachments.push({
		title: "Theory of computing Full Text PDF",
		mimeType: "application/pdf",
		url:pdfLink});

	//Get the article topLine
	var topLine = ZU.xpathText(doc, '//div[@id="articletopline"]');

	//Get the article publication date lines
	var pubDateLines = ZU.xpathText(doc, '//div[@id="articledates"]');

	//Get the article copyright line (to determine authors) 
	//This seems the most consistent way of determining the authors for this
	//journal.
	var authorLine = ZU.xpathText(doc, '//div[@id="copyright"]/a[1]');

	var keywordLine = ZU.xpathText(doc, '(//div[@class="hang"])[3]');

	var DOI = ZU.xpathText(doc, '//div[@id="doi"]');

	//Now start filling up data
	//Title
	var title = ZU.xpathText(doc, '//div[@id="articletitle"]');
	if (!title)
		title = ZU.xpathText(doc, '//div[@id="title"]');
	newItem.title = title;

	//DOI and URL
	newItem.DOI = ZU.cleanDOI(DOI);
	newItem.url = url;

	//Publcication date line
	if (pubDateLines){
		var pubDateRegexp = /Published:\s+(\w+\s+[0-9]+(?:,|\s)+[0-9]+)/gm;
		newItem.date = pubDateRegexp.exec(pubDateLines)[1];

		//This also contain page information for surveys
		if (type == "book"){
			var pageNum = /([0-9]+)\s+pages/.exec(pubDateLines)[1];
			newItem.numPages = pageNum;
		}
	}

	//Keywords
	if (keywordLine){
		keywords = ZU.trimInternal(/Keywords:\s+(.*)/.exec(keywordLine)[1]);
		keywordList = keywords.split(/,\s+/);
		newItem.tags = keywordList;
	}

	//Author
	if (authorLine){
		authorLine = ZU.trimInternal(authorLine);
		authors = /[^0-9]+[0-9]+\s+(.*)/.exec(authorLine)[1];
		authors = authors.replace(/,?\s+and\s+/, ", ");
		authorList = authors.split(/\s*,\s+/);
		for (author in authorList){
			newItem.creators.push(ZU.cleanAuthor(authorList[author], "author"));
		}
	}

	//Article number etc.
	if (topLine){
		topLine = ZU.trimInternal(topLine);
		if (type == "book"){
			number = /Graduate Surveys\s+([0-9]+)/.exec(topLine)[1];
			newItem.seriesNumber = number;    
		} else if (type == "journalArticle"){
			volumeData = /Volume\s+([0-9]+).*Article\s+([0-9]+)\s+pp\.\s+([0-9]+)-([0-9]+)/.exec(topLine);
			newItem.volume = volumeData[1];
			newItem.number = volumeData[2];
			newItem.pages = volumeData[3] + "–" + volumeData[4];
		}       
	}

	//Format specific data
	if (type == "book"){
		newItem.series = "Graduate Surveys";
		newItem.publisher = "Theory of Computing Library";
	}

	if (type == "journalArticle"){
		newItem.publicationTitle = "Theory of Computing";
		newItem.publisher = "Theory of Computing";
	}

	newItem.complete();
}

/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://theoryofcomputing.org/articles/gs004/",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"firstName": "Pooya",
						"lastName": "Hatami",
						"creatorType": "author"
					},
					{
						"firstName": "Raghav",
						"lastName": "Kulkarni",
						"creatorType": "author"
					},
					{
						"firstName": "Denis",
						"lastName": "Pankratov",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"sensitivity",
					"block sensitivity",
					"complexity measures of Boolean functions"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Variations on the Sensitivity Conjecture",
				"DOI": "10.4086/toc.gs.2011.004",
				"url": "http://theoryofcomputing.org/articles/gs004/",
				"date": "June 22, 2011",
				"numPages": "27",
				"seriesNumber": "4",
				"series": "Graduate Surveys",
				"publisher": "Theory of Computing Library",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://toc.nada.kth.se/articles/v009a013/index.html",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Aditya",
						"lastName": "Bhaskara",
						"creatorType": "author"
					},
					{
						"firstName": "Devendra",
						"lastName": "Desai",
						"creatorType": "author"
					},
					{
						"firstName": "Srinkath",
						"lastName": "Srinivasan",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"derandomization",
					"expanders",
					"explicit construction",
					"hitting sets",
					"perfect hashing"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Optimal Hitting Sets for Combinatorial Shapes",
				"DOI": "10.4086/toc.2013.v009a013",
				"url": "http://toc.nada.kth.se/articles/v009a013/index.html",
				"date": "May 25, 2013",
				"volume": "9",
				"number": "13",
				"pages": "441–470",
				"publicationTitle": "Theory of Computing",
				"publisher": "Theory of Computing",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://tocmirror.cs.tau.ac.il/articles/gs003/index.html",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"firstName": "Emanuele",
						"lastName": "Viola",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"additive combinatorics",
					"linearity testing"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Selected Results in Additive Combinatorics: An Exposition",
				"DOI": "10.4086/toc.gs.2011.003",
				"url": "http://tocmirror.cs.tau.ac.il/articles/gs003/index.html",
				"date": "May 15, 2011",
				"numPages": "15",
				"seriesNumber": "3",
				"series": "Graduate Surveys",
				"publisher": "Theory of Computing Library",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP",
				"shortTitle": "Selected Results in Additive Combinatorics"
			}
		]
	},
	{
		"type": "web",
		"url": "http://toc.ilab.sztaki.hu/articles/v005a002/index.html",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Tal",
						"lastName": "Moran",
						"creatorType": "author"
					},
					{
						"firstName": "Moni",
						"lastName": "Naor",
						"creatorType": "author"
					},
					{
						"firstName": "Gil",
						"lastName": "Segev",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"history-independent",
					"write-once memory",
					"tamper-evident",
					"vote storage mechanism",
					"information-theoretic security",
					"conflict resolution",
					"expander graphs"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Deterministic History-Independent Strategies for Storing Information on Write-Once Memories",
				"DOI": "10.4086/toc.2009.v005a002",
				"url": "http://toc.ilab.sztaki.hu/articles/v005a002/index.html",
				"date": "May 23, 2009",
				"volume": "5",
				"number": "2",
				"pages": "43–67",
				"publicationTitle": "Theory of Computing",
				"publisher": "Theory of Computing",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://toc.cse.iitk.ac.in/articles/v009a009/index.html",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Scott",
						"lastName": "Aaronson",
						"creatorType": "author"
					},
					{
						"firstName": "Paul",
						"lastName": "Christiano",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"electronic cash",
					"multivariate polynomials",
					"quantum cryptography",
					"quantum lower bounds"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Quantum Money from Hidden Subspaces",
				"DOI": "10.4086/toc.2013.v009a009",
				"url": "http://toc.cse.iitk.ac.in/articles/v009a009/index.html",
				"date": "March 11, 2013",
				"volume": "9",
				"number": "9",
				"pages": "349–401",
				"publicationTitle": "Theory of Computing",
				"publisher": "Theory of Computing",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://cs.anu.edu.au/publications/toc/articles/gs003/",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"firstName": "Emanuele",
						"lastName": "Viola",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"additive combinatorics",
					"linearity testing"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Theory of Computing Snapshot"
					},
					{
						"title": "Theory of computing Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Selected Results in Additive Combinatorics: An Exposition",
				"DOI": "10.4086/toc.gs.2011.003",
				"url": "http://cs.anu.edu.au/publications/toc/articles/gs003/",
				"date": "May 15, 2011",
				"numPages": "15",
				"seriesNumber": "3",
				"series": "Graduate Surveys",
				"publisher": "Theory of Computing Library",
				"libraryCatalog": "Theory of Computing",
				"accessDate": "CURRENT_TIMESTAMP",
				"shortTitle": "Selected Results in Additive Combinatorics"
			}
		]
	}
]
/** END TEST CASES **/