Skip to content

Commit

Permalink
Aleph: Allow missing slash when detecting MAB2 URL
Browse files Browse the repository at this point in the history
Fixes zotero#2255. This ended up being simpler than I thought it would be: the
translator already understood that some Aleph records are in MAB2
format, but the URL regex was too restrictive.
  • Loading branch information
AbeJellinek committed May 20, 2021
1 parent 7aeaea1 commit cebd715
Showing 1 changed file with 147 additions and 9 deletions.
156 changes: 147 additions & 9 deletions Library Catalog (Aleph).js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsb",
"lastUpdated": "2016-12-17 23:52:01"
"lastUpdated": "2021-05-20 20:05:07"
}

/*
Expand Down Expand Up @@ -50,6 +50,29 @@ Poland:
https://aleph.bg.pwr.wroc.pl/F
*/

/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2021 Simon Kornblith, Michael Berkowitz, and Ming Yeung Cheung
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) {
var singleRe = new RegExp("^https?://[^/]+/F/?[A-Z0-9\-]*\?.*(?:func=full-set-set|func=direct|func=myshelf-full.*)");

Expand All @@ -67,9 +90,9 @@ function detectWeb(doc, url) {

function doWeb(doc, url) {
var detailRe = new RegExp("^https?://[^/]+/F/?[A-Z0-9\-]*\?.*(?:func=full-set-set|func=direct|func=myshelf-full|func=myself_full.*)");
var mab2Opac = new RegExp("^https?://(?!alephdai)[^/]+berlin|193\.30\.112\.134|duisburg-essen/F/[A-Z0-9\-]+\?.*|^https?://katalog\.ub\.uni-duesseldorf\.de/F/|^https?://aleph\.mpg\.de/F/");
var mab2Opac = new RegExp("^https?://(?!alephdai)[^/]+berlin|193\.30\.112\.134|duisburg-essen/F/[A-Z0-9\-]+\?.*|^https?://katalog\.ub\.uni-duesseldorf\.de/F|^https?://aleph\.mpg\.de/F");
var uri = doc.location.href;
var newUris = new Array();
var newUris = [];

if (detailRe.test(uri)) {
// find the 'add to basket' link where it will have the document number, replace the function with 'direct'
Expand Down Expand Up @@ -103,7 +126,7 @@ function doWeb(doc, url) {
});

} else {
var itemRegexp = '^https?://[^/]+/F/?[A-Z0-9\-]*\?.*(?:func=full-set-set.*\&format=999|func=direct|func=myshelf-full.*)'
var itemRegexp = '^https?://[^/]+/F/?[A-Z0-9\-]*\?.*(?:func=full-set-set.*\&format=999|func=direct|func=myshelf-full.*)';
var items = Zotero.Utilities.getItemArray(doc, doc, itemRegexp, '^[0-9]+$');
// ugly hack to see if we have any items
var haveItems = false;
Expand All @@ -114,7 +137,7 @@ function doWeb(doc, url) {

// If we don't have any items otherwise, let us use the numbers
if (!haveItems) {
var items = Zotero.Utilities.getItemArray(doc, doc, itemRegexp);
items = Zotero.Utilities.getItemArray(doc, doc, itemRegexp);

// We try to get more text by grabbing the whole table row
var newItems = {};
Expand Down Expand Up @@ -234,6 +257,7 @@ function scrape(newDoc, marc, url) {
}
}
}

var newItem = new Zotero.Item();
record.translate(newItem);

Expand All @@ -248,8 +272,8 @@ function scrape(newDoc, marc, url) {
}

var oldCreators = newItem.creators;
newItem.creators = new Array();
var transient = new Array();
newItem.creators = [];
var transient = [];
for (var i=0; i<oldCreators.length; i++) {
var a = oldCreators[i];
if (a.lastName) {
Expand All @@ -266,6 +290,120 @@ function scrape(newDoc, marc, url) {
newItem.title = newItem.title.replace(/(<<|>>)/g, '');
newItem.complete();
}

/** BEGIN TEST CASES **/
var testCases = []
/** END TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://naude.bibliotheque-mazarine.fr/F/GFVQXDP767A179G9GAIRLC17TQHRXP67DJCKQMH28VKPBPKCHF-02823?func=full-set-set&set_number=000594&set_entry=000001&format=999",
"items": [
{
"itemType": "book",
"title": "Registre du dépôt de Nesle: oeuvres d'art saisies pendant la Révolution chez les émigrés et condamnés parisiens en vue de l'instruction publique",
"creators": [
{
"firstName": "Jean-Pierre",
"lastName": "Samoyault ",
"creatorType": "author"
},
{
"lastName": "Société",
"firstName": "de l'histoire de l'art français ",
"creatorType": "author"
}
],
"date": "2021",
"ISBN": "9782701806174",
"language": "fre",
"libraryCatalog": "naude.bibliotheque-mazarine.fr Library Catalog",
"place": "Paris",
"publisher": "éditions de Boccard",
"series": "Archives de l'art français",
"seriesNumber": "nouvelle période, XLI",
"shortTitle": "Registre du dépôt de Nesle",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://aleph2.mpg.de/F/FXPBUPI4F7S5QN3M2TSEDBJM5I5INT86VG624HH3BT81E52PYM-05671?func=full-set-set&set_number=004725&set_entry=000002&format=999",
"items": [
{
"itemType": "book",
"title": "Zwoelf: die Zeitung der Hochschule für Musik und Theater Hamburg",
"creators": [
{
"lastName": "Hochschule",
"firstName": "für Musik und Theater Hamburg",
"creatorType": "author"
}
],
"date": "2008",
"callNumber": "780",
"language": "ger",
"libraryCatalog": "aleph2.mpg.de Library Catalog",
"place": "Hamburg",
"shortTitle": "Zwoelf",
"attachments": [],
"tags": [
{
"tag": "Zeitschrift |2 gnd-content"
}
],
"notes": [
{
"note": "Gesehen am 12.09.17"
}
],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://aleph.mpg.de/F?func=direct&doc_number=000000037&local_base=mpg01",
"items": [
{
"itemType": "book",
"title": "The primary auditory neurons of the mammalian cochlea",
"creators": [
{
"firstName": "Alain",
"lastName": "Dabdoub",
"creatorType": "author"
},
{
"firstName": "Bernd",
"lastName": "Fritzsch",
"creatorType": "author"
},
{
"firstName": "Arthur N.",
"lastName": "Popper",
"creatorType": "author"
},
{
"firstName": "Richard R.",
"lastName": "Fay",
"creatorType": "author"
}
],
"date": "2016",
"ISBN": "9781493930302",
"extra": "Literaturangaben",
"language": "eng",
"libraryCatalog": "aleph.mpg.de Library Catalog",
"series": "Springer handbook of auditory research ; 52",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/

0 comments on commit cebd715

Please sign in to comment.