Trans: Fixed ESpacenet, many thanks to Edouard Leroy

This commit is contained in:
Avram Lyon 2011-05-06 10:49:40 +00:00
parent 4b4968a24e
commit fd209f98dc

View file

@ -1,8 +1,8 @@
{
"translatorID":"176948f7-9df8-4afc-ace7-4c1c7318d426",
"label":"ESpacenet",
"creator":"Gilles Poulain and Rintze Zelle",
"target":"http://v3.espacenet.com/",
"creator":"Gilles Poulain, Rintze Zelle, and Edouard Leroy",
"target":"^https?://worldwide\\.espacenet\\.com/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
@ -20,19 +20,18 @@ function detectWeb(doc, url) {
}
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 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);
@ -42,17 +41,17 @@ function doWeb(doc, url) {
articles.push(i);
}
if(articles.length == 0) return true;
Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
Zotero.wait();
} else {
articles = [url];
scrape(doc, 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];
var item = reftext.match(re);
return item[1];
}
function scrape(doc,url) {
@ -60,104 +59,96 @@ function scrape(doc,url) {
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
//Get title
var xpath = "/html/body/table[2]/tbody/tr[1]/td[3]/h2";
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();
var title = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
// In the very common case of all-caps, fix them!
if (title == title.toUpperCase()) {
title = Zotero.Utilities.capitalizeTitle(title.toLowerCase(), true);
}
title = title1.join(" ");
}
//Get Abstract
var xpath = '//td[@id="abCell"]';
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);
var abstract = Zotero.Utilities.trimInternal(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]";
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);
var applicantField = Zotero.Utilities.trimInternal(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]";
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);
var anumber = Zotero.Utilities.trimInternal(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]";
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 = 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 = "//table[1]/tbody/tr/td[1]/table/tbody/tr[6]/td[2]";
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);
var CIBnumber = Zotero.Utilities.trimInternal(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]";
var xpath = "//tr[contains(th/text(),'- European:')]/td";
if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()){
var tmpECLAnumber = Zotero.Utilities.trimInternal(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] + "; "
}
ECLAnumber = Zotero.Utilities.trimInternal(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
//Get priority number
var xpath = "//table[1]/tbody/tr/td[1]/table/tbody/tr[9]/td[2]";
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[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.trimInternal(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]";
//Get date
var xpath = '//table[@class="tableType3"]/tbody/tr[3]/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);
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.attachments = [{url:doc.location.href, title:"Espacenet patent record"}];
newArticle.title = title;
newArticle.date = date;
newArticle.abstractNote = abstract;
newArticle.patentNumber = pnumber;
newArticle.priorityNumbers = prnumber;
newArticle.applicationNumber = anumber;
newArticle.extra = "CIB: " + CIBnumber + "\nECLA: " + ECLAnumber
newArticle.extra = "CIB: " + CIBnumber + "\nECLA: " + ECLAnumber;
if (applicantField) {
var applicant = reorganizeNames(applicantField).join("; ");
newArticle.assignee = applicant;
newArticle.assignee = reorganizeNames(applicantField).join("; ");
}
var inventors = reorganizeNames(inventorField);
for (var m = 0; m< inventors.length; m++) {
newArticle.creators.push(Zotero.Utilities.cleanAuthor(inventors[m], "inventor", true));
}
newArticle.complete();
newArticle.complete();
}
function reorganizeNames(nameField) {
@ -165,15 +156,15 @@ function reorganizeNames(nameField) {
var nameParts = nameCollection.split(" ");
for (var j in nameParts) {
nameParts[j] = nameParts[j][0].toUpperCase() + nameParts[j].substr(1).toLowerCase();
}
nameCollection = nameParts.join(" ");
}
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 = nameArray[m].split(", ");
nameParts[0] = nameParts[0].concat(",");
nameArray[m] = nameParts.join(" ");
} else {
@ -181,5 +172,5 @@ function reorganizeNames(nameField) {
}
}
return nameArray;
}
return nameArray;
}