-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESpacenet.js
174 lines (145 loc) · 5.81 KB
/
ESpacenet.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
{
"translatorID":"176948f7-9df8-4afc-ace7-4c1c7318d426",
"translatorType":4,
"label":"ESpacenet",
"creator":"Gilles Poulain",
"target":"http://v3.espacenet.com/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2008-09-02 13:40:00"
}
function detectWeb(doc, url) {
if(doc.location.href.match("results?")) {
return "multiple";
} else if (doc.location.href.match("textdoc")) {
return "patent";
}
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var titles = doc.evaluate('//td[3]/strong/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_title;
while (next_title = titles.iterateNext()) {
items[next_title.href] = next_title.textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
} else {
articles = [url];
}
Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
Zotero.wait();
}
function getItem(reftext,re) {
var item = reftext.match(re);
return item[1];
}
function scrape(doc,url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
//Get title
var xpath = "/html/body/form/table[2]/tbody/tr[1]/td[3]/h2";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var title = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var title1 = title.split(" ");
for (var j in title1) {
title1[j] = title1[j][0].toUpperCase() + title1[j].substr(1).toLowerCase();
}
title = title1.join(" ");
}
//Get Abstract
var xpath = '//td[@id="abCell"]';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var abstract = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get Applicant
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[4]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var applicant = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get application number
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[8]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var anumber = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get patent number
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[1]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var pnumber = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get CIB
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[6]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var CIBnumber = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get ECLA
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[7]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var tmpECLAnumber = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
tmpECLAnumber = tmpECLAnumber.substr(24);
tmpECLAnumber = tmpECLAnumber.replace(/\)+/g, '; ');
var aus = tmpECLAnumber.split("; ");
var ECLAnumber = "";
for (var i=0; i< aus.length/2 ; i++){
ECLAnumber = ECLAnumber + aus[i] + "; "
}
}
//Get priority number
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[9]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var prnumber = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get date
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[2]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var date = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get Creators
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[3]/td[2]";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var author = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Create Zotero Ref
var newArticle = new Zotero.Item('patent');
newArticle.url = doc.location.href;
newArticle.title = title;
newArticle.date = date;
newArticle.abstractNote = abstract;
newArticle.assignee = applicant;
newArticle.patentNumber = pnumber;
newArticle.priorityNumbers = prnumber;
newArticle.applicationNumber = anumber;
newArticle.extra = "CIB: " + CIBnumber + "\nECLA: " + ECLAnumber
var author1 = author.split("; ");
;
for (var m = 0; m< author1.length; m++) {
if (author1[m].match(/\(/)) {
author1[m] = author1[m].substr(0, author1[m].length-5);
}
words = author1[m].split(/\s/);
for (var j in words) {
words[j] = words[j][0].toUpperCase() + words[j].substr(1).toLowerCase();
}
var inventor = '';
for (var k = 1; k < words.length; k++) {
inventor = inventor +words[k] + " ";
if (k == words.length-1) {
inventor = inventor +words[0];
newArticle.creators.push(Zotero.Utilities.cleanAuthor(inventor, "inventor"));
}
}
}
newArticle.complete();
}