summaryrefslogtreecommitdiff
path: root/zbMATH.js
blob: 4d5caf52a7b0c6328443d47e210424c45ea03fcb (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
{
	"translatorID": "1d84c107-9dbb-4b87-8208-e3632b87889f",
	"label": "zbMATH",
	"creator": "Philipp Zumstein",
	"target": "^https?://(www\\.)?zbmath\\.org/",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsv",
	"lastUpdated": "2014-06-05 08:12:07"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	zbMATH Translator, Copyright © 2014 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( ZU.xpath(doc, '//div[@class="list"]/article').length>0 ) {
		return "multiple";
	} else if (ZU.xpath(doc, '//a[contains(@class, "bib")]').length>0 ) {//contains
		//it is a single entry --> generic fallback = journalArticle
		return "journalArticle";
	}
}

function scrape(doc, url) {
	var bibArray = doc.getElementsByClassName("bib");
	var bibUrl = bibArray[0].getAttribute('href');//e.g. "bibtex/06115874.bib"

	ZU.doGet(bibUrl, function(text) {
		//Z.debug(text);
		
		var trans = Zotero.loadTranslator('import');
		trans.setTranslator('9cb70025-a888-4a29-a210-93ec52da40d4');//https://github.com/zotero/translators/blob/master/BibTeX.js
		trans.setString(text);

		trans.setHandler('itemDone', function (obj, item) {
			
			item.title = item.title.replace(/\.$/, '');
			
			if (item.publisher) {
				var publisherSeperation = item.publisher.indexOf(":");
				if(publisherSeperation != -1) {
					item.place = item.publisher.substr(0,publisherSeperation);
					item.publisher = item.publisher.substr(publisherSeperation+1);
				}
			}
			
			//keywords are normally not in the bib file, so we take them from the page
			//moreover, the meaning of the MSC classification is also only given on the page
			if (item.tags.length==0 ) {
				var keywords = ZU.xpath(doc, '//div[@class="keywords"]/a');
				for(var i=0; i<keywords.length; i++) {
					item.tags.push( keywords[i].textContent );
				}
				var classifications = ZU.xpath(doc, '//div[@class="classification"]//tr')
				for(var i=0; i<classifications.length; i++) {
					item.extra = (item.extra ? item.extra + "\n" : '') + 'MSC2010: ' + ZU.xpathText(classifications[i], './td' , null , " = ");
				}
			}
			
			//add abstract but not review
			var abstractOrReview = ZU.xpathText(doc, '//div[@class="abstract"]');
			if(abstractOrReview.indexOf('Summary') == 0) {
				item.abstractNote = abstractOrReview.replace(/^Summary:?\s*/, '');
			}
			
			item.attachments = [{
				title: "Snapshot",
				document:doc
			}];

			var id = ZU.xpath(doc, '//div[@class="title"]/a[@class="label"]')[0];
			if (id) {
				if(!item.extra) item.extra = '';
				else item.extra += "\n";
				
				item.extra += 'Zbl: ' + ZU.trimInternal(id.textContent)
					.replace(/^\s*Zbl\s+/i, ''); //e.g. Zbl 1255.05045
				item.url = id.href;
			}
			
			item.complete();
			//Z.debug(item);
		});
		
		trans.translate();
	});

}


function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		var items = new Object();
		var articles = new Array();
		var rows = ZU.xpath(doc, '//div[@class="list"]/article');
		for(var i=0; i<rows.length; i++) {
			var title = ZU.xpathText(rows[i], './div[@class="title"]/a[1]');
			var link = ZU.xpathText(rows[i], './div[@class="title"]/a[1]/@href');
			items[link] = title;
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				articles.push(i);
			}
			ZU.processDocuments(articles, scrape);
		});
	} else {
		scrape(doc, url);
	}
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "https://www.zbmath.org/?q=an:06115874",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Dan",
						"lastName": "Hefetz",
						"creatorType": "author"
					},
					{
						"firstName": "Michael",
						"lastName": "Krivelevich",
						"creatorType": "author"
					},
					{
						"firstName": "Tibor",
						"lastName": "Szabó",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"random graphs",
					"sharp thresholds",
					"spanning trees",
					"tree-universality"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Snapshot"
					}
				],
				"itemID": "zbMATH06115874",
				"journalAbbreviation": "Random Struct. Algorithms",
				"ISSN": "1042-9832; 1098-2418/e",
				"issue": "4",
				"language": "English",
				"DOI": "10.1002/rsa.20472",
				"extra": "MSC2010: 05C05 = Trees\nMSC2010: 05C80 = Random graphs\nZbl: 1255.05045",
				"abstractNote": "We prove that a given tree T on n vertices with bounded maximum degree is contained asymptotically almost surely in the binomial random graph Gn,(1+ε)logn n provided that T belongs to one of the following two classes: (1) T has linearly many leaves; (2) T has a path of linear length all of whose vertices have degree two in T.",
				"url": "https://www.zbmath.org/?q=an:1255.05045",
				"libraryCatalog": "zbMATH",
				"title": "Sharp threshold for the appearance of certain spanning trees in random graphs",
				"publicationTitle": "Random Structures & Algorithms",
				"volume": "41",
				"pages": "391–412",
				"date": "2012"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.zbmath.org/?q=se:00001331+ai:bollobas.bela",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "https://zbmath.org/?q=an:06212000",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Noga",
						"lastName": "Alon",
						"creatorType": "author"
					},
					{
						"firstName": "Erik D.",
						"lastName": "Demaine",
						"creatorType": "author"
					},
					{
						"firstName": "Mohammad T.",
						"lastName": "Hajiaghayi",
						"creatorType": "author"
					},
					{
						"firstName": "Tom",
						"lastName": "Leighton",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"equilibrium",
					"low diameter",
					"network creation",
					"network design",
					"price of anarchy"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Snapshot"
					}
				],
				"itemID": "zbMATH06212000",
				"journalAbbreviation": "SIAM J. Discrete Math.",
				"ISSN": "0895-4801; 1095-7146/e",
				"issue": "2",
				"language": "English",
				"DOI": "10.1137/090771478",
				"extra": "MSC2010: 90C27 = Combinatorial optimization\nMSC2010: 05C85 = Graph algorithms (graph theory)\nMSC2010: 91A06 = n-person games, n>2\nZbl: 1273.90167",
				"abstractNote": "We study a natural network creation game, in which each node locally tries to minimize its local diameter or its local average distance to other nodes by swapping one incident edge at a time. The central question is what structure the resulting equilibrium graphs have, in particular, how well they globally minimize diameter. For the local-average-distance version, we prove an upper bound of 2 O(lgn) , a lower bound of 3, and a tight bound of exactly 2 for trees, and give evidence of a general polylogarithmic upper bound. For the local-diameter version, we prove a lower bound of Ω(n) and a tight upper bound of 3 for trees. The same bounds apply, up to constant factors, to the price of anarchy. Our network creation games are closely related to the previously studied unilateral network creation game. The main difference is that our model has no parameter α for the link creation cost, so our results effectively apply for all values of α without additional effort; furthermore, equilibrium can be checked in polynomial time in our model, unlike in previous models. Our perspective enables simpler proofs that get at the heart of network creation games.",
				"url": "https://zbmath.org/?q=an:1273.90167",
				"libraryCatalog": "zbMATH",
				"title": "Basic network creation games",
				"publicationTitle": "SIAM Journal on Discrete Mathematics",
				"volume": "27",
				"pages": "656–668",
				"date": "2013"
			}
		]
	},
	{
		"type": "web",
		"url": "http://zbmath.org/?q=cc:35",
		"items": "multiple"
	}
]
/** END TEST CASES **/