summaryrefslogtreecommitdiff
path: root/ESpacenet.js
blob: cc000aa0720823c0700d120515bf5dfdc5a3aea3 (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
{
	"translatorID": "176948f7-9df8-4afc-ace7-4c1c7318d426",
	"label": "ESpacenet",
	"creator": "Sebastian Karcher and Aurimas Vinckevicius",
	"target": "^https?://worldwide\\.espacenet\\.com/",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-08-15 02:07:20"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	ESpacenet translator - Copyright © 2011 Sebastian Karcher
	
	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.indexOf("searchResults?") !== -1
		&& getSearchResults(doc).length) {
			return "multiple";
	}

	if (url.indexOf("biblio") !== -1
		&& getTitle(doc)) {
		return "patent";
	}
}

function getSearchResults(doc) {
	return ZU.xpath(doc,'//span[@class="resNumber"]/a[starts-with(@id,"publicationId")]');
}

function getTitle(doc) {
	var title = ZU.xpathText(doc, '//div[@id="pagebody"]/h3[1]');
	if(title) {
		if(title.toUpperCase() == title) {
			title = ZU.capitalizeTitle(title, true);
		}
		return title.trim();
	}
}

//locale labels from URL
var i18n = {
	/** German **/
	de_EP: {
		"Erfinder:": "Inventor(s):",
		"Anmelder:": "Applicant(s):",
		"Klassifikation:": "Classification:",
		"Internationale": "international",
		"Europäische": "Euro",
		"Anmeldenummer:": "Application number:",
		"Prioritätsnummer(n):": "Priority number(s):",
		"Bookmark zur Seite": "Page bookmark"
	},
	/** French **/
	fr_EP: {
		"Inventeur(s)": "Inventor(s):",
		"Demandeur(s)": "Applicant(s):",
		"Classification:": "Classification:",
		"internationale": "international",
		"européenne": "Euro",
		"Numéro de demande": "Application number:",
		"Numéro(s) de priorité:": "Priority number(s):",
		"Signet": "Page bookmark"
	}
}

function initLocale(url) {
	var m = url.match(/[?&]locale=([^&]+)/);
	if(m && i18n[m[1]]) {
		i18n = i18n[m[1]];	
	} else {
		i18n = {};	//English
	}
}

function L(label, fromEN) {
	if(fromEN) {
		for(var l in i18n) {
			if(i18n[l] == label) {
				return l;
			}
		}
		return label;
	}

	return i18n[label] || label;
}

var labelMap = {
	"Application number:": "applicationNumber",
	"Priority number(s):": "priorityNumbers",
	"Page bookmark": "url"
};

function applyValue(newItem, label, value) {
	if (value && labelMap[label]) {
		newItem[labelMap[label]] = value;
	}
}

//clean up names list and call callback with a clean name
function cleanNames(names, callback) {
	if(names) {
		names = names.replace(/[()]/g, "").trim();

		if(names == names.toUpperCase()) {
			names = ZU.capitalizeTitle(names, true);
		}

		names = names.split(/\s*;\s*/);
		for(var j=0, m=names.length; j<m; j++) {
			callback(names[j].replace(/\s*,$/, ''));
		}
	}
}

function scrape(doc) {
	var newItem = new Zotero.Item("patent");
	newItem.title = getTitle(doc);

	var rows = ZU.xpath(doc,
		'//tr[@class="noPrint" or ./th[@class="printTableText"]]');

	for (var i=0, n=rows.length; i<n; i++) {
		var label = L(rows[i].firstElementChild.textContent.trim());
		var value = rows[i].firstElementChild.nextElementSibling;
		if(!value) continue;
		//Z.debug("label: " + label);
		//Z.debug("value: " + value.textContent);
		switch(label) {
			case "Inventor(s):":
				cleanNames(ZU.xpathText(value, './span[@id="secondaryInventors"]'),
					function(name) {
						newItem.creators.push(
							ZU.cleanAuthor(name.replace(/,?\s/, ', '),	//format displayed is LAST FIRST MIDDLE, so we add a comma after LAST
								"inventor", true));
					});
			break;
			case "Applicant(s):":
				var assignees = [];
				cleanNames(ZU.xpathText(value, './span[@id="secondaryApplicants"]'),
				  	function(name) {
				  		assignees.push(name);
				  	});
				newItem.assignee = assignees.join('; ');
			break;
			case "Classification:":
				var	CIB = ZU.trimInternal(
					ZU.xpathText(value,
						'.//td[preceding-sibling::th[contains(text(),"'
						+ L("international", true) + '")]]') || '');
				var ECLA = ZU.trimInternal(ZU.xpathText(value,
						'.//td[preceding-sibling::th[contains(text(),"'
						+ L("Euro", true) + '")]]/a', null, '; ') || '');
				if(CIB || ECLA) {
					newItem.extra = [];
					if(CIB) newItem.extra.push('CIB: ' + CIB);
					if(ECLA) newItem.extra.push('ECLA: ' + ECLA);
					newItem.extra = newItem.extra.join('\n');
				}
			break;
			case "Page bookmark":
				applyValue(newItem, label, value.firstElementChild.href)
			break;
			default:
				applyValue(newItem, label, ZU.trimInternal(value.textContent));
		}
	}

	var date = ZU.xpathText(doc, '//div[@id="pagebody"]/h1[1]');
	if(date && (date = date.match(/\d{4}-\d{2}-\d{2}/))) {
		newItem.date = date[0];
	}
	
	var patentnumber = ZU.xpathText(doc, '//div[@class="application article clearfix"]/h3');
	if (patentnumber) newItem.patentNumber = ZU.trimInternal(patentnumber.replace(/Abstract (not available )?(of|for)|Abrégé (non disponible )?pour|(Keine )?Zusammenfassung (verfügbar )?(von|für)/, ""));
	newItem.abstractNote = ZU.trimInternal(
		ZU.xpathText(doc, '//p[@class="printAbstract"]') || '');

	newItem.attachments.push({
		title:"Espacenet patent record",
		document: doc
	});

	newItem.complete();
}

function doWeb(doc, url) {
	initLocale(url);

	if (detectWeb(doc, url) == "multiple"){
		var hits = {};
		var results = getSearchResults(doc);
		for (var i=0, n=results.length; i<n; i++) {
			hits[results[i].href] = results[i].textContent.trim();
		}

		Z.selectItems(hits, function(items) {
			if (!items) return true;

			var urls = [];
			for (var j in items) {
				urls.push(j);
			}
			ZU.processDocuments(urls, scrape);
		});
	} else {
		scrape(doc);	
	}
}   
  /** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://worldwide.espacenet.com/searchResults?DB=worldwide.espacenet.com&locale=en_EP&query=cell+phone&ST=singleline&compact=false",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://worldwide.espacenet.com/publicationDetails/biblio?DB=worldwide.espacenet.com&II=2&ND=3&adjacent=true&locale=en_EP&FT=D&date=20120426&CC=WO&NR=2012054443A1&KC=A1",
		"items": [
			{
				"itemType": "patent",
				"title": "Electronic Control Glove",
				"creators": [
					{
						"firstName": "Willie",
						"lastName": "Blount",
						"creatorType": "inventor"
					}
				],
				"issueDate": "2012-04-26",
				"abstractNote": "Many people active and inactive can't readily control their audio experience without reaching into a pocket or some other location to change a setting or answer the phone. The problem is the lack of convenience and the inaccessibility when the user is riding his motorcycle, skiing, bicycling, jogging, or even walking with winter gloves on, etc. The electronic control glove described here enables enhanced control over electronic devices wirelessly at all times from the user's fingertips. The glove is manufactured with electrical conducive materials along the fingers and the thumb, where contact with the thumb and finger conductive materials creates a closed circuit which is transmitted to a control device on the glove that can then wirelessly transmit messages to remote electronic devices such as cell phones, audio players, garage door openers, military hardware and software, in work environments, and so forth.",
				"applicationNumber": "WO2011US56657 20111018",
				"assignee": "Blue Infusion Technologies, Llc; Blount, Willie, Lee, Jr",
				"extra": "CIB: G06F3/033; G09G5/08",
				"patentNumber": "WO2012054443 (A1)",
				"priorityNumbers": "US20100394879P 20101020 ; US20100394013P 20101018",
				"url": "http://worldwide.espacenet.com/publicationDetails/biblio?FT=D&date=20120426&DB=worldwide.espacenet.com&locale=en_EP&CC=WO&NR=2012054443A1&KC=A1&ND=4",
				"attachments": [
					{
						"title": "Espacenet patent record"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://worldwide.espacenet.com/publicationDetails/biblio?DB=worldwide.espacenet.com&II=4&ND=3&adjacent=true&locale=en_EP&FT=D&date=20120426&CC=US&NR=2012101951A1&KC=A1#",
		"items": [
			{
				"itemType": "patent",
				"title": "Method and System for Secure Financial Transactions Using Mobile Communications Devices",
				"creators": [
					{
						"firstName": "Michael",
						"lastName": "Li",
						"creatorType": "inventor"
					},
					{
						"firstName": "Yuri",
						"lastName": "Shakula",
						"creatorType": "inventor"
					},
					{
						"firstName": "Martin",
						"lastName": "Rodriguez",
						"creatorType": "inventor"
					}
				],
				"issueDate": "2012-04-26",
				"abstractNote": "The present invention employs public key infrastructure to electronically sign and encrypt important personal information on a mobile communications device (MCD), without disclosing private, personal information to the transaction counterparts and middleman, thus preserving highly elevated and enhanced security and fraud protection. In one embodiment, the present invention can use a mobile device identifier, such as a cell phone number or email address, for example, as an index/reference during the entire transaction, so that only the account holder and the account issuer know the underlying account number and other private information.",
				"applicationNumber": "US201113172170 20110629",
				"assignee": "Li Michael; Shakula Yuri; Rodriguez Martin",
				"extra": "CIB: G06Q20/00",
				"patentNumber": "US2012101951 (A1)",
				"priorityNumbers": "US201113172170 20110629 ; US20100406097P 20101022",
				"url": "http://worldwide.espacenet.com/publicationDetails/biblio?FT=D&date=20120426&DB=worldwide.espacenet.com&locale=en_EP&CC=US&NR=2012101951A1&KC=A1&ND=4",
				"attachments": [
					{
						"title": "Espacenet patent record"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://worldwide.espacenet.com/publicationDetails/biblio?locale=de_EP&II=9&FT=D&CC=AU&DB=EPODOC&NR=2814389A&date=19890601&ND=3&KC=A&adjacent=true",
		"items": [
			{
				"itemType": "patent",
				"title": "Eswl Employing Non-Focused Spherical-Sector Shock Waves",
				"creators": [
					{
						"firstName": "S. Filler",
						"lastName": "William",
						"creatorType": "inventor"
					}
				],
				"issueDate": "1989-06-01",
				"applicationNumber": "AU19890028143D 19891108",
				"assignee": "William S. Filler",
				"extra": "CIB: A61B17/22; A61B17/225; G10K11/32; G10K15/04; (IPC1-7): A61B17/22",
				"patentNumber": "AU2814389 (A)",
				"priorityNumbers": "US19870118325 19871109",
				"url": "http://worldwide.espacenet.com/publicationDetails/biblio?FT=D&date=19890601&DB=EPODOC&locale=de_EP&CC=AU&NR=2814389A&KC=A&ND=4",
				"attachments": [
					{
						"title": "Espacenet patent record"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://worldwide.espacenet.com/publicationDetails/biblio?locale=fr_EP&II=9&FT=D&CC=AU&DB=EPODOC&NR=2814389A&date=19890601&ND=3&KC=A&adjacent=true",
		"items": [
			{
				"itemType": "patent",
				"title": "Eswl Employing Non-Focused Spherical-Sector Shock Waves",
				"creators": [
					{
						"firstName": "S. Filler",
						"lastName": "William",
						"creatorType": "inventor"
					}
				],
				"issueDate": "1989-06-01",
				"applicationNumber": "AU19890028143D 19891108",
				"assignee": "William S. Filler",
				"extra": "CIB: A61B17/22; A61B17/225; G10K11/32; G10K15/04; (IPC1-7): A61B17/22",
				"patentNumber": "AU2814389 (A)",
				"priorityNumbers": "US19870118325 19871109",
				"url": "http://worldwide.espacenet.com/publicationDetails/biblio?FT=D&date=19890601&DB=EPODOC&locale=fr_EP&CC=AU&NR=2814389A&KC=A&ND=4",
				"attachments": [
					{
						"title": "Espacenet patent record"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	}
]
/** END TEST CASES **/