summaryrefslogtreecommitdiff
path: root/wiso.js
blob: fcf01bbb53f9a465301e1cce8c884ed36828f790 (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
{
	"translatorID": "136d5c30-d8b1-476f-9564-702a41b6126e",
	"label": "wiso",
	"creator": "Philipp Zumstein",
	"target": "^https?://www\\.wiso-net\\.de/webcgi\\?",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gsv",
	"lastUpdated": "2014-03-04 23:58:44"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	wiso 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 (url.search(/START=A[246]0/) !== -1) {
		if( ZU.xpath(doc, '//a[contains(@class, "boxExport")]').length>0 ) {
			//single item --> generic fallback = journalArticle
			return "journalArticle";
		}
	} else if ( ZU.xpath(doc, '//a/span[contains(@class, "boxHeader")]').length>0 ) {
		return "multiple";
	}
}


function scrape(doc, url) {
	var risUrl = url+"&OHNE_SAVE=1&T_TEMPLATE=ris";

	ZU.doGet(risUrl, function(text) {
		
		//author names are messy and not consistently saved
		//sometimes a list of authors is saved in one field seperated by commas
		//to prevent this breaking sync:
		text = text.replace(/^(A[U123]|ED)\s+-\s+(.+[,;].+)$/mg, cleanAuthorFields );
		
		//sometimes more than one T1 fields are present
		//or the title is distributed over T1, T2, T3...
		if( /^TY\s+-\s+JOUR/m.test(text) && /^JF\s+-\s+/m.test(text) && !/^TI\s+-\s+/m.test(text)) {
			var titlesArray = [];
			text = text.replace(/\r?\n^T[1-5]\s+-\s+(.+)$/mg, function(m, title) {
				title = ZU.trimInternal(title);
				if(title) titlesArray.push(title);
				return '';
			});
			
			if(titlesArray.length) {
				//insert an aggregated TI tag
				text = text.replace(/^TY\s+-\s+(.+)$/m , "$&\nTI  - " + titlesArray.join(": "));
			}
		}

		//the field custom field TS seems to be used for some database info
		text = text.replace(/^TS\s+-/m,"DB -");
		//language LA not LG
		text = text.replace(/^LG\s+-/m,"LA -");
		//sometimes an abstract is saved in the N1 field instead of the AB filed:
		if ( text.search(/^AB\s+-/m) == -1) {
			text = text.replace(/^N1\s+-/m,"AB -");
		}
		var trans = Zotero.loadTranslator('import');
		trans.setTranslator('32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7');//https://github.com/zotero/translators/blob/master/RIS.js
		trans.setString(text);
		//Z.debug(text);

		trans.setHandler('itemDone', function (obj, item) {
			item.date = item.date.replace(/(\d\d)\.(\d\d)\.(\d\d\d\d)/,"$3-$2-$1");//e.g. 02.03.2014 ==> 2014-03-02
			item.attachments = [{
				title: "Snapshot",
				document:doc
			}];
			//the url for ebooks is sometimes wrong/incomplete
			if (item.url.indexOf("DOKV_DB=&") != -1) {
				item.url = ZU.xpathText(doc, '//a[@class="linkifyplus"]');
			}
			//Zotero.debug(item);
			item.complete();
		});
	
		trans.translate();
	} , null , "ISO-8859-1");//the text file is LATIN1 encoded
	
}


function cleanAuthorFields(m, tag, authorStr) {
	//m = matched string (everything)
	//tag = first parenthesized submatch, i.e., AU, A1, A2, A3 or ED
	//authorStr = second parenthesized submatch, i.e., what is following the tag
	var authors = authorStr.split(';');
	var fixName = false;
	if(authors.length == 1)  {
		//no semicolon
		fixName = true;
		authors = authorStr.split(',');
		if(authors.length < 3) {
			//at most single comma, don't mess with it
			return m;
		} else if (authors.length == 3) {
			//we have to distinguish the correct cases where the third part is
			//just a suffix as "Jr." and wrong cases where this is a list of
			//three authors ==> easiest is maybe to check for a space
			if (ZU.superCleanString(authors[2]).indexOf(' ') == -1) {
				return m;
			}
		}
	}
	
	//here: One of the following two cases holds:
	//(i) authorStr contains semicolon(s), authors is the array of its different parts, fixName = false
	//(ii) authorStr contains no semicolon but more than one comma, authors is the array of its different parts, fixName = true	
	var str = '';
	for(var i=0; i<authors.length; i++) {
		var author = ZU.superCleanString(authors[i]).replace(/(?:Dr|Prof)\.\s*/,"");
		if(fixName && author.indexOf(',') == -1 && author.indexOf(' ') != -1) {
			//best guess: split at the last space
			var splitAt = author.lastIndexOf(' ');
			author = author.substring(splitAt+1) + ', ' + author.substring(0, splitAt);
		}
		if(author) str += '\n' + tag + '  - ' + author;
	}
	return str.substr(1);
}


function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		var items = new Object();
		var articles = new Array();
		var rows = ZU.xpath(doc, '//a[./span[@class="boxHeader"]]')
		for(var i=0; i<rows.length; i++) {
			var title = ZU.xpathText(rows[i], './span[@class="boxHeader"]');
			var link = ZU.xpathText(rows[i], './@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": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZECO&DOKV_NO=AUIN425053660&DOKV_HS=0&PP=1",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"lastName": "von Michael Ziegler",
						"creatorType": "author",
						"fieldMode": 1
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Snapshot"
					}
				],
				"title": "Die Technologie fällt nicht vom Himmel",
				"date": "2014-03-03",
				"publicationTitle": "AI",
				"ISSN": "0005-1306",
				"issue": "003",
				"url": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZECO&DOKV_NO=AUIN425053660&DOKV_HS=0&PP=1",
				"abstractNote": "Automatisiertes Fahren: Wie verändert dieser Megatrend unsere Fahrzeuge, die Wertschöpfungskette und die Mobilität allgemein? Fünf ausgewiesene Experten beantworten beim »Automobil Industrie« Round-Table-Gespräch die wichtigsten Fragen.",
				"archive": "powered by GENIOS",
				"libraryCatalog": "wiso",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZWIW&DOKV_NO=BEFO20071105986-E-FIZT-BEFO-DOMA-ZDEE-ETEC&DOKV_HS=0&PP=1",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"lastName": "Köpke",
						"firstName": "Ralf",
						"creatorType": "author"
					},
					{
						"lastName": "Nikionok-Ehrlich",
						"firstName": "Angelika",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Energiepolitik",
					"Energiemarkt",
					"Preisentwicklung",
					"Betriebswirtschaft",
					"Energiehandel",
					"Energiemanagement",
					"Energiepolitik",
					"Europaeische Union",
					"Preisentwicklung",
					"Regenerative Energie",
					"Wettbewerb",
					"Wirtschaftsrecht",
					"Zertifizierung"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Snapshot"
					}
				],
				"title": "Eigentor für die Stromwirtschaft",
				"publicationTitle": "Energie und Management",
				"ISSN": "0945-8794",
				"pages": "6",
				"url": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZWIW&DOKV_NO=BEFO20071105986-E-FIZT-BEFO-DOMA-ZDEE-ETEC&DOKV_HS=0&PP=1",
				"abstractNote": "Der Stromkonzern E.ON kündigt zum Jahresbeginn 2008 Strompreiserhöhungen von knapp 10 % aufgrund höherer Beschaffungskosten und gestiegener Aufwendungen für erneuerbare Energien an. Diese vermeintliche Rechtfertigung wird widerlegt. Rein rechnerisch ergäben sich lediglich 0,8 % wegen der Brennstoffkosten und 0,2 % wegen der EEG-Umlage (Erneuerbare-Energien-Gesetz). Der angekündigte hohe Sprung lässt sich nicht nachvollziehen. Die Strompreisentwicklung an der Leipziger Strombörse EEX seit 2002 wird grafisch dargestellt. Daraus kann abgeleitet werden, in welchem Maße sich die vier Erzeugungsoligopolisten bereits an der CO2-Einpreisung der kostenlos zugeteilten CO2-Zertifikate bereichert haben. Die Bundesregierung arbeitet an einer Kartellrechtsänderung, aber es bleiben Bedenken, ob die vorgesehenen Regulierungen Wirkung zeigen werden. Denn Regionalversorger und Stadtwerke hängen an der Preispolitik von E.ON und RWE, und wenn der Durchschnitt insgesamt steigt, wird es keine deutlichen Einzelabweichungen nach oben geben.",
				"language": "Deutsch",
				"archive": "BEFO (C) WTI Frankfurt",
				"date": "2007",
				"libraryCatalog": "wiso",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZWIW&DOKV_NO=BLISED1E880E5071CB2CCEDB0885805C993A&DOKV_HS=0&PP=1",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"lastName": "Burger",
						"firstName": "Markus",
						"creatorType": "author"
					},
					{
						"lastName": "Sydow",
						"firstName": "Jörg",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Unternehmensnetzwerk",
					"Empirische Methode",
					"Unternehmenskooperation",
					"Organisationstheorie"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Snapshot"
					}
				],
				"title": "How Interorganizational Networks Can Become Path-Dependent: Bargaining Practic es in the Photonic s Industry",
				"date": "2014-01-17",
				"publicationTitle": "sbr Schmalenbach Business Review",
				"ISSN": "1439-2917",
				"volume": "66",
				"issue": "1",
				"pages": "73-97",
				"url": "http://www.wiso-net.de/webcgi?START=A60&DOKV_DB=ZWIW&DOKV_NO=BLISED1E880E5071CB2CCEDB0885805C993A&DOKV_HS=0&PP=1",
				"abstractNote": "The authors investigate whether and how path dependence can develop in interorganizational networks. They focus our analysis on one particular type of network management practices - bargaining practices, which we define as recurrent activities through which network partners agree to identify and distribute their cooperative surplus. They conduct three empirical case studies of regional networks in the photonics industry, using qualitative interviews and content analysis. A major finding is that network bargaining practices can indeed exhibit interorganizational path dependencies. This paper contributes by operationalizing the theory of organizational path dependence and by extending this theory to parsimoniously explain the dynamics of networks.",
				"language": "Englisch",
				"archive": "BLIS (c) GBI-Genios",
				"libraryCatalog": "wiso",
				"accessDate": "CURRENT_TIMESTAMP",
				"shortTitle": "How Interorganizational Networks Can Become Path-Dependent"
			}
		]
	}
]
/** END TEST CASES **/