Skip to content

Commit

Permalink
Fix Dagstuhl Research Online Publication Server translator
Browse files Browse the repository at this point in the history
This commit fixes the Dagstuhl Research Online Publication Server translator by updating the outdated URL structure and correcting XPATH queries.
  • Loading branch information
bardiharborow committed Nov 30, 2024
1 parent 9f1d764 commit bb6ced8
Showing 1 changed file with 49 additions and 43 deletions.
92 changes: 49 additions & 43 deletions Dagstuhl Research Online Publication Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,62 @@
"translatorID": "0526c18d-8dc8-40c9-8314-399e0b743a4d",
"label": "Dagstuhl Research Online Publication Server",
"creator": "Philipp Zumstein",
"target": "^https?://(www\\.)?drops\\.dagstuhl\\.de/opus/",
"target": "^https?://(www\\.)?drops\\.dagstuhl\\.de/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-08-23 06:54:08"
"lastUpdated": "2024-11-30 08:38:44"
}

/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2016 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 (url.indexOf('source_opus')>-1 || url.indexOf('volltexte')>-1) {
var bibtexEntry = ZU.xpathText(doc, '//pre/tt');
if (bibtexEntry.indexOf("@InCollection")>-1) {
if (url.includes('/entities/document/')) {
var bibtexEntry = ZU.xpathText(doc, "//pre[contains(@class, 'bibtex')]");
if (bibtexEntry.includes("@InCollection")) {
return "bookSection";
}
if (bibtexEntry.indexOf("@Article")>-1) {
if (bibtexEntry.includes("@Article")) {
return "journalArticle";
}
return "conferencePaper";
} else if (getSearchResults(doc, true)) {
}
else if (getSearchResults(doc, true)) {
return "multiple";
}

return false;
}

function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//b/a[contains(@href, "source_opus")]|//td/a[contains(@href, "source_opus")]');//
for (var i=0; i<rows.length; i++) {
var rows = ZU.xpath(doc, "//a[contains(@href, '/entities/document/')]");//
for (var i = 0; i < rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
Expand All @@ -70,69 +73,70 @@ function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
return;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
} else {
}
else {
scrape(doc, url);
}
}

function scrape(doc, url) {
var bibtexEntry = ZU.xpathText(doc, '//pre/tt');
function scrape(doc, _) {
var bibtexEntry = ZU.xpathText(doc, "//pre[contains(@class, 'bibtex')]");
//Z.debug(bibtexEntry);
var pdfurl = ZU.xpathText(doc, '//td//a[contains(@href, "pdf")]/@href');
var pdfurl = ZU.xpathText(doc, "//section[contains(@class, 'files')]//a[contains(@href, 'pdf')]/@href");

var translator = Zotero.loadTranslator("import");
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
translator.setString(bibtexEntry);
translator.setHandler("itemDone", function(obj, item) {

translator.setHandler("itemDone", function (obj, item) {
//if a note is just a list of keywords, then save them as tags
//and delete this note
for (var i=0; i<item.notes.length; i++) {
for (var i = 0; i < item.notes.length; i++) {
var note = item.notes[i].note;
if (note.indexOf('Keywords:')>-1) {
if (note.includes('Keywords:')) {
note = note.replace('<p>', '').replace('</p>', '').replace('Keywords:', '');
var keywords = note.split(',');
for (var j=0; j<keywords.length; j++) {
for (var j = 0; j < keywords.length; j++) {
item.tags.push(keywords[j].trim());
}
item.notes.splice(i, 1);
}
}

item.attachments.push({
title: "Snapshot",
document: doc
});

if (pdfurl) {
item.attachments.push({
url: pdfurl,
title: "Full Text PDF",
mimeType: "application/pdf"
});
}

item.complete();
});
translator.translate();
}

}/** BEGIN TEST CASES **/
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://drops.dagstuhl.de/opus/frontdoor.php?source_opus=4958",
"url": "https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.STACS.2015.1",
"items": [
{
"itemType": "conferencePaper",
"title": "Overcoming Intractability in Unsupervised Learning (Invited Talk)",
"title": "Overcoming Intractability in Unsupervised Learning",
"creators": [
{
"firstName": "Sanjeev",
Expand All @@ -153,18 +157,19 @@ var testCases = [
"date": "2015",
"DOI": "10.4230/LIPIcs.STACS.2015.1",
"ISBN": "9783939897781",
"itemID": "arora:LIPIcs:2015:4958",
"itemID": "arora:LIPIcs.STACS.2015.1",
"libraryCatalog": "Dagstuhl Research Online Publication Server",
"pages": "1–1",
"place": "Dagstuhl, Germany",
"proceedingsTitle": "32nd International Symposium on Theoretical Aspects of Computer Science (STACS 2015)",
"publisher": "Schloss DagstuhlLeibniz-Zentrum fuer Informatik",
"publisher": "Schloss DagstuhlLeibniz-Zentrum für Informatik",
"series": "Leibniz International Proceedings in Informatics (LIPIcs)",
"url": "http://drops.dagstuhl.de/opus/volltexte/2015/4958",
"url": "https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.STACS.2015.1",
"volume": "30",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
},
{
"title": "Full Text PDF",
Expand All @@ -184,17 +189,17 @@ var testCases = [
},
{
"type": "web",
"url": "http://drops.dagstuhl.de/opus/portals/lipics/index.php?semnr=15001",
"url": "https://drops.dagstuhl.de/entities/volume/LIPIcs-volume-30",
"items": "multiple"
},
{
"type": "web",
"url": "http://drops.dagstuhl.de/opus/ergebnis.php?wer=opus&suchart=teil&Lines_Displayed=10&sort=o.date_year+DESC%2C+o.title&suchfeld1=freitext&suchwert1=&opt1=AND&opt2=AND&suchfeld3=date_year&suchwert3=&startindex=0&page=0&dir=2&suche=&suchfeld2=oa.person&suchwert2=Hauzar%2C%20David",
"url": "https://drops.dagstuhl.de/search?term=Hauzar%2C%20David",
"items": "multiple"
},
{
"type": "web",
"url": "http://drops.dagstuhl.de/opus/volltexte/2016/5933/",
"url": "https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.SoCG.2016.41",
"items": [
{
"itemType": "conferencePaper",
Expand Down Expand Up @@ -239,18 +244,19 @@ var testCases = [
"date": "2016",
"DOI": "10.4230/LIPIcs.SoCG.2016.41",
"ISBN": "9783959770095",
"itemID": "geyer_et_al:LIPIcs:2016:5933",
"itemID": "geyer_et_al:LIPIcs.SoCG.2016.41",
"libraryCatalog": "Dagstuhl Research Online Publication Server",
"pages": "41:1–41:15",
"place": "Dagstuhl, Germany",
"proceedingsTitle": "32nd International Symposium on Computational Geometry (SoCG 2016)",
"publisher": "Schloss DagstuhlLeibniz-Zentrum fuer Informatik",
"publisher": "Schloss DagstuhlLeibniz-Zentrum für Informatik",
"series": "Leibniz International Proceedings in Informatics (LIPIcs)",
"url": "http://drops.dagstuhl.de/opus/volltexte/2016/5933",
"url": "https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.SoCG.2016.41",
"volume": "51",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
},
{
"title": "Full Text PDF",
Expand All @@ -269,4 +275,4 @@ var testCases = [
]
}
]
/** END TEST CASES **/
/** END TEST CASES **/

0 comments on commit bb6ced8

Please sign in to comment.