public
Last active

New Espacenet zotero translator

  • Download Gist
ESpacenet.js
JavaScript
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
{
"translatorID":"176948f7-9df8-4afc-ace7-4c1c7318d426",
"label":"ESpacenet",
"creator":"Gilles Poulain and Rintze Zelle",
"target":"http://worldwide.espacenet.com/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":"1",
"translatorType":4,
"lastUpdated":"2011-01-11 04:31:00"
}
 
function detectWeb(doc, url) {
if(url.match("searchResults\?")) {
return "multiple";
} else if (doc.location.href.match("biblio")) {
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('//span[@class="resNumber"]/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
 
var next_title;
while (next_title = titles.iterateNext()) {
items[next_title.href] = Zotero.Utilities.trim(next_title.textContent);
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
 
} else {
articles = [url];
}
if(articles.length == 0) return true;
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 = '//div[@id="pagebody"]/h3';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var title = Zotero.Utilities.trimInternal(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 = '//div[@class="application article clearfix"]/p[1]';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var abstract = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get Applicant
var xpath = '//table[@class="tableType3"]/tbody/tr[5]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var applicantField = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get application number
var xpath = '//table[@class="tableType3"]/tbody/tr[7]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var anumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get patent number
var xpath = '//table[@class="tableType3"]/tbody/tr[2]/td/a';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var pnumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var pnumber= pnumber.split("-");
pnumber=pnumber[0];
}
 
//Get CIB
var xpath = '//tr[contains(th/text(),"- international:")]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var CIBnumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get ECLA
var xpath = "//tr[contains(th/text(),'- European:')]/td";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
ECLAnumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get priority number
var xpath = '//table[@class="tableType3"]/tbody/tr[8]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var prnumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
 
//Get date
var xpath = '//table[@class="tableType3"]/tbody/tr[3]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var date = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
 
//Get Creators
var xpath = '//table[@class="tableType3"]/tbody/tr[4]/td';
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var inventorField = Zotero.Utilities.trimInternal(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.patentNumber = pnumber;
newArticle.priorityNumbers = prnumber;
newArticle.applicationNumber = anumber;
newArticle.extra = "CIB: " + CIBnumber + "\nECLA: " + ECLAnumber
 
if (applicantField) {
var applicant = reorganizeNames(applicantField).join("; ");
newArticle.assignee = applicant;
}
 
var inventors = reorganizeNames(inventorField);
for (var m = 0; m< inventors.length; m++) {
newArticle.creators.push(Zotero.Utilities.cleanAuthor(inventors[m], "inventor", true));
}
 
newArticle.complete();
}
 
function reorganizeNames(nameField) {
var nameCollection = nameField.split("(")[1].split(")")[0];
var nameParts = nameCollection.split(" ");
for (var j in nameParts) {
nameParts[j] = nameParts[j][0].toUpperCase() + nameParts[j].substr(1).toLowerCase();
}
nameCollection = nameParts.join(" ");
 
var nameArray = nameCollection.split(", ; ");
 
for (var m = 0; m< nameArray.length; m++) {
if (nameArray[m].match(",")) {
var nameParts = "";
nameParts = nameArray[m].split(", ");
nameParts[0] = nameParts[0].concat(",");
nameArray[m] = nameParts.join(" ");
} else {
nameArray[m] = nameArray[m].replace(" ", ", ");
}
}
 
return nameArray;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.