Skip to content
Permalink
Browse files

Update neural information processing systems (zotero#1747)

  • Loading branch information...
GuyAglionby authored and adam3smith committed Sep 28, 2018
1 parent b6a5735 commit 9a431bc8f6020e601fd9f981921dcf16bf499e4d
Showing with 55 additions and 36 deletions.
  1. +55 −36 Neural Information Processing Systems.js
@@ -1,67 +1,76 @@
{
"translatorID": "c816f8ad-4c73-4f6d-914e-a6e7212746cf",
"label": "Neural Information Processing Systems",
"creator": "Fei Qi, Sebastian Karcher",
"target": "^https?://(books|papers)\\.nips\\.cc/",
"creator": "Fei Qi, Sebastian Karcher, Guy Aglionby",
"target": "^https?://papers\\.nips\\.cc/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2014-03-11 19:45:28"
"lastUpdated": "2018-09-17 14:30:14"
}

function detectWeb(doc, url) {
var contRe = /\/book\//;
var m = contRe.exec( url );
if (m && ZU.xpathText(doc, '//ul/li/a[contains(@href, "paper")]')) return "multiple";
else if (url.indexOf("/paper/") && ZU.xpathText(doc, '//meta[@name="citation_title"]/@content')) return "bookSection";
let contRe = /\/book\/|\/author\/|\/search\//;
if (contRe.exec(url) && getSearchResults(doc, true)) return "multiple";
else if (url.includes("/paper/")) return "bookSection";
return false;
}

function scrape(doc, url) {
var pdfurl = url + ".pdf";
var bibtexurl = url+ "/bibtex"
Zotero.Utilities.HTTP.doGet(bibtexurl, function( text ) {
var translator = Zotero.loadTranslator("import");
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
// Zotero.debug( text );
translator.setString( text );
translator.setHandler( "itemDone", function( obj, item ) {
item.attachments = [{url: pdfurl, title:"NIPS Full Text PDF", mimeType:"application/pdf"},
{document: doc, title: "NIPS Snapshort", mimeTYpe: "text/html"}];
item.complete();
});
translator.translate();
//work on PDF pages
let baseurl = url.replace(/\.pdf$/, "");
let pdfurl = baseurl + ".pdf";
let bibtexurl = baseurl+ "/bibtex";
Zotero.Utilities.HTTP.doGet(bibtexurl, function( text ) {
let translator = Zotero.loadTranslator("import");
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
translator.setString( text );
translator.setHandler( "itemDone", function( obj, item ) {
item.attachments.push({url: pdfurl, title:"NIPS Full Text PDF", mimeType:"application/pdf"});
if (url.endsWith(".pdf")) {
item.attachments.push({url: baseurl, title:"NIPS Snapshot", mimeType: "text/html"});
}
else {
item.attachments.push({document: doc, title: "NIPS Snapshot"});
}
item.complete();
});
translator.translate();
});
}

function doWeb( doc, url ) {
var titleRe = '//ul/li/a[contains(@href, "paper")]';
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
// Retrive items
var items = new Object();
var arts = new Array();
var titles = doc.evaluate( titleRe, doc, null, XPathResult.ANY_TYPE, null);
while ( title = titles.iterateNext()) {
var art = new Object;
items[title.href] = title.textContent;
}
let items = getSearchResults(doc, false);
Zotero.selectItems(items, function (items) {
if (!items) {
return true;
}
for (var i in items) {
arts.push(i);
}
ZU.processDocuments(arts, scrape)
ZU.processDocuments(Object.keys(items), scrape);
});
}
else {
scrape(doc, url)
scrape(doc, url);
}
}

function getSearchResults(doc, checkOnly) {
let items = {};
let found = false;
let rows = ZU.xpath(doc, '//li//a[contains(@href, "paper")]');
for (let i=0; i<rows.length; i++) {
let href = rows[i].href;
let title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
/** BEGIN TEST CASES **/
var testCases = [
{
@@ -145,6 +154,16 @@ var testCases = [
"type": "web",
"url": "http://papers.nips.cc/book/advances-in-neural-information-processing-systems-22-2009",
"items": "multiple"
},
{
"type": "web",
"url": "https://papers.nips.cc/author/richard-s-zemel-388",
"items": "multiple"
},
{
"type": "web",
"url": "https://papers.nips.cc/search/?q=bill",
"items": "multiple"
}
]
/** END TEST CASES **/
/** END TEST CASES **/

0 comments on commit 9a431bc

Please sign in to comment.
You can’t perform that action at this time.