{ "translatorID": "bf6b49e3-9198-4fbc-a559-a81fcfcce908", "label": "World Shakespeare Bibliography Online", "creator": "Matthias Heim", "target": "^https?://(?:www\\.)?worldshakesbib\\.org", "minVersion": "1.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcs", "lastUpdated": "2014-06-11 22:48:03" } /* World Shakespeare Bibliography Online translator Copyright (C) 2011 Matthias Heim This program 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. This program 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 General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ /* * Translator for the World Shakespeare Bibliography Online http://www.worldshakesbib.org * Version 0.1: 3 November 2011 detectWeb complete * Version 0.2: 4 November 2011 doWeb * Version 0.4: 6 November 2011 initial version, fully working, but somewhat messy code with ugly workarounds * Currently it works only for individual items, and collections of items saved by the user * Currently, it does not offer Item Selection Dialogues for browse or search pages * The World Shakespeare Bibliography Online offers extensive links to related documents, * these are currently added as attached URLs to the corresponding entry in the bibliography, * not as related items in Zotero, as translators can only add, but not access items in the * Zotero database. * Written by Matthias Heim Matthias.Heim@unine.ch */ var entries=new Array(); function Entry() { this.item_type=""; this.dictionary=new Array(); this.baseURL=""; // returns one-dimensional array of table, uneven entries being the left side, even entries the right this.tableIntoArray = function(tableHTML) { currentTDstart=0; var TD=new Array(); while ((currentTDstart=tableHTML.indexOf("",currentTDstart))!=-1) { currentTD=tableHTML.substring(currentTDstart+4, (currentTDstart=tableHTML.indexOf("",currentTDstart))); // remove enclosing tag, enclosing tag, enclosing brackets, and enclosing quotation marks if (currentTD.substr(0,3)+currentTD.substr(-4)=="") currentTD=currentTD.slice(3,-4); if (currentTD.substr(0,3)+currentTD.substr(-4)=="") { currentTD=currentTD.slice(3,-4); // check whether it really was enclosing, for e.g. // currentTD="Hamlet to The Tempest"; if (currentTD.indexOf("")>currentTD.indexOf("")) currentTD=""+currentTD+""; } if (currentTD.substr(0,1)+currentTD.substr(-1)=="[]") currentTD=currentTD.slice(1,-1); if (currentTD.substr(0,1)+currentTD.substr(-1)=="\"\"") currentTD=currentTD.slice(1,-1); // remove enclosing tag, except if preceding element is a "Head Entry", in which case only the href-URL is retained if (currentTD.substr(0,2)+currentTD.substr(-4)=="") { if (TD[TD.length-1]=="Head Entry") currentTD=currentTD.substring(currentTD.indexOf("href=\"")+6,currentTD.indexOf("\">")) else currentTD=currentTD.slice(currentTD.indexOf(">")+1,-4); } // remove font-color red tags, as these only highlight search items. Could probably be done with a regexp. while ((redstart=currentTD.indexOf(''))!=-1) { currentTD=currentTD.substring(0,redstart)+currentTD.substring(redstart+18); if ((redstart=currentTD.indexOf(''))!=-1) currentTD=currentTD.substring(0,redstart)+currentTD.substring(redstart+7); } // remove final period? Yes, but watch out, it removes it also after initials if (currentTD.substr(-1)==".") currentTD=currentTD.slice(0,-1); if (currentTD.substr(-1)==",") currentTD=currentTD.slice(0,-1); // the case with many name entries //Zotero.debug(currentTD+"\n"); TD.push(currentTD); } return TD; } this.addTable = function(tableHTML) { // turn table into array var tableArray=this.tableIntoArray(tableHTML); // Some names are followed by an entry for their roles, simply replace name-index entry with role if ((entryno=arrayTableIndexOf(tableArray,"Role"))!=-1) { tableArray[entryno-3]=tableArray[entryno]; tableArray.splice(entryno-1,2); } var headEntry=""; // If a head-entry exists, it needs to be extracted and later followed up! if ((entryno=arrayTableIndexOf(tableArray, "Head Entry"))!=-1) { headEntry=tableArray[entryno]; tableArray.splice(entryno-1,2); } entryno=arrayTableIndexOf(tableArray, "Document Type"); if (this.item_type=="") { // new item this.item_type=tableArray[entryno]; tableArray.splice(entryno-1,2); // remove entry for document type } else { // check whether item_type has changed if (this.item_type!=tableArray[entryno]) { if ((this.item_type=="Article") && ((tableArray[entryno]=="Book monograph") || (tableArray[entryno]=="Book collection")) ) { this.item_type="bookSection"; // and not "Article"! tableArray.splice(entryno-1,2); // remove entry for document type tableArray[arrayTableIndexOf(tableArray, "Title")-1]="bookTitle"; redundantname=arrayTableIndexOf(tableArray,"Name"); if (redundantname!=-1) tableArray.splice(redundantname-1,2); tableArray.splice(arrayTableIndexOf(tableArray,"Notes/Performers")-1,2); // would refer only to collection, not to essay tableArray.splice(arrayTableIndexOf(tableArray,"Language")-1,2); tableArray.splice(arrayTableIndexOf(tableArray,"Record Number")-1,2); entryno2=arrayTableIndexOf(this.dictionary, "Venue/Publisher"); this.dictionary[entryno2-1]="Pages"; this.dictionary[entryno2]=this.dictionary[entryno2].substring(this.dictionary[entryno2].lastIndexOf(" ")); } else { Zotero.debug("Unhandled change of item type exception. Item not saved."); // possibly a commit of the item to the database could be possible, but this event should actually never occur! return; } } // always retain the Index Location where the user found the document, hence discard it in follow-up entries arrayTableExtractItem(tableArray, "Index Location"); arrayTableExtractItem(tableArray, "Record Number"); } // assign all items from tableArray to this.dictionary for (entryno=0; entryno")+4); while (publisher.charAt(publisher.length-1)==" ") publisher=publisher.slice(0,publisher.length-1) } } if ((url_index=publisher.indexOf("http"))!=-1) { // final common format, more difficult to parse safely url_lastindex=publisher.indexOf(" ",url_index+4); if (url_lastindex==-1) url_lastindex=publisher.length; newItem.url=publisher.slice(url_index,url_lastindex); publisher=publisher.slice(0,url_index)+publisher.slice(url_lastindex+1); while (publisher.charAt(publisher.length-1)==" ") publisher=publisher.slice(0,publisher.length-1) } //e.g. Manchester and New York: Manchester University Press, 2003. x + 227 pp. if ((this.item_type=="book") || (this.item_type=="bookSection")) { if ((this.item_type=="book") && (publisher.slice(-3)==" pp")) newItem.numPages=publisher.slice(publisher.slice(0,-3).lastIndexOf(" ")+1,-3); newItem.place=publisher.slice(0,publisher.indexOf(":")); newItem.publisher=publisher.slice(publisher.indexOf(":")+2, publisher.lastIndexOf(",")); } // article publication info: e.g. // Shakespeare Quarterly 61, no. 2 (2010): 56-77 if ((this.item_type=="journalArticle") || (this.item_type=="thesis")) { publisher+=" "; // dissertations are poorly parsed, but this format works for // most dissertations in the database if (this.item_type!="thesis") // usually unpaginated newItem.pages=publisher.slice((i=publisher.indexOf("): ")+3),publisher.indexOf(" ", i)); else newItem.university=publisher.slice(publisher.lastIndexOf("(")+1, publisher.lastIndexOf(")")); newItem.publicationTitle=publisher.slice(publisher.indexOf("")+3,publisher.indexOf("")); publisher=publisher.slice(publisher.indexOf("")+5,publisher.indexOf(" (")); if ((issuestart=publisher.indexOf(", no."))!=-1) { newItem.volume=publisher.slice(0,issuestart); newItem.issue=publisher.slice(issuestart+6); } else newItem.volume=publisher; } // All the items below lack a standard format // The information usually includes date, label, running time, etc. // It is copied into the field that matches the usual information most closely if ((this.item_type=="audioRecording") || (this.item_type=="videoRecording") || (this.item_type=="film")) { if (this.item_type=="audioRecording") newItem.label=publisher; if (this.item_type=="videoRecording") newItem.videoRecordingFormat=publisher; if (this.item_type=="film") newItem.distributor=publisher; } } series=arrayTableExtractItem(this.dictionary, "Series Statement"); if ((series!=-1) && ((this.item_type=="book") || (this.item_type=="bookSection") || (this.item_type=="journalArticle"))) newItem.series=series; if ((series!=-1) && ((this.item_type=="audioRecording") || (this.item_type="videoRecording"))) newItem.seriesTitle=series; language=arrayTableExtractItem(this.dictionary, "Language"); if (language!=-1) newItem.language=language; archiveLocation=arrayTableExtractItem(this.dictionary, "Index Location"); if (archiveLocation!=-1) newItem.archiveLocation=archiveLocation; callNumber=arrayTableExtractItem(this.dictionary, "Record Number"); if (callNumber!=-1) newItem.callNumber=callNumber; date=arrayTableExtractItem(this.dictionary, "Date"); if (date!=-1) newItem.date=date; arrayTableExtractItem(this.dictionary, "Cross Reference"); // To be discarded AdditionalTitleInfo=arrayTableExtractItem(this.dictionary, "Additional Title Info"); NotesPerformers=arrayTableExtractItem(this.dictionary,"Notes/Performers"); newItem.abstractNote=((AdditionalTitleInfo!=-1)?(AdditionalTitleInfo+((NotesPerformers!=-1)?"\n":"")):"")+((NotesPerformers!=-1)?NotesPerformers:""); reviews=arrayTableExtractItem(this.dictionary,"Reviews"); if (reviews!=-1) { newItem.notes.push({note:reviews}); } // Extract tags tags=arrayTableExtractItem(this.dictionary,"Descriptive Terms"); if (tags!=-1) { newItem.tags=newItem.tags.concat(tags.split("; ")); } tags=arrayTableExtractItem(this.dictionary,"Persons"); if (tags!=-1) { newItem.tags=newItem.tags.concat(tags.split("; ")); } // see also links are saved as attached URLs seeAlso=arrayTableExtractItem(this.dictionary,"See Also"); if (seeAlso!=-1) { seeAlso=seeAlso.split("")+5), mimeType: "text/html", snapshot: false}); } } } while (arrayTableExtractItem(this.dictionary,"Document Type")!=-1); // sometimes survives as a duplicate, discard otherInformation="Other Information:"; for (i=0; iIndex Location"); if (entry_start != -1) { this.addTable(records_content.substring(entry_start, records_content.indexOf("", entry_start)+8)); } else Zotero.debug("No entry could be found on page") } else Zotero.debug("No result could be found"); } } function doWeb(doc, url) { // doWeb has its own parser, duplicating addPage above somewhat, because it is the // only page where multiple results are possible, taking this into account here // speeds the parsing up. // records are always contained within a div with the id 'records' if (doc.getElementById("records")!= null) { var records_content=doc.getElementById("records").innerHTML; // each entry is always presented in a table beginning in the same string var entry_start=0; while ((entry_start=records_content.indexOf("Index Location",entry_start))!=-1) { // at least one entry present entries.push(new Entry()); entries[entries.length-1].baseURL=url.substring(0, url.indexOf("/",7)); entries[entries.length-1].addTable(records_content.substring(entry_start, (entry_start=records_content.indexOf("", entry_start)+8))); } } else Zotero.debug("No results could be found"); // This is where search and browse results could be parsed! } function arrayTableIndexOf(narray, nvalue) { for (var neach=0; neachIndex Location"); // at least one entry present if (first_entry != -1) { // at least one entry is present // a note on "multiple" // This only works on the "View Saved Entries" (http://www.worldshakesbib.org/export) page, not in the search! // Completely different code would be necessary for browse or search pages // Since this page always already represents a selection made by the user, the handler will indiscriminately save all items, and not offer an Item Selection Dialogue // TODO: either behaviour may of course be changed in subsequent versions if (records_content.indexOf("Index Location",first_entry+1)!=-1) return "multiple"; // several entries present // if only one entry is present, its type can be retrieved from the 'Document type' entry in the table // e.g. Document TypeArticle // Note that Article can also mean bookSection, a distinction that only the doWeb function will test, as it involves a GET command document_type=records_content.substring(startindex=(records_content.indexOf("Document Type")+37),records_content.indexOf("",startindex)); switch (document_type) { case "Article": return "journalArticle"; // but could equally be "bookSection", see above break; case "Book monograph": case "Book collection": // Zotero does not distinguish the two return "book" break; case "Dissertation": return "thesis" break; case "Production": // this is most likely a theatre production, but videoRecording offers the closest alternative in Zotero return "videoRecording"; break; case "Audio Recording": return "audioRecording"; break; case "Film": return "film"; break; default: // unrecognized item? return empty, as no entry present } } // else no entry present } } /** BEGIN TEST CASES **/ var testCases = [ { "type": "web", "url": "http://www.worldshakesbib.org/search?searchtype=browse&index=30.14.05.30&rid=49952&words=&returnlink=%2Fsearch%3Fsearchtype%3Dbrowse%26index%3D30.14.05.30%26return%3D1", "items": [ { "itemType": "book", "creators": [ { "firstName": "Madhavi", "lastName": "Menon", "creatorType": "author" } ], "notes": [ { "note": "Review(s): Guy-Bray, Stephen. Renaissance Quarterly 62, no. 1 (2009): 318-20; Patricia, Anthony Guy. Popular Culture Review 20, no. 2 (2009): 88-93; Rieh, Anna. Sixteenth Century Journal 41, no. 4 (2010): 1243-44; Rosenberger, JeriLynn. Sixteenth Century Journal 41, no. 4 (2010): 1243-44; Paul, Ryan Singh. Shaksper: The Global Shakespeare Discussion List 6 October 2011: SHK 22.0270 (http://shaksper.net)" } ], "tags": [ "queer theory", "sexuality", "desire", "Madden, John" ], "seeAlso": [], "attachments": [ { "title": "See also: Madden, Shakespeare in Love", "mimeType": "text/html", "snapshot": false } ], "title": "Unhistorical Shakespeare: Queer Theory in Shakespearean Literature and Film", "numPages": "195", "place": "New York and Basingstoke", "publisher": "Palgrave Macmillan", "language": "English", "archiveLocation": "30.12.05.30 Individual Works — Plays; Cymbeline; Scholarship And Criticism; Criticism", "callNumber": "aaw627", "date": "2008", "abstractNote": "Introducing the term \"homohistory\" as a \"methodological resistance to sexuality as historical difference\" in Shakespeare criticism, pursues the \"eccentricities of desire\" in Venus and Adonis, Cymbeline, and Titus Adronicus, as well as in such contemporary films as John Madden's Shakespeare in Love (q.v.) and Bollywood adaptations of Much Ado about Nothing", "libraryCatalog": "World Shakespeare Bibliography Online", "shortTitle": "Unhistorical Shakespeare" } ] }, { "type": "web", "url": "http://www.worldshakesbib.org/search?rid=10156&words=", "items": [ { "itemType": "journalArticle", "creators": [ { "firstName": "A. Luis", "lastName": "Pujante", "creatorType": "author" }, { "firstName": "Miguel Angel", "lastName": "Centenero", "creatorType": "author" } ], "notes": [], "tags": [ "songs", "semantics", "music", "metrics", "rhythm", "Schlegel, A. W. von" ], "seeAlso": [], "attachments": [], "title": "Las canciones de Shakespeare en las traducciones alemanas de A. W. Schlegel", "pages": "93-106", "publicationTitle": "Cuadernos de filología inglesa", "volume": "4", "language": "Spanish", "archiveLocation": "10.35.30 General Shakespeareana; Language, Linguistics, Philology; Translation", "callNumber": "bi950", "date": "1995", "abstractNote": "Finds that A. W. von Schlegel's translations of the songs in Shakespeare (which \"combine a high degree of semantic fidelity to the text with a perfect adjustment to the original tunes\") are an exception to the tendency of translators to ignore their musical dimension. Concludes that although Schlegel did not know the tunes, his synchronization of metrical stress with musical beat results from his reading of the lines rhythmically. English summary, 93", "libraryCatalog": "World Shakespeare Bibliography Online" } ] } ] /** END TEST CASES **/