-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add translator Landesbibliographie Baden-Wurttemberg.js #1774
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,303 @@ | ||
{ | ||
"translatorID": "d2c0d2f4-42c0-41e0-8021-3b87b52b27d2", | ||
"label": "Landesbibliographie Baden-Württemberg", | ||
"creator": "Philipp Zumstein", | ||
"target": "^https?://(www\\.)?statistik\\.baden-wuerttemberg\\.de/LABI", | ||
"minVersion": "3.0", | ||
"maxVersion": "", | ||
"priority": 100, | ||
"inRepository": true, | ||
"translatorType": 4, | ||
"browserSupport": "gcsibv", | ||
"lastUpdated": "2018-11-01 11:35:17" | ||
} | ||
|
||
/* | ||
***** BEGIN LICENSE BLOCK ***** | ||
|
||
Copyright © 2018 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 ***** | ||
*/ | ||
|
||
|
||
// attr()/text() v2 | ||
function attr(docOrElem,selector,attr,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.getAttribute(attr):null;}function text(docOrElem,selector,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.textContent:null;} | ||
|
||
|
||
function detectWeb(doc, url) { | ||
if (url.includes('/LABI.asp?')) { | ||
if (getSearchResults(doc, true)) { | ||
return "multiple"; | ||
} else { | ||
var labels = doc.querySelectorAll('td>b'); | ||
for (let label of labels) { | ||
if (label.textContent == 'ISBN:') { | ||
return "book"; | ||
} | ||
if (label.textContent.includes('Enthalten')) { | ||
return "journalArticle"; | ||
} | ||
} | ||
return "report"; | ||
} | ||
} | ||
} | ||
|
||
|
||
function getSearchResults(doc, checkOnly) { | ||
var items = {}; | ||
var found = false; | ||
var rows = doc.querySelectorAll('td.right + td>a'); | ||
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; | ||
} | ||
|
||
|
||
function doWeb(doc, url) { | ||
if (detectWeb(doc, url) == "multiple") { | ||
Zotero.selectItems(getSearchResults(doc, false), function (items) { | ||
if (!items) { | ||
return true; | ||
} | ||
var articles = []; | ||
for (var i in items) { | ||
articles.push(i); | ||
} | ||
ZU.processDocuments(articles, scrape); | ||
}); | ||
} else { | ||
scrape(doc, url); | ||
} | ||
} | ||
|
||
|
||
function scrape(doc, url) { | ||
var type = detectWeb(doc, url); | ||
var risURL = attr(doc, 'a.export', 'href'); | ||
ZU.doGet(risURL, function(text) { | ||
// Z.debug(text) | ||
var translator = Zotero.loadTranslator("import"); | ||
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7"); | ||
translator.setString(text); | ||
translator.setHandler("itemDone", function(obj, item) { | ||
item.itemType = type; | ||
// fixes the added author information in the title, | ||
// which might be fixed by them in the future | ||
item.title = item.title.replace(/\/[^\/]*$/, ''); | ||
|
||
if (type == "book" && item.pages) { | ||
var m = item.pages.match(/(\d+) Seiten/); | ||
if (m) { | ||
item.numPages = m[1]; | ||
delete item.pages; | ||
} | ||
} | ||
item.attachments.push({ | ||
title: "Titel in der Landesbibliographie Baden-Württemberg", | ||
url: url, | ||
snapshot: false | ||
}); | ||
item.complete(); | ||
}); | ||
|
||
translator.translate(); | ||
}); | ||
} | ||
|
||
/** BEGIN TEST CASES **/ | ||
var testCases = [ | ||
{ | ||
"type": "web", | ||
"url": "http://www.statistik.baden-wuerttemberg.de/LABI/LABI.asp?HC=63amFSWsgYL&K1=10&T1=mannheim&TA=5", | ||
"items": [ | ||
{ | ||
"itemType": "journalArticle", | ||
"title": "Überfordert : Mozart: Don Giovanni : Mannheim, Nationaltheater", | ||
"creators": [ | ||
{ | ||
"lastName": "Schweikert", | ||
"firstName": "Uwe", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2018", | ||
"issue": "9/10", | ||
"libraryCatalog": "Landesbibliographie Baden-Württemberg", | ||
"pages": "56-57", | ||
"publicationTitle": "Opernwelt", | ||
"shortTitle": "Überfordert", | ||
"volume": "59", | ||
"attachments": [ | ||
{ | ||
"title": "Titel in der Landesbibliographie Baden-Württemberg", | ||
"snapshot": false | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"tag": "Mannheim" | ||
}, | ||
{ | ||
"tag": "Musik" | ||
}, | ||
{ | ||
"tag": "Nationaltheater Mannheim" | ||
}, | ||
{ | ||
"tag": "Oper" | ||
}, | ||
{ | ||
"tag": "Schauspiel, Oper, Operette und Ballett" | ||
} | ||
], | ||
"notes": [ | ||
{ | ||
"note": "<p>\"Premiere am 14. Juli 2018\" (Textende)</p>" | ||
} | ||
], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "http://www.statistik.baden-wuerttemberg.de/LABI/LABI.asp?HC=53amwU0Dwj6&K1=10&T1=mannheim&TA=12", | ||
"items": [ | ||
{ | ||
"itemType": "book", | ||
"title": "Hafen Mannheim 2018 : 150 Jahre Mannheimer Akte", | ||
"creators": [ | ||
{ | ||
"lastName": "Mardo", | ||
"firstName": "Thommy", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2018", | ||
"ISBN": "9783864760938", | ||
"libraryCatalog": "Landesbibliographie Baden-Württemberg", | ||
"numPages": "208", | ||
"place": "Mannheim", | ||
"publisher": "Verlag Waldkirch", | ||
"shortTitle": "Hafen Mannheim 2018", | ||
"attachments": [ | ||
{ | ||
"title": "Titel in der Landesbibliographie Baden-Württemberg", | ||
"snapshot": false | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"tag": "Bildband" | ||
}, | ||
{ | ||
"tag": "Hafen" | ||
}, | ||
{ | ||
"tag": "Mannheim" | ||
}, | ||
{ | ||
"tag": "Mannheimer Rheinschiffahrtsakte" | ||
}, | ||
{ | ||
"tag": "Oberrheingebiet" | ||
}, | ||
{ | ||
"tag": "Rhein-Neckar-Hafen Mannheim" | ||
}, | ||
{ | ||
"tag": "Rheinschifffahrt" | ||
}, | ||
{ | ||
"tag": "Schifffahrt" | ||
}, | ||
{ | ||
"tag": "Wasserstraßen" | ||
} | ||
], | ||
"notes": [ | ||
{ | ||
"note": "<p>Text in deutsch, englisch und französisch</p>" | ||
} | ||
], | ||
"seeAlso": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "web", | ||
"url": "http://www.statistik.baden-wuerttemberg.de/LABI/LABI.asp?HC=53anjtk4Avy&K1=10&T1=mannheim&EF=Z&TA=87", | ||
"items": [ | ||
{ | ||
"itemType": "report", | ||
"title": "Rechenschaftsbericht ... des Rektors", | ||
"creators": [ | ||
{ | ||
"lastName": "Universität ", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comes from
which is catalogued as a "Körperschaft" in the original. Maybe we could move it to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I had seen that but markdown swallowed the relevant bit. I think we should leave it as author, which seems fine to me, but we should filter out the pointy brackets (< >) so that it actually imports as "Universität Mannheim" and not just "Universität " |
||
"creatorType": "author", | ||
"fieldMode": 1 | ||
} | ||
], | ||
"date": "2000///(2001); 2001/02(2003) -", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we clean this? I'm not even sure how Zotero would end up parsing this date (though I think just as 2000?). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is more complicated because here the whole series is meant. So
means that there was a report for 1972/1973, ..., and another report for 1999/2000 published in 2001, but no report in 2000/2001 (the note explained why). Then from 2001/2002 in 2003 it started again normally. How about moving the date in this case to a note? Deleting would be okay also for me, because these report (series) are not my main focus here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still pick a date to import, maybe the first one? Putting the rest into notes sounds right. |
||
"libraryCatalog": "Landesbibliographie Baden-Württemberg", | ||
"place": "Mannheim", | ||
"attachments": [ | ||
{ | ||
"title": "Titel in der Landesbibliographie Baden-Württemberg", | ||
"snapshot": false | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"tag": "Mannheim" | ||
}, | ||
{ | ||
"tag": "Universität" | ||
}, | ||
{ | ||
"tag": "Universität Mannheim" | ||
}, | ||
{ | ||
"tag": "Universitäten" | ||
}, | ||
{ | ||
"tag": "Zeitschrift" | ||
} | ||
], | ||
"notes": [ | ||
{ | ||
"note": "Internetausg.: Universität <Mannheim>: Rechenschaftsbericht ... des Rektors" | ||
}, | ||
{ | ||
"note": "2000/01 u.d.T.: Universität <Mannheim>: Rechenschaftsbericht ... des geschäftsführenden Prorektors" | ||
} | ||
], | ||
"seeAlso": [] | ||
} | ||
] | ||
} | ||
] | ||
/** END TEST CASES **/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove spaces before colons in titles and update tests?