From 329757b4a1cc737587684097f814d678fb46ab32 Mon Sep 17 00:00:00 2001 From: Philipp Zumstein Date: Mon, 21 Oct 2024 08:51:11 +0200 Subject: [PATCH 01/16] =?UTF-8?q?Neuer=20Bestandsabgleich=20f=C3=BCr=20ALM?= =?UTF-8?q?A-Bibliotheken=20mit=20SRU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- isbn/alma-sru.php | 246 +++++++++++++++++++++++++++++++++++ isbn/srulibraries.json | 114 ++++++++++++++++ tools/bestandsabgleichB.html | 151 +++++++++++++++++++++ 3 files changed, 511 insertions(+) create mode 100644 isbn/alma-sru.php create mode 100644 isbn/srulibraries.json create mode 100644 tools/bestandsabgleichB.html diff --git a/isbn/alma-sru.php b/isbn/alma-sru.php new file mode 100644 index 0000000..7c85ec5 --- /dev/null +++ b/isbn/alma-sru.php @@ -0,0 +1,246 @@ + + * + * This is free software licensed under the terms of the GNU GPL, + * version 3, or (at your option) any later version. + * See for more details. + * + * Aufruf aus Webbrowser: + * alma-sru?isbn=ISBN + * ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen + * ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein + * alma-sru?base=BIB&isbn=ISBN&format=json + * alma-sru?base=BIB&isbn=ISBN&format=holdings + * alma-sru?base=BIB&isbn=ISBN&format=holdings&with=collections +* + * Sucht übergebene ISBN bzw. PPN in der SRU-Schnittstelle einer Alma-Bibliothek + * und gibt maximal 10 Ergebnisse als MARCXML, JSON zurück oder eine + * formattierte Bestandsangabe (eine kurze Zeile und die Details in einer + * Tabelle). + */ + +include 'conf.php'; +include 'lib.php'; + +$suchString = ''; +$suchStringSWB = ''; + +if (isset($_GET['ppn'])) { + $ppn = trim($_GET['ppn']); + $suchString = 'dc.id=' . $ppn; +} +if (isset($_GET['base'])) { + $file = file_get_contents('./srulibraries.json'); + $json = json_decode($file, true); + $urlBase = $json[$_GET['base']]['sru']; +} else { + echo "Keine Base-URL für die SRU-Schnittstelle (Alma) angegeben\n"; + exit; +} + +$urlBase = $urlBase . '?version=1.2&operation=searchRetrieve&recordSchema=marcxml&query='; + +$filteredSuchString = 'alma.mms_tagSuppressed=false'; +if (isset($_GET['isbn'])) { + $n = trim($_GET['isbn']); + $nArray = preg_split("/\s*(or|,|;)\s*/i", $n, -1, PREG_SPLIT_NO_EMPTY); + $suchString = 'alma.all=' . implode('+OR+alma.all=', $nArray); + $suchStringSWB = implode(' or ', $nArray); +} + +if (strlen($suchString)) { + $filteredSuchString .= '+AND+(' . $suchString . ')'; +} + +# work around ExLibris server configuration issue +$contextOptions = [ + 'ssl' => [ + 'verify_peer' => true, + 'ciphers' => 'DEFAULT@SECLEVEL=1', + ], +]; +$context = stream_context_create($contextOptions); +$result = file_get_contents($urlBase . $filteredSuchString, false, $context); + +if ($result === false) { + header('HTTP/1.1 400 Bad Request'); + echo "Verbindung zu SRU-Schnittstelle fehlgeschlagen\n"; + var_dump($urlBase . $filteredSuchString); + exit; +} + +// Delete namespaces such that we don't need to specify them +// in every xpath query. +$result = str_replace(' xmlns:xs="http://www.w3.org/2001/XMLSchema"', '', $result); +$result = str_replace(' xmlns="http://www.loc.gov/MARC21/slim"', '', $result); + +$doc = new DOMDocument(); +$doc->preserveWhiteSpace = false; +@$doc->loadHTML($result); +$xpath = new DOMXPath($doc); + +$records = $xpath->query("//records/record/recorddata/record"); //beachte: kein CamelCase sondern alles klein schreiben + +$outputString = "\n"; +$outputString .= "\n"; +$outputArray = []; + +foreach ($records as $record) { + // Filter out any other results which contain the ISBN but not in the 020 or 776 field + $foundMatch = false; + $foundIsbns = $xpath->query('.//datafield[@tag="020" or @tag="776"]/subfield', $record); + foreach ($foundIsbns as $foundNode) { + $foundValue = $foundNode->nodeValue; + foreach ($nArray as $queryValue) { + $testString = preg_replace('/[^0-9xX]/', '', $queryValue); + if (strlen($testString) == 13) { + // Delete the 978-prefix and the check value at the end for ISBN13 + $testString = substr($testString, 3, -1); + } elseif (strlen($testString) == 10) { + // Delete check value at the end for ISBN10 + $testString = substr($testString, 0, -1); + } + if (strpos(preg_replace('/[^0-9xX]/', '', $foundValue), $testString) !== false) { + $foundMatch = true; + } + } + } + if ($foundMatch) { + $outputString .= $doc->saveXML($record); + array_push($outputArray, $doc->saveXML($record)); + } +} +$outputString .= ""; + + +$map = STANDARD_MARC_MAP; +$map['bestand'] = '//datafield[@tag="AVA"]/subfield[@code="b"]'; +$map['sammlung'] = '//datafield[@tag="AVE"]/subfield[@code="m"]'; + +if (!isset($_GET['format'])) { + header('Content-type: text/xml'); + echo $outputString; +} elseif ($_GET['format'] == 'json') { + $outputXml = simplexml_load_string($outputString); + + $outputMap = performMapping($map, $outputXml); + $outputIndividualMap = []; + for ($j = 0; $j < count($outputArray); $j++) { + $outputXml = simplexml_load_string($outputArray[$j]); + $outputSingleMap = performMapping($map, $outputXml); + array_push($outputIndividualMap, $outputSingleMap); + } + $outputMap["einzelaufnahmen"] = $outputIndividualMap; + + + header('Content-type: application/json'); + echo json_encode($outputMap, JSON_PRETTY_PRINT); +} elseif ($_GET['format'] == 'holdings') { + echo "\n\n Bestand Alma-SRU zu ISBN-Suche\n \n \n\n\n"; + $outputXml = simplexml_load_string($outputString); + $avaNodes = $outputXml->xpath('//datafield[@tag="AVA"]'); + $aveNodes = $outputXml->xpath('//datafield[@tag="AVE"]'); + $size = strlen($outputString); + if ($avaNodes) { + echo "\n"; + $bestand = []; + foreach ($avaNodes as $node) { + echo "\n"; + $subfields = $node->xpath('./subfield'); + foreach ($subfields as $subfield) { + $code = $subfield[0]["code"]; + $value = getValues($subfield[0]); + echo " "; + } + echo "\n\n"; + + $location = getValues($node->xpath('./subfield[@code="b"]')[0]); + $sublocation = getValues($node->xpath('./subfield[@code="c"]')[0]); + /*if (strpos($sublocation, "Lehrbuchsammlung") !== false) { + $location = "LBS"; + }*/ + + $node_f = $node->xpath('./subfield[@code="f"]'); + $number = count($node_f) ? getValues($node_f[0]) : 0; + if (array_key_exists($location, $bestand)) { + $bestand[$location] += $number; + } else { + $bestand[$location] = $number; + } + } + echo "
" . $value . "
\n"; + echo "
\n"; + if ($aveNodes) { + $collections = []; + echo "\n"; + foreach ($aveNodes as $node) { + echo "\n"; + $subfields = $node->xpath('./subfield'); + foreach ($subfields as $subfield) { + $code = $subfield[0]["code"]; + $value = getValues($subfield[0]); + echo " "; + } + echo "\n\n"; + $collection = $node->xpath('./subfield[@code="m"]'); + if ($collection) { + $collections[] = getValues($collection[0]); + } + } + echo "
" . $value . "
\n"; + echo "
\n"; + } + + + echo '
Bestand Alma-SRU: '; + foreach ($bestand as $loc => $n) { + echo $n . "x" . $loc . ", "; + } + if ($aveNodes) { + echo "E"; + if ($_GET['with']) { + echo ' (' . implode(" | ", $collections) . ')'; + } + } + echo '
'; + } elseif ($aveNodes and !$avaNodes) { + echo "\n"; + $collections = []; + foreach ($aveNodes as $node) { + echo "\n"; + $subfields = $node->xpath('./subfield'); + foreach ($subfields as $subfield) { + $code = $subfield[0]["code"]; + $value = getValues($subfield[0]); + echo " "; + } + echo "\n\n"; + $collection = $node->xpath('./subfield[@code="m"]'); + if ($collection) { + $collections[] = getValues($collection[0]); + } + } + echo "
" . $value . "
\n"; + echo "
\n"; + echo '
Bestand Alma-SRU: E'; + if ($_GET['with']) { + echo ' (' . implode(" | ", $collections) . ')'; + } + echo '
'; + } elseif ($size > 100) { + //if the isbn is not found, then the $outputString is a minimal xml document + //of size 48, for larger size something might be found... + $urlMAN = 'man-sru.php?isbn=' . $suchStringSWB; + echo '
Bestand Alma-SRU: eventuell da (' . $size . ")
\n"; + echo '
See SRU Result
'; + } else { + echo 'Es wurde nichts gefunden'; + } + echo "\n\n"; +} diff --git a/isbn/srulibraries.json b/isbn/srulibraries.json new file mode 100644 index 0000000..e6b4c0b --- /dev/null +++ b/isbn/srulibraries.json @@ -0,0 +1,114 @@ +{ + "CH-UBS" : { + "name": "Basel U", + "sru": "https://ubs.swisscovery.slsp.ch/view/sru/41SLSP_UBS" + }, + "CH-BFH" : { + "name": "Bern FH", + "sru": "https://bfh.swisscovery.slsp.ch/view/sru/41SLSP_BFH" + }, + "CH-UBE" : { + "name": "Bern U", + "sru": "https://ube.swisscovery.slsp.ch/view/sru/41SLSP_UBE" + }, + "CH-BCUFR" : { + "name": "Fribourg BCU", + "sru": "https://bcufr.swisscovery.slsp.ch/view/sru/41SLSP_BCUFR" + }, + "CH-HSG " : { + "name": "St. Gallen U", + "sru": "https://hsg.swisscovery.slsp.ch/view/sru/41SLSP_HSG" + }, + "CH-UGE" : { + "name": "Genève UGE", + "sru": "https://uge.swisscovery.slsp.ch/view/sru/41SLSP_UGE" + }, + "CH-EPF" : { + "name": "Lausanne EPFL", + "sru": "https://epf.swisscovery.slsp.ch/view/sru/41SLSP_EPF" + }, + "CH-USI" : { + "name": "Lugano USI", + "sru": "https://usi.swisscovery.slsp.ch/view/sru/41SLSP_USI" + }, + "CH-RZS" : { + "name": "Luzern RZS", + "sru": "https://rzs.swisscovery.slsp.ch/view/sru/41SLSP_RZS" + }, + "CH-UNE" : { + "name": "Neuchâtel UNE", + "sru": "https://une.swisscovery.slsp.ch/view/sru/41SLSP_UNE" + }, + "CH-FHNW" : { + "name": "Nordwestschweiz FHNW", + "sru": "https://fhnw.swisscovery.slsp.ch/view/sru/41SLSP_FNW" + }, + "CH-OSTFH" : { + "name": "Ostschweiz FH", + "sru": "https://ostgre.swisscovery.slsp.ch/view/sru/41SLSP_FHO" + }, + "CH-ETH" : { + "name": "Zürich ETH", + "sru": "https://eth.swisscovery.slsp.ch/view/sru/41SLSP_ETH" + }, + "CH-UZB": { + "name": "Zürich UZB", + "sru": "https://uzb.swisscovery.slsp.ch/view/sru/41SLSP_UZB" + }, + "CH-ZHAW" : { + "name": "Zürich ZHAW", + "sru": "https://zhaw.swisscovery.slsp.ch/view/sru/41SLSP_ZAW" + }, + "DE-6" : { + "name": "Münster ULB", + "sru": "https://katalogplus.uni-muenster.de/view/sru/49HBZ_ULM" + }, + "AT-UBG" : { + "name": "Graz U", + "sru": "https://obv-at-ubg.userservices.exlibrisgroup.com/view/sru/43ACC_UBG" + }, + "AT-TUG" : { + "name": "Graz TU", + "sru": "https://obv-at-ubtug.userservices.exlibrisgroup.com/view/sru/43ACC_TUG" + }, + "AT-UBI" : { + "name": "Innsbruck U", + "sru": "https://obv-at-ubi.alma.exlibrisgroup.com/view/sru/43ACC_UBI" + }, + "AT-UBK" : { + "name": "Klagenfurt U", + "sru": "https://obv-at-ubk.userservices.exlibrisgroup.com/view/sru/43ACC_UBK" + }, + "AT-UBL" : { + "name": "Linz U", + "sru": "https://obv-at-ubl.userservices.exlibrisgroup.com/view/sru/43ACC_UBL" + }, + "AT-UBS" : { + "name": "Salzburg U", + "sru": "https://obv-at-ubs.userservices.exlibrisgroup.com/view/sru/43ACC_UBS" + }, + "AT-UBWW" : { + "name": "Wien WU", + "sru": "https://obv-at-ubww.userservices.exlibrisgroup.com/view/sru/43ACC_WUW" + }, + "AT-UBW" : { + "name": "Wien U", + "sru": "https://obv-at-ubw.userservices.exlibrisgroup.com/view/sru/43ACC_UBW" + }, + "AT-TUW" : { + "name": "Wien TU", + "sru": "https://obv-at-ubtuw.userservices.exlibrisgroup.com/view/sru/43ACC_TUW" + }, + "DE-180" : { + "name": "Mannheim U", + "sru": "https://uni-mannheim.alma.exlibrisgroup.com/view/sru/49MAN_INST" + }, + "DE-12" : { + "name": "München BSB", + "sru": "https://bsb.alma.exlibrisgroup.com/view/sru/49BVB_BSB" + }, + "DE-188" : { + "name": "Berlin FU", + "sru": "https://fu-berlin.alma.exlibrisgroup.com/view/sru/49KOBV_FUB" + } +} \ No newline at end of file diff --git a/tools/bestandsabgleichB.html b/tools/bestandsabgleichB.html new file mode 100644 index 0000000..2b286bb --- /dev/null +++ b/tools/bestandsabgleichB.html @@ -0,0 +1,151 @@ + + +Bestandsabgleich Alma-SRU + + + + + + + + + + +

Bestandsabgleich Alma-SRU

+ +

Anhand einer Liste von ISBNs wird der Bestand über eine Alma-SRU-Schnittstelle abgefragt und die Ergebnisse in der gleichen Reihenfolge wiedergegeben.

+ +

Eingabe

+ +
+ + +Bookmark +
+
+ Mit Link + Mit ISBN + Sammlungen anzeigen + +
+ +

Ausgabe

+ +

Status: 0 von 0 ISBNs geprüft

+ + + +
+ + + + + + + From 1a107f7ef9fdc1207f64194c2cd8e0592d85d35a Mon Sep 17 00:00:00 2001 From: Philipp Zumstein Date: Mon, 16 Dec 2024 15:51:12 +0100 Subject: [PATCH 02/16] Parameter umbenannt, SRU-Liste angepasst --- isbn/alma-sru.php | 12 ++++++------ isbn/srulibraries.json | 8 ++++---- tools/bestandsabgleichB.html | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/isbn/alma-sru.php b/isbn/alma-sru.php index 7c85ec5..5005904 100644 --- a/isbn/alma-sru.php +++ b/isbn/alma-sru.php @@ -15,9 +15,9 @@ * alma-sru?isbn=ISBN * ISBN ist eine 10- bzw. 13-stellige ISBN mit/ohne Bindestriche/Leerzeichen * ISBN kann ebenfalls eine Komma-separierte Liste von ISBNs sein - * alma-sru?base=BIB&isbn=ISBN&format=json - * alma-sru?base=BIB&isbn=ISBN&format=holdings - * alma-sru?base=BIB&isbn=ISBN&format=holdings&with=collections + * alma-sru?bibliothek=BIB&isbn=ISBN&format=json + * alma-sru?bibliothek=BIB&isbn=ISBN&format=holdings + * alma-sru?bibliothek=BIB&isbn=ISBN&format=holdings&with=collections * * Sucht übergebene ISBN bzw. PPN in der SRU-Schnittstelle einer Alma-Bibliothek * und gibt maximal 10 Ergebnisse als MARCXML, JSON zurück oder eine @@ -35,12 +35,12 @@ $ppn = trim($_GET['ppn']); $suchString = 'dc.id=' . $ppn; } -if (isset($_GET['base'])) { +if (isset($_GET['bibliothek'])) { $file = file_get_contents('./srulibraries.json'); $json = json_decode($file, true); - $urlBase = $json[$_GET['base']]['sru']; + $urlBase = $json[$_GET['bibliothek']]['sru']; } else { - echo "Keine Base-URL für die SRU-Schnittstelle (Alma) angegeben\n"; + echo "Bibliothek nicht gefunden in der Liste der bekannten Alma-SRU-Schnittstellen.\n"; exit; } diff --git a/isbn/srulibraries.json b/isbn/srulibraries.json index e6b4c0b..cb8b306 100644 --- a/isbn/srulibraries.json +++ b/isbn/srulibraries.json @@ -59,10 +59,6 @@ "name": "Zürich ZHAW", "sru": "https://zhaw.swisscovery.slsp.ch/view/sru/41SLSP_ZAW" }, - "DE-6" : { - "name": "Münster ULB", - "sru": "https://katalogplus.uni-muenster.de/view/sru/49HBZ_ULM" - }, "AT-UBG" : { "name": "Graz U", "sru": "https://obv-at-ubg.userservices.exlibrisgroup.com/view/sru/43ACC_UBG" @@ -106,6 +102,10 @@ "DE-12" : { "name": "München BSB", "sru": "https://bsb.alma.exlibrisgroup.com/view/sru/49BVB_BSB" + }, + "DE-6" : { + "name": "Münster ULB", + "sru": "https://katalogplus.uni-muenster.de/view/sru/49HBZ_ULM" }, "DE-188" : { "name": "Berlin FU", diff --git a/tools/bestandsabgleichB.html b/tools/bestandsabgleichB.html index 2b286bb..917e5af 100644 --- a/tools/bestandsabgleichB.html +++ b/tools/bestandsabgleichB.html @@ -29,7 +29,7 @@ var suffix = (document.getElementById("mitSammlungen").checked) ? "&with=collections" : ""; var numberOfDigits = value.replace(/\D/g, '').length; if (numberOfDigits>=9) { - $.get("../isbn/alma-sru.php?base="+sruBase+"&format=holdings&isbn="+value+suffix, function(data) { + $.get("../isbn/alma-sru.php?bibliothek="+sruBase+"&format=holdings&isbn="+value+suffix, function(data) { var pattern = /
Bestand Alma-SRU: (.*) Date: Mon, 16 Dec 2024 15:52:40 +0100 Subject: [PATCH 03/16] PPNs Anreicherungstool um ISBNs angereichert --- tools/ppnListe.html | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/ppnListe.html b/tools/ppnListe.html index 0bede26..d75e725 100644 --- a/tools/ppnListe.html +++ b/tools/ppnListe.html @@ -22,12 +22,13 @@ function check(index, value) { $('#ausgabe').append('
'); $('#query-'+index).attr("data-ppn", value); - value = value.replace(/^(\w*).*$/, '$1'); + value = value.replace(/^([\w-]*).*$/, '$1'); if (value.length > 0) { + var typ = $("#eingabetyp :selected").text(); var verbund = $("#verbund :selected").text(); var feld = $("#feld :selected").text(); var filter = $("#filter").val(); - $.get("../isbn/" + verbund + ".php?format=json&ppn=" + value, function(data) { + $.get("../isbn/" + verbund + ".php?format=json&" + typ + "=" + value, function(data) { if (document.getElementById("mit").checked) { $('#query-'+index).text(value + ": "); } @@ -64,13 +65,19 @@ -

PPN-Liste anreichern

+

PPN/ISBN-Liste anreichern

-

Eine Liste mit PPNs kann hier eingegeben werden und mit Werten eines Feldes z.B. ISBN, RVK, Bestand, Schlagwörter aus dem gleichen Verbund angereichert werden.

+

Eine Liste mit PPNs oder ISBNs kann hier eingegeben werden und mit Werten eines Feldes z.B. RVK, Bestand, Schlagwörter aus dem gleichen Verbund angereichert werden.

Eingabe

+ + +

-
+

(Eingabe von RegExp auch möglich, z.B. "(21.*|180)" für Bestand)

- a) PPN ausgeben; + a) PPN/ISBN mit ausgeben; b) Trennzeichen

Ausgabe

-

Status: 0 von 0 PPNs geprüft

+

Status: 0 von 0 PPNs/ISBNs geprüft