Skip to content
Permalink
Browse files

Fixes P - Part 2 (#1317)

* Rewrite Philosopher's Imprint.js
* Rewrite Publications du Quebec.js
* Update tests in PubMed.js
* Update Project MUSE.js
* Update Pubget.js
* Rewrite Protein Data Bank.js
* Pubget: make xpath for finding pmid more robust
We'll want to still find this if they switch to https
* Publication de Quebec: Don't fail when we don't have the codeloi

not doing this for title, since translators fall without that anyway
  • Loading branch information...
zuphilip authored and adam3smith committed Jun 3, 2017
1 parent d41b9d9 commit f1a7a0089fb8bf33e335c11e637433766ac6644e
Showing with 376 additions and 327 deletions.
  1. +102 −90 Philosopher's Imprint.js
  2. +8 −7 Project MUSE.js
  3. +102 −93 Protein Data Bank.js
  4. +24 −24 PubMed.js
  5. +73 −63 Pubget.js
  6. +67 −50 Publications du Quebec.js
@@ -1,96 +1,118 @@
{
"translatorID": "b0abb562-218c-4bf6-af66-c320fdb8ddd3",
"label": "Philosopher's Imprint",
"creator": "Michael Berkowitz",
"creator": "Philipp Zumstein",
"target": "^https?://quod\\.lib\\.umich\\.edu/p/phimp",
"minVersion": "1.0.0b4.r5",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2015-06-02 21:09:41"
"lastUpdated": "2017-06-03 13:00:06"
}

/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2017 Philipp Zumstein
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 (doc.evaluate('//div/span[text() = "Search Results"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
if (url.indexOf('/p/phimp?t')>-1 && getSearchResults(doc, true)) {
return "multiple";
} else if (url.match(/\d+\.\d+\.\d+/)) {
} else if (url.indexOf('/p/phimp/')>-1) {
return "journalArticle";
}
}

function getID(str) {
return str.match(/\d+\.\d+\.\d+/)[0];
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
//TODO: adjust the xpath
var rows = ZU.xpath(doc, '//table[@id="searchresults"]//td[2]/a');
for (var i=0; i<rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}


function doWeb(doc, url) {
var ids = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var titles = doc.evaluate('//div[@class="itemcitation"]//a', doc, null, XPathResult.ANY_TYPE, null);
var title;
while (title = titles.iterateNext()) {
items[title.href] = title.textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
ids.push('http://quod.lib.umich.edu/cgi/t/text/text-idx?c=phimp;view=text;rgn=main;idno=' + getID(i));
}
} else {
ids = ['http://quod.lib.umich.edu/cgi/t/text/text-idx?c=phimp;view=text;rgn=main;idno=' + getID(url)];
}
Zotero.Utilities.processDocuments(ids, function(newDoc) {
var rows = newDoc.evaluate('//tr[td[@id="labelcell"]]', newDoc, null, XPathResult.ANY_TYPE, null);
var row;
var data = new Object();
while (row = rows.iterateNext()) {
var heading = newDoc.evaluate('./td[1]', row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var value = newDoc.evaluate('./td[2]', row, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
data[heading.replace(/[\s:]/g, "")] = value;
}
var item = new Zotero.Item("journalArticle");
item.title = Zotero.Utilities.trimInternal(data['Title']);
if (data['Author']) {
item.creators.push(Zotero.Utilities.cleanAuthor(data['Author'], "author"));
} else if (data['Authors']) {
var authors = data['Authors'].split(",");
for (var i=0; i<authors.length; i++) {
var a = authors[i];
item.creators.push(Zotero.Utilities.cleanAuthor(a, "author"));
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
}
}
if (data['Keywords']) {
var kws = data['Keywords'].split(/\n/);
for (var i=0; i<kws.length; i++) {
var kw = kws[i];
if (kw != "") item.tags.push(kw);
var articles = [];
for (var i in items) {
articles.push(i);
}


ZU.processDocuments(articles, scrape);
});
} else {
scrape(doc, url);
}
}

function scrape(doc, url) {
var abstract = ZU.xpathText(doc, '//div[contains(@class, "abstract")]/p[1]');
var purl = ZU.xpathText(doc, '//div[@id="purl"]/a/@href');
var license = ZU.xpathText(doc, '//a[@id="licenseicon"]/@href');
var pdfurl = ZU.xpathText(doc, '//li[@id="download-pdf"]/a/@href');

var translator = Zotero.loadTranslator('web');
// Embedded Metadata
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
translator.setDocument(doc);
translator.setHandler('itemDone', function (obj, item) {
if (abstract) {
item.abstractNote = abstract;
}
var voliss = data['Source'].replace(item.title, "");
if (item.creators.length > 1) {
voliss = voliss.replace(data['Authors'], "");
} else if (item.creators.length == 1) {
voliss = voliss.replace(data['Author'], "");
if (purl) {
item.url = purl;
}
Zotero.debug(voliss);
item.volume = voliss.match(/vol\.\s+(\d+)/)[1];
item.issue = voliss.match(/no\.\s+(\d+)/)[1];
if (voliss.match(/pp\.\s+([\d\-]+)/)){
item.pages = voliss.match(/pp\.\s+([\d\-]+)/)[1];
if (pdfurl) {
item.attachments.push({
url: pdfurl,
title: "Full Text PDF",
mimeType: "application/pdf"
});
}
item.date = Zotero.Utilities.trimInternal(voliss.match(/[^,]+$/)[0]);
item.rights = license;
item.place = "Ann Arbor, MI";
item.publisher = "University of Michigan";
item.abstractNote = data['Abstract'];
item.url = data['URL'];
item.attachments = [
{url:item.url, title:item.title + " Snapshot", mimeType:"text/html"},
{url:'http://quod.lib.umich.edu/p/phimp/images/' + getID(item.url) + '.pdf', title:"Philosopher's Imprint Full Text PDF", mimeType:"application/pdf"}
];

item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}/** BEGIN TEST CASES **/
});
translator.translate();
}

/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
@@ -103,45 +125,35 @@ var testCases = [
"items": [
{
"itemType": "journalArticle",
"title": "Morality, Fiction, and Possibility",
"creators": [
{
"firstName": "Brian",
"lastName": "Weatherson",
"creatorType": "author"
}
],
"notes": [],
"tags": [
"Kendall Walton",
"Tamar Szabó Gendler",
"concepts",
"fiction",
"imagination",
"morality",
"possibility"
],
"seeAlso": [],
"date": "2004-11-01",
"ISSN": "1533-628X",
"abstractNote": "Authors have a lot of leeway with regard to what they can make true in their story. In general, if the author says that p is true in the fiction we're reading, we believe that p is true in that fiction. And if we're playing along with the fictional game, we imagine that, along with everything else in the story, p is true. But there are exceptions to these general principles. Many authors, most notably Kendall Walton and Tamar Szabó Gendler, have discussed apparent counterexamples when p is \"morally deviant\". Many other statements that are conceptually impossible also seem to be counterexamples. In this paper I do four things. I survey the range of counterexamples, or at least putative counterexamples, to the principles. Then I look to explanations of the counterexamples. I argue, following Gendler, that the explanation cannot simply be that morally deviant claims are impossible. I argue that the distinctive attitudes we have towards moral propositions cannot explain the counterexamples, since some of the examples don't involve moral concepts. And I put forward a proposed explanation that turns on the role of 'higher-level concepts', concepts that if they are satisfied are satisfied in virtue of more fundamental facts about the world, in fiction, and in imagination.",
"issue": "3",
"libraryCatalog": "quod.lib.umich.edu",
"publicationTitle": "Philosopher's Imprint",
"rights": "http://creativecommons.org/licenses/by-nc-nd/3.0/",
"url": "http://hdl.handle.net/2027/spo.3521354.0004.003",
"volume": "4",
"attachments": [
{
"title": "Morality, Fiction, and Possibility Snapshot",
"mimeType": "text/html"
"title": "Snapshot"
},
{
"title": "Philosopher's Imprint Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"title": "Morality, Fiction, and Possibility",
"volume": "4",
"issue": "3",
"pages": "1-27",
"date": "November 2004",
"place": "Ann Arbor, MI",
"publisher": "University of Michigan",
"abstractNote": "Authors have a lot of leeway with regard to what they can make true in their story. In general, if the author says that p is true in the fiction we're reading, we believe that p is true in that fiction. And if we're playing along with the fictional game, we imagine that, along with everything else in the story, p is true. But there are exceptions to these general principles. Many authors, most notably Kendall Walton and Tamar Szabó Gendler, have discussed apparent counterexamples when p is \"morally deviant\". Many other statements that are conceptually impossible also seem to be counterexamples. In this paper I do four things. I survey the range of counterexamples, or at least putative counterexamples, to the principles. Then I look to explanations of the counterexamples. I argue, following Gendler, that the explanation cannot simply be that morally deviant claims are impossible. I argue that the distinctive attitudes we have towards moral propositions cannot explain the counterexamples, since some of the examples don't involve moral concepts. And I put forward a proposed explanation that turns on the role of 'higher-level concepts', concepts that if they are satisfied are satisfied in virtue of more fundamental facts about the world, in fiction, and in imagination.",
"url": "http://hdl.handle.net/2027/spo.3521354.0004.003",
"libraryCatalog": "Philosopher's Imprint",
"accessDate": "CURRENT_TIMESTAMP"
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
@@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-08-27 02:45:11"
"lastUpdated": "2017-06-03 17:36:44"
}

/*
@@ -82,7 +82,7 @@ function doWeb(doc, url) {
}

function scrape(doc, url) {
var abstract = ZU.xpathText(doc, '//div[@class="abstract"]');
var abstract = ZU.xpathText(doc, '//div[@class="abstract"]/abstract');
if (!abstract) abstract = ZU.xpathText(doc, '//div[@class="description"][1]');
var translator = Zotero.loadTranslator('web');
// Embedded Metadata
@@ -123,7 +123,7 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2006",
"date": "2006/07/20",
"ISSN": "1477-464X",
"issue": "1",
"libraryCatalog": "Project MUSE",
@@ -154,7 +154,7 @@ var testCases = [
"items": [
{
"itemType": "book",
"title": "Writing the Forest in Early Modern England",
"title": "Writing the Forest in Early Modern England: A Sylvan Pastoral Nation",
"creators": [
{
"firstName": "Jeffrey S.",
@@ -168,6 +168,7 @@ var testCases = [
"language": "English",
"libraryCatalog": "Project MUSE",
"publisher": "Duquesne University Press",
"shortTitle": "Writing the Forest in Early Modern England",
"url": "http://muse.jhu.edu/book/785",
"attachments": [
{
@@ -194,7 +195,7 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2013",
"date": "2013/12/12",
"DOI": "10.1353/tech.2013.0137",
"ISSN": "1097-3729",
"abstractNote": "This article uses coverage of the fiftieth anniversary of the Pill as an example of what Richard Hirsh describes as the “real world” role of historians of technology. It explores how the presentation of historical topics on the world wide web has complicated how the history of technology is conveyed to the public. The article shows that that the Pill is especially suited to demonstrating the public role of historians of technology because, as the most popular form of reversible birth control, it has touched the lives of millions of Americans. Thus, an exploration of how the Pill’s fiftieth anniversary was covered illustrates how historians can use their expertise to provide a nuanced interpretation of a controversial topic in the history of technology.",
@@ -231,10 +232,10 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2014",
"date": "2014/08/13",
"DOI": "10.1353/lar.2014.0030",
"ISSN": "1542-4278",
"abstractNote": "This article highlights an important paradox: in Argentina between 2003 and 2013 the center-left Peronist government’s approach to governance mirrors that of the center-right Peronist administration of the 1990s. While the latter centralized authority to pursue neoliberal reforms, the former have centralized authority in the name of expanding government intervention in the economy. In both cases, corruption has tended to go unchecked due to insufficient government accountability. Therefore, although economic policies and political rhetoric have changed dramatically, government corruption remains a constant of the Argentine political system due to the executive branch’s ability to emasculate constitutional checks and balances.\n, \nRESUMEN\nEste artículo pone de relieve una paradoja importante: en la Argentina entre 2003 y 2013 los gobiernos peronistas de centro-izquierda reflejan los de la administración peronista de centro-derecha de la década de 1990. Mientras en los años noventa la concentración del poder presidencial se usó para promover reformas neoliberales, en los 2000 la autoridad centralizada se persiguió en nombre de la expansión de la intervención gubernamental en la economía. En ambos casos, la corrupción ha tendido a pasar inadvertida debido a la insuficiencia de la rendición de cuentas del gobierno. Por lo tanto, aunque las políticas económicas y la retórica política han cambiado drásticamente, la corrupción gubernamental sigue siendo una constante del sistema político argentino, gracias a la capacidad del Poder Ejecutivo para nulificar a los controles y equilibrios constitucionales",
"abstractNote": "This article highlights an important paradox: in Argentina between 2003 and 2013 the center-left Peronist government’s approach to governance mirrors that of the center-right Peronist administration of the 1990s. While the latter centralized authority to pursue neoliberal reforms, the former have centralized authority in the name of expanding government intervention in the economy. In both cases, corruption has tended to go unchecked due to insufficient government accountability. Therefore, although economic policies and political rhetoric have changed dramatically, government corruption remains a constant of the Argentine political system due to the executive branch’s ability to emasculate constitutional checks and balances., Este artículo pone de relieve una paradoja importante: en la Argentina entre 2003 y 2013 los gobiernos peronistas de centro-izquierda reflejan los de la administración peronista de centro-derecha de la década de 1990. Mientras en los años noventa la concentración del poder presidencial se usó para promover reformas neoliberales, en los 2000 la autoridad centralizada se persiguió en nombre de la expansión de la intervención gubernamental en la economía. En ambos casos, la corrupción ha tendido a pasar inadvertida debido a la insuficiencia de la rendición de cuentas del gobierno. Por lo tanto, aunque las políticas económicas y la retórica política han cambiado drásticamente, la corrupción gubernamental sigue siendo una constante del sistema político argentino, gracias a la capacidad del Poder Ejecutivo para nulificar a los controles y equilibrios constitucionales",
"issue": "2",
"libraryCatalog": "Project MUSE",
"pages": "173-195",
Oops, something went wrong.

0 comments on commit f1a7a00

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