Skip to content

Commit

Permalink
added portraits from Münchner Stadtmuseum, closes #152
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Nov 24, 2016
1 parent e7382d4 commit 9693d3f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions catalogues/options.xml
Expand Up @@ -40,6 +40,7 @@
<!-- <entry xml:id="wikipedia">http://tools.wmflabs.org/persondata/redirect/gnd/</entry>-->
<entry xml:id="portraitindex">http://www.portraitindex.de/dokumente/pnd/</entry>
<entry xml:id="tripota">http://www.tripota.uni-trier.de/beacon.php?ID=</entry>
<entry xml:id="munich-stadtmuseum">https://stadtmuseum.bayerische-landesbibliothek-online.de/pnd/</entry>
<entry xml:id="adb">http://tools.wmflabs.org/persondata/redirect/gnd/ws-adb/</entry>
<entry xml:id="dnb">http://d-nb.info/gnd/</entry>
<entry xml:id="beacon">http://beacon.findbuch.de/seealso/pnd-aks?format=seealso&amp;id=</entry>
Expand Down
38 changes: 37 additions & 1 deletion modules/img.xqm
Expand Up @@ -58,7 +58,10 @@ declare
let $tripota-images :=
if(count(map:keys($beaconMap)[contains(., 'GND-Zuordnung')]) gt 0) then img:tripota-images($model, $lang)
else ()
let $iconographyImages := ($local-image, $wikipedia-images, $portraitindex-images, $tripota-images)
let $munich-stadtmuseum-images :=
if(count(map:keys($beaconMap)[contains(., 'Porträtsammlung')]) gt 0) then img:munich-stadtmuseum-images($model, $lang)
else ()
let $iconographyImages := ($local-image, $wikipedia-images, $portraitindex-images, $tripota-images, $munich-stadtmuseum-images)
let $portrait :=
if($suppressExternalPortrait) then img:get-generic-portrait($model, $lang)
else ($iconographyImages, img:get-generic-portrait($model, $lang))[1]
Expand Down Expand Up @@ -93,6 +96,7 @@ declare %private function img:wikipedia-images($model as map(*), $lang as xs:str
else ()
(: Look for images in wikipedia infobox (for organizations) and thumbnails :)
let $pics := $wikiArticle//xhtml:table[contains(@class,'toptextcells')] | $wikiArticle//xhtml:div[@class='thumbinner']
let $errorLog := if(count($pics) = 0) then core:logToFile('info', 'img:wikipedia-images(): no images found for GND ' || $gnd) else ()
return
for $div in $pics
let $tmpPicURI := ($div//xhtml:img[@class='thumbimage']/@src | $div[self::xhtml:table]//xhtml:img[not(@class='thumbimage')]/@src)[1]
Expand Down Expand Up @@ -155,6 +159,7 @@ declare %private function img:portraitindex-images($model as map(*), $lang as xs
if($gnd) then wega-util:grabExternalResource('portraitindex', $gnd, config:get-doctype-by-id($model('docID')), $lang)
else ()
let $pics := $page//xhtml:div[@class='listItemThumbnail']
let $errorLog := if(count($pics) = 0) then core:logToFile('info', 'img:portraitindex-images(): no images found for GND ' || $gnd) else ()
return
for $div in $pics
let $picURI := $div//xhtml:img/data(@src)
Expand Down Expand Up @@ -185,6 +190,7 @@ declare %private function img:tripota-images($model as map(*), $lang as xs:strin
if($gnd) then wega-util:grabExternalResource('tripota', $gnd, config:get-doctype-by-id($model('docID')), $lang)
else ()
let $pics := $page//xhtml:td
let $errorLog := if(count($pics) = 0) then core:logToFile('info', 'img:tripota-images(): no images found for GND ' || $gnd) else ()
return
for $div in $pics
let $picURI := concat('http://www.tripota.uni-trier.de/', $div//xhtml:img[starts-with(@src, 'portraits')]/data(@src))
Expand All @@ -201,6 +207,36 @@ declare %private function img:tripota-images($model as map(*), $lang as xs:strin
else ()
};

(:~
: Helper function for grabbing images from the Münchner Stadtmuseum
:
: @author Peter Stadler
: @param
: @param $lang the language variable (de|en)
: @return
:)
declare %private function img:munich-stadtmuseum-images($model as map(*), $lang as xs:string) as map(*)* {
let $gnd := query:get-gnd($model('doc'))
let $page :=
if($gnd) then wega-util:grabExternalResource('munich-stadtmuseum', $gnd, config:get-doctype-by-id($model('docID')), $lang)
else ()
let $pics := $page//xhtml:a[@class='imagelink'][ancestor::xhtml:div[@id='main']]
let $errorLog := if(count($pics) = 0) then core:logToFile('info', 'img:munich-stadtmuseum-images(): no images found for GND ' || $gnd) else ()
return
for $a in $pics
let $picURI := concat('https://stadtmuseum.bayerische-landesbibliothek-online.de', $a/xhtml:img/@src)
return
if($picURI castable as xs:anyURI) then
map {
'caption' := str:normalize-space($a/xhtml:img/@title) || ' (Quelle: Münchner Stadtmuseum)',
'linkTarget' := 'https://stadtmuseum.bayerische-landesbibliothek-online.de/pnd/' || $gnd,
'source' := 'Münchner Stadtmuseum',
'url' := function($size) {
$picURI
}
}
else ()
};

(:~
: Helper function for adding local (= from the WeGA) images
Expand Down
28 changes: 27 additions & 1 deletion modules/wega-util.xqm
Expand Up @@ -48,7 +48,11 @@ import module namespace lang="http://xquery.weber-gesamtausgabe.de/modules/lang"
case 'deutsche-biographie' return 'https://www.deutsche-biographie.de/gnd' || $gnd || '.html'
default return config:get-option($resource) || $gnd
let $fileName := string-join(($gnd, $lang, 'xml'), '.')
let $response := core:cache-doc(str:join-path-elements(($config:tmp-collection-path, $resource, $fileName)), wega-util:http-get#1, xs:anyURI($url), $lease)
let $response :=
(: Because the EXPath http client is very picky about HTTPS certificates, we need to use the standard httpclient module for the munich-stadtmuseum which uses HTTPS :)
switch($resource)
case 'munich-stadtmuseum' return core:cache-doc(str:join-path-elements(($config:tmp-collection-path, $resource, $fileName)), wega-util:httpclient-get#1, xs:anyURI($url), $lease)
default return core:cache-doc(str:join-path-elements(($config:tmp-collection-path, $resource, $fileName)), wega-util:http-get#1, xs:anyURI($url), $lease)
return
if($response//httpclient:response/@statusCode eq '200') then $response//httpclient:response
else ()
Expand Down Expand Up @@ -85,6 +89,28 @@ declare function wega-util:http-get($url as xs:anyURI) as element(wega:externalR
</wega:externalResource>
};

(:~
: Helper function for wega:grabExternalResource()
:
: @author Peter Stadler
: @param $url the URL as xs:anyURI
: @return element wega:externalResource, a wrapper around httpclient:response
:)
declare function wega-util:httpclient-get($url as xs:anyURI) as element(wega:externalResource) {
let $req := <http:request href="{$url}" method="get" timeout="3"><http:header name="Connection" value="close"/></http:request>
let $response :=
try { httpclient:get($url, true(), <Headers/>) }
catch * {core:logToFile('warn', string-join(('wega-util:httpclient-get', $err:code, $err:description, 'URL: ' || $url), ' ;; '))}
(:let $response :=
if($response/httpclient:body[matches(@mimetype,"text/html")]) then wega:changeNamespace($response,'http://www.w3.org/1999/xhtml', 'http://exist-db.org/xquery/httpclient')
else $response:)
(: let $statusCode := $response[1]/data(@status):)
return
<wega:externalResource date="{current-date()}">
{ $response }
</wega:externalResource>
};

declare function wega-util:beacon-map($gnd as xs:string, $docType as xs:string) as map(*) {
let $findbuchResponse :=
switch($docType)
Expand Down

0 comments on commit 9693d3f

Please sign in to comment.