From b696036d678bcd82396ae6dd80a1ff5e7eb2f33b Mon Sep 17 00:00:00 2001 From: mrodzis Date: Wed, 13 Nov 2019 13:08:55 +0100 Subject: [PATCH 1/6] Implement entities in work index, general formatting --- modules/fontane/index-processor.xqm | 409 +++++++++++++++++----------- 1 file changed, 252 insertions(+), 157 deletions(-) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index 4a077801..bb168f2d 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -450,44 +450,43 @@ element xhtml:li { declare function ixp:has-former-or-current-location($links as element(tei:link)*) as element(xhtml:li)* { -for $link in $links -let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) -let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] -return - if(count($id) != 1) then - (update insert comment {"unable to parse target: " || serialize($link)} following $link, - update delete $link) - else -let $targetNode := $ixp:dataCollection/id($id) -return - if(count($targetNode) gt 1) - then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], - update delete $id[2] - ) - else if(count($targetNode) = 0) - then - (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, - update delete $link - ) - else -let $list := ixp:get-list-by-entity($targetNode) -return - element xhtml:li { - attribute class { "former-or-current-location" }, - element xhtml:a { - attribute href { "register.html?e=" || $id }, - , - " ", - $targetNode/*[1]/string(), - let $ancestors := $targetNode/ancestor::tei:place - for $parentPlace at $pos in $ancestors - let $name := $parentPlace/*[1]/string() + for $link in $links + let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) + let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] return - ((if($pos = 1) then "(" else ", ") || - $name || - (if($pos = count($ancestors)) then ")" else ())) - } - } + if(count($id) != 1) then + (update insert comment {"unable to parse target: " || serialize($link)} following $link, + update delete $link) + else + let $targetNode := $ixp:dataCollection/id($id) + return + if(count($targetNode) gt 1) + then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], + update delete $id[2] + ) + else if(count($targetNode) = 0) then + (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, + update delete $link + ) + else + let $list := ixp:get-list-by-entity($targetNode) + return + element xhtml:li { + attribute class { "former-or-current-location" }, + element xhtml:a { + attribute href { "register.html?e=" || $id }, + , + " ", + $targetNode/*[1]/string(), + let $ancestors := $targetNode/ancestor::tei:place + for $parentPlace at $pos in $ancestors + let $name := $parentPlace/*[1]/string() + return + ((if($pos = 1) then "(" else ", ") || + $name || + (if($pos = count($ancestors)) then ")" else ())) + } + } }; (:~ renewed version of the linking function @@ -507,24 +506,28 @@ let $hits := $ixp:dataCollection//tei:rs let $array := array{ for $hit in $hits - let $base := $hit/base-uri() - let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] - let $resolve := ixp:resolve-name($tguri) - return - map{ - "base": $base, - "tguri" : $tguri, - "title" : $resolve, - "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) - } + let $base := $hit/base-uri() + let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] + let $resolve := ixp:resolve-name($tguri) + return + map{ + "base": $base, + "tguri" : $tguri, + "title" : $resolve, + "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) + } } let $titles := $array?*?title => distinct-values() let $countNotebooks := count($titles) return element xhtml:li { attribute class { "links" }, - if($countNotebooks lt 2) then 'In Notizbuch' else ('In den Notizbüchern ', - ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)), + if($countNotebooks lt 2) then + 'In Notizbuch' + else + ('In den Notizbüchern ', + ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse) + ), element xhtml:ul { (: main list :) for $title in $titles @@ -1209,6 +1212,7 @@ else let $bibl := $place/tei:bibl let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"] let $formerCurrentLocation := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] + let $entitiesWithin := ixp:get-entities-within-a-place($id) let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] return element xhtml:li { @@ -1284,6 +1288,7 @@ else (: links :) ixp:links($place), ixp:li-code($place), + $entitiesWithin, element xhtml:ul { for $plac in $place/tei:place let $sort := string($plac/*[1]) @@ -1349,14 +1354,14 @@ as element(xhtml:div) { @@ -1370,15 +1375,169 @@ return ixp:prepare-work($i) : prepares a single work item :) declare function ixp:prepare-work($work as element(tei:item)) as element(xhtml:li) { -(: check if the item points to another entity :) -if( not(exists($work/@xml:id)) ) -then - (: pointer :) - ixp:pointer($work) -else - (: entity :) - let $id := $work/@xml:id - let $labelMain := $work/tei:name[1] + (: check if the item points to another entity :) + if( not(exists($work/@xml:id)) ) then + (: pointer :) + ixp:pointer($work) + else + (: entity :) + let $id := $work/@xml:id + let $labelMain := $work/tei:name[1] + return + element xhtml:li { + attribute id { string($id) }, + ixp:entry-class($id), + (: link to this entry :) + ixp:entry-link($id), + local:make-work-main-label($labelMain), + element xhtml:ul { + local:make-work-commons($work), + for $listPlace in $work/tei:listPlace + return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPlace" }, + for $place in $listPlace/tei:place + let $sort := string($place/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-place($place) + } + } + } + } +}; + + +(:~ Some places like museums have entities within them which are referenced + : in the index of works. These entities should also be displayed when viewing + : a place on register.html. + : + : This function provides a list of entities that are located in a place. + : + : @author Michelle Weidling + : @param $work-id The current work ID as string, e.g. "Museum_Neuruppin" + : @return A xhtml:li with all the entities that are or have been located at the current place. + :) +declare function ixp:get-entities-within-a-place($work-id as xs:string) as +element(xhtml:li)* { + let $nodes := ixp:getNodes() + (: the 5th position of ixp:getNodes() is the work index, excluding Fontane's + works and periodicals. :) + let $work-index := array:get($nodes, 5) + let $items := $work-index//tei:link[@corresp = "http://erlangen-crm.org/current/P53_has_former_or_current_location"][substring-after(@target, " ") = "plc:" || $work-id]/ancestor::tei:item[1] + + for $item in $items return + ixp:prepare-minified-work($item) +}; + + +(:~ + : A minified index entry for a work. This function is only needed for displaying + : information of an entity that is located at a certain place. In comparison to + : ixp:prepare-work it lacks a list of places in which it is located since we'd + : run into a recursion if we'd invoked the full ixp:prepare-work. + : + : @author Michelle Weidling + : @param $work An entity that is located at a certain place + : @return A xhtml:li with the same information as ixp:prepare-work provides EXCEPT the entity's place + : :) +declare function ixp:prepare-minified-work($work as element(tei:item)) +as element(xhtml:li) { + (: check if the item points to another entity :) + if( not(exists($work/@xml:id)) ) then + (: pointer :) + ixp:pointer($work) + else + (: entity :) + let $id := $work/@xml:id + let $labelMain := $work/tei:name[1] + return + element xhtml:li { + attribute id { string($id) }, + ixp:entry-class($id), + (: link to this entry :) + ixp:entry-link($id), + local:make-work-main-label($labelMain), + element xhtml:ul { + local:make-work-commons($work) + } + } +}; + +declare function local:make-work-main-label($labelMain as element(tei:name)) +as element(xhtml:span) { + element xhtml:span { + attribute class { "label-main" }, + $labelMain/text() + } +}; + +declare function local:make-work-alt-labels($labelAlt as element(tei:name)*) +as element(xhtml:li)* { + for $l in $labelAlt return + element xhtml:li { + attribute class {"label-" || string($l/@type)}, + $l/text(), + if($l/@type = "variant") + then () + else ( + " ", + element xhtml:a { + attribute href { string($l/@xml:base) || string($l) }, + + } + ) + } +}; + +declare function local:make-dates($dates as element(tei:date)*) +as element(xhtml:li)* { + for $d in $dates return + element xhtml:li { + attribute class {"date"}, + $d/text() + } +}; + +declare function local:make-translations($translationOf as element(tei:link)*) +as element(xhtml:li)* { + for $link in $translationOf + let $url := $link/@target => substring-after(" ") + return + element xhtml:li { + attribute class {"translationOf"}, + "Übersetzung von ", + + { + ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) + } + + } +}; + +declare function local:make-work-list-person($work as element(tei:item)) +as element(xhtml:li)* { + for $listPerson in $work/tei:listPerson return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPerson" }, + for $person in $listPerson/tei:person + let $sort := string($person/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-person($person) + + } + } +}; + +declare function local:make-work-commons($work as element(tei:item)) as +element(xhtml:li)+ { let $labelAlt := $work/tei:name[not(@type="variant")][position() gt 1] let $variant := $work/tei:name[@type="variant"] let $idnos := $work/tei:idno @@ -1400,97 +1559,33 @@ else let $translationOf := $work/tei:linkGrp/tei:link[@corresp="http://purl.org/ontology/bibo/#translationOf"] let $formerCurrentLocation := $work/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] let $links := $work/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] + return - element xhtml:li { - attribute id { string($id) }, - ixp:entry-class($id), - (: link to this entry :) - ixp:entry-link($id), - element xhtml:span { - attribute class { "label-main" }, - $labelMain/text() - }, - element xhtml:ul { - (: variant :) - ixp:variant($variant), - (: secondary label :) - for $l in $labelAlt - return - element xhtml:li { - attribute class {"label-" || string($l/@type)}, - $l/text(), - if($l/@type = "variant") - then () - else ( - " ", - element xhtml:a { - attribute href { string($l/@xml:base) || string($l) }, - - } - ) - }, - (: idno :) - ixp:idno($idnos), - for $d in $date - return - element xhtml:li { - attribute class {"date"}, - $d/text() - }, - (: creator :) - if (not(exists($creator))) then () else + ( + (: variant :) + ixp:variant($variant), + (: secondary label :) + local:make-work-alt-labels($labelAlt), + (: idno :) + ixp:idno($idnos), + local:make-dates($date), + (: creator :) + if (not(exists($creator))) then + () + else ixp:creator($creator), - (: translationOf :) - for $link in $translationOf - let $url := $link/@target => substring-after(" ") - return - element xhtml:li { - attribute class {"translationOf"}, - "Übersetzung von ", - { - ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) - } - }, - (: note :) - ixp:note($note), - (: bibl :) - ixp:bibl($bibl), - (: former_or_current_location :) - ixp:has-former-or-current-location($formerCurrentLocation), - (: links :) - ixp:links($work), - ixp:li-code($work), - (: further entities :) - for $listPerson in $work/tei:listPerson - return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPerson" }, - for $person in $listPerson/tei:person - let $sort := string($person/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-person($person) - - } - }, - for $listPlace in $work/tei:listPlace - return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPlace" }, - for $place in $listPlace/tei:place - let $sort := string($place/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-place($place) - } - } - } - } + (: translationOf :) + local:make-translations($translationOf), + (: note :) + ixp:note($note), + (: bibl :) + ixp:bibl($bibl), + (: former_or_current_location :) + ixp:has-former-or-current-location($formerCurrentLocation), + (: links :) + ixp:links($work), + ixp:li-code($work), + (: further entities :) + local:make-work-list-person($work) + ) }; - -- GitLab From 09e82c160a0ffc08768e3b83b0fe5a294ac7273d Mon Sep 17 00:00:00 2001 From: mrodzis Date: Wed, 13 Nov 2019 13:08:55 +0100 Subject: [PATCH 2/6] Implement entities in work index, general formatting --- modules/fontane/index-processor.xqm | 408 +++++++++++++++++----------- 1 file changed, 252 insertions(+), 156 deletions(-) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index c7f8d8ff..e13925b7 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -450,44 +450,43 @@ element xhtml:li { declare function ixp:has-former-or-current-location($links as element(tei:link)*) as element(xhtml:li)* { -for $link in $links -let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) -let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] -return - if(count($id) != 1) then - (update insert comment {"unable to parse target: " || serialize($link)} following $link, - update delete $link) - else -let $targetNode := $ixp:dataCollection/id($id) -return - if(count($targetNode) gt 1) - then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], - update delete $id[2] - ) - else if(count($targetNode) = 0) - then - (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, - update delete $link - ) - else -let $list := ixp:get-list-by-entity($targetNode) -return - element xhtml:li { - attribute class { "former-or-current-location" }, - element xhtml:a { - attribute href { "register.html?e=" || $id }, - , - " ", - $targetNode/*[1]/string(), - let $ancestors := $targetNode/ancestor::tei:place - for $parentPlace at $pos in $ancestors - let $name := $parentPlace/*[1]/string() + for $link in $links + let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) + let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] return - ((if($pos = 1) then "(" else ", ") || - $name || - (if($pos = count($ancestors)) then ")" else ())) - } - } + if(count($id) != 1) then + (update insert comment {"unable to parse target: " || serialize($link)} following $link, + update delete $link) + else + let $targetNode := $ixp:dataCollection/id($id) + return + if(count($targetNode) gt 1) + then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], + update delete $id[2] + ) + else if(count($targetNode) = 0) then + (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, + update delete $link + ) + else + let $list := ixp:get-list-by-entity($targetNode) + return + element xhtml:li { + attribute class { "former-or-current-location" }, + element xhtml:a { + attribute href { "register.html?e=" || $id }, + , + " ", + $targetNode/*[1]/string(), + let $ancestors := $targetNode/ancestor::tei:place + for $parentPlace at $pos in $ancestors + let $name := $parentPlace/*[1]/string() + return + ((if($pos = 1) then "(" else ", ") || + $name || + (if($pos = count($ancestors)) then ")" else ())) + } + } }; (:~ renewed version of the linking function @@ -507,24 +506,28 @@ let $hits := $ixp:dataCollection//tei:rs let $array := array{ for $hit in $hits - let $base := $hit/base-uri() - let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] - let $resolve := ixp:resolve-name($tguri) - return - map{ - "base": $base, - "tguri" : $tguri, - "title" : $resolve, - "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) - } + let $base := $hit/base-uri() + let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] + let $resolve := ixp:resolve-name($tguri) + return + map{ + "base": $base, + "tguri" : $tguri, + "title" : $resolve, + "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) + } } let $titles := $array?*?title => distinct-values() let $countNotebooks := count($titles) return element xhtml:li { attribute class { "links" }, - if($countNotebooks lt 2) then 'In Notizbuch' else ('In den Notizbüchern ', - ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)), + if($countNotebooks lt 2) then + 'In Notizbuch' + else + ('In den Notizbüchern ', + ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse) + ), element xhtml:ul { (: main list :) for $title in $titles @@ -1209,6 +1212,7 @@ else let $bibl := $place/tei:bibl let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"] let $formerCurrentLocation := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] + let $entitiesWithin := ixp:get-entities-within-a-place($id) let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] return element xhtml:li { @@ -1284,6 +1288,7 @@ else (: links :) ixp:links($place), ixp:li-code($place), + $entitiesWithin, element xhtml:ul { for $plac in $place/tei:place let $sort := string($plac/*[1]) @@ -1349,14 +1354,14 @@ as element(xhtml:div) {
    -{ -for $i in $wrkList//tei:item[not(tei:list)][@xml:id = $filter] -order by (lower-case(($i/tei:name[not(@type)]/text())[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") ) -return ixp:prepare-work($i) -} + { + for $i in $wrkList//tei:item[not(tei:list)][@xml:id = $filter] + order by (lower-case(($i/tei:name[not(@type)]/text())[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") ) + return ixp:prepare-work($i) + }
@@ -1370,15 +1375,169 @@ return ixp:prepare-work($i) : prepares a single work item :) declare function ixp:prepare-work($work as element(tei:item)) as element(xhtml:li) { -(: check if the item points to another entity :) -if( not(exists($work/@xml:id)) ) -then - (: pointer :) - ixp:pointer($work) -else - (: entity :) - let $id := $work/@xml:id - let $labelMain := $work/tei:name[1] + (: check if the item points to another entity :) + if( not(exists($work/@xml:id)) ) then + (: pointer :) + ixp:pointer($work) + else + (: entity :) + let $id := $work/@xml:id + let $labelMain := $work/tei:name[1] + return + element xhtml:li { + attribute id { string($id) }, + ixp:entry-class($id), + (: link to this entry :) + ixp:entry-link($id), + local:make-work-main-label($labelMain), + element xhtml:ul { + local:make-work-commons($work), + for $listPlace in $work/tei:listPlace + return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPlace" }, + for $place in $listPlace/tei:place + let $sort := string($place/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-place($place) + } + } + } + } +}; + + +(:~ Some places like museums have entities within them which are referenced + : in the index of works. These entities should also be displayed when viewing + : a place on register.html. + : + : This function provides a list of entities that are located in a place. + : + : @author Michelle Weidling + : @param $work-id The current work ID as string, e.g. "Museum_Neuruppin" + : @return A xhtml:li with all the entities that are or have been located at the current place. + :) +declare function ixp:get-entities-within-a-place($work-id as xs:string) as +element(xhtml:li)* { + let $nodes := ixp:getNodes() + (: the 5th position of ixp:getNodes() is the work index, excluding Fontane's + works and periodicals. :) + let $work-index := array:get($nodes, 5) + let $items := $work-index//tei:link[@corresp = "http://erlangen-crm.org/current/P53_has_former_or_current_location"][substring-after(@target, " ") = "plc:" || $work-id]/ancestor::tei:item[1] + + for $item in $items return + ixp:prepare-minified-work($item) +}; + + +(:~ + : A minified index entry for a work. This function is only needed for displaying + : information of an entity that is located at a certain place. In comparison to + : ixp:prepare-work it lacks a list of places in which it is located since we'd + : run into a recursion if we'd invoked the full ixp:prepare-work. + : + : @author Michelle Weidling + : @param $work An entity that is located at a certain place + : @return A xhtml:li with the same information as ixp:prepare-work provides EXCEPT the entity's place + : :) +declare function ixp:prepare-minified-work($work as element(tei:item)) +as element(xhtml:li) { + (: check if the item points to another entity :) + if( not(exists($work/@xml:id)) ) then + (: pointer :) + ixp:pointer($work) + else + (: entity :) + let $id := $work/@xml:id + let $labelMain := $work/tei:name[1] + return + element xhtml:li { + attribute id { string($id) }, + ixp:entry-class($id), + (: link to this entry :) + ixp:entry-link($id), + local:make-work-main-label($labelMain), + element xhtml:ul { + local:make-work-commons($work) + } + } +}; + +declare function local:make-work-main-label($labelMain as element(tei:name)) +as element(xhtml:span) { + element xhtml:span { + attribute class { "label-main" }, + $labelMain/text() + } +}; + +declare function local:make-work-alt-labels($labelAlt as element(tei:name)*) +as element(xhtml:li)* { + for $l in $labelAlt return + element xhtml:li { + attribute class {"label-" || string($l/@type)}, + $l/text(), + if($l/@type = "variant") + then () + else ( + " ", + element xhtml:a { + attribute href { string($l/@xml:base) || string($l) }, + + } + ) + } +}; + +declare function local:make-dates($dates as element(tei:date)*) +as element(xhtml:li)* { + for $d in $dates return + element xhtml:li { + attribute class {"date"}, + $d/text() + } +}; + +declare function local:make-translations($translationOf as element(tei:link)*) +as element(xhtml:li)* { + for $link in $translationOf + let $url := $link/@target => substring-after(" ") + return + element xhtml:li { + attribute class {"translationOf"}, + "Übersetzung von ", + + { + ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) + } + + } +}; + +declare function local:make-work-list-person($work as element(tei:item)) +as element(xhtml:li)* { + for $listPerson in $work/tei:listPerson return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPerson" }, + for $person in $listPerson/tei:person + let $sort := string($person/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-person($person) + + } + } +}; + +declare function local:make-work-commons($work as element(tei:item)) as +element(xhtml:li)+ { let $labelAlt := $work/tei:name[not(@type="variant")][position() gt 1] let $variant := $work/tei:name[@type="variant"] let $idnos := $work/tei:idno @@ -1400,96 +1559,33 @@ else let $translationOf := $work/tei:linkGrp/tei:link[@corresp="http://purl.org/ontology/bibo/#translationOf"] let $formerCurrentLocation := $work/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] let $links := $work/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] + return - element xhtml:li { - attribute id { string($id) }, - ixp:entry-class($id), - (: link to this entry :) - ixp:entry-link($id), - element xhtml:span { - attribute class { "label-main" }, - $labelMain/text() - }, - element xhtml:ul { - (: variant :) - ixp:variant($variant), - (: secondary label :) - for $l in $labelAlt - return - element xhtml:li { - attribute class {"label-" || string($l/@type)}, - $l/text(), - if($l/@type = "variant") - then () - else ( - " ", - element xhtml:a { - attribute href { string($l/@xml:base) || string($l) }, - - } - ) - }, - (: idno :) - ixp:idno($idnos), - for $d in $date - return - element xhtml:li { - attribute class {"date"}, - $d/text() - }, - (: creator :) - if (not(exists($creator))) then () else + ( + (: variant :) + ixp:variant($variant), + (: secondary label :) + local:make-work-alt-labels($labelAlt), + (: idno :) + ixp:idno($idnos), + local:make-dates($date), + (: creator :) + if (not(exists($creator))) then + () + else ixp:creator($creator), - (: translationOf :) - for $link in $translationOf - let $url := $link/@target => substring-after(" ") - return - element xhtml:li { - attribute class {"translationOf"}, - "Übersetzung von ", - { - ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) - } - }, - (: note :) - ixp:note($note), - (: bibl :) - ixp:bibl($bibl), - (: former_or_current_location :) - ixp:has-former-or-current-location($formerCurrentLocation), - (: links :) - ixp:links($work), - ixp:li-code($work), - (: further entities :) - for $listPerson in $work/tei:listPerson - return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPerson" }, - for $person in $listPerson/tei:person - let $sort := string($person/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-person($person) - - } - }, - for $listPlace in $work/tei:listPlace - return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPlace" }, - for $place in $listPlace/tei:place - let $sort := string($place/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-place($place) - } - } - } - } + (: translationOf :) + local:make-translations($translationOf), + (: note :) + ixp:note($note), + (: bibl :) + ixp:bibl($bibl), + (: former_or_current_location :) + ixp:has-former-or-current-location($formerCurrentLocation), + (: links :) + ixp:links($work), + ixp:li-code($work), + (: further entities :) + local:make-work-list-person($work) + ) }; -- GitLab From 813460f79df361f4c96ca177e8c516a1ee72e32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Thu, 21 Nov 2019 17:12:54 +0100 Subject: [PATCH 3/6] Revert "Implement entities in work index, general formatting" This reverts commit 09e82c160a0ffc08768e3b83b0fe5a294ac7273d. --- modules/fontane/index-processor.xqm | 408 +++++++++++----------------- 1 file changed, 156 insertions(+), 252 deletions(-) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index e13925b7..c7f8d8ff 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -450,43 +450,44 @@ element xhtml:li { declare function ixp:has-former-or-current-location($links as element(tei:link)*) as element(xhtml:li)* { - for $link in $links - let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) - let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] +for $link in $links +let $thisId := string($link/parent::tei:linkGrp/parent::tei:*/@xml:id) +let $id := ($link/@target => replace("\w{3}:|#", "") => tokenize(" "))[. != ""][. != $thisId] +return + if(count($id) != 1) then + (update insert comment {"unable to parse target: " || serialize($link)} following $link, + update delete $link) + else +let $targetNode := $ixp:dataCollection/id($id) +return + if(count($targetNode) gt 1) + then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], + update delete $id[2] + ) + else if(count($targetNode) = 0) + then + (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, + update delete $link + ) + else +let $list := ixp:get-list-by-entity($targetNode) +return + element xhtml:li { + attribute class { "former-or-current-location" }, + element xhtml:a { + attribute href { "register.html?e=" || $id }, + , + " ", + $targetNode/*[1]/string(), + let $ancestors := $targetNode/ancestor::tei:place + for $parentPlace at $pos in $ancestors + let $name := $parentPlace/*[1]/string() return - if(count($id) != 1) then - (update insert comment {"unable to parse target: " || serialize($link)} following $link, - update delete $link) - else - let $targetNode := $ixp:dataCollection/id($id) - return - if(count($targetNode) gt 1) - then (update insert comment {"xml:id used multiple times. this occurence is removed. please check and reinsert item when xml:id is unique. " || serialize($id[2])} following $id[2], - update delete $id[2] - ) - else if(count($targetNode) = 0) then - (update insert comment {"ID " || $id || " not found: Please create an appropriate item. " || serialize($link)} following $link, - update delete $link - ) - else - let $list := ixp:get-list-by-entity($targetNode) - return - element xhtml:li { - attribute class { "former-or-current-location" }, - element xhtml:a { - attribute href { "register.html?e=" || $id }, - , - " ", - $targetNode/*[1]/string(), - let $ancestors := $targetNode/ancestor::tei:place - for $parentPlace at $pos in $ancestors - let $name := $parentPlace/*[1]/string() - return - ((if($pos = 1) then "(" else ", ") || - $name || - (if($pos = count($ancestors)) then ")" else ())) - } - } + ((if($pos = 1) then "(" else ", ") || + $name || + (if($pos = count($ancestors)) then ")" else ())) + } + } }; (:~ renewed version of the linking function @@ -506,28 +507,24 @@ let $hits := $ixp:dataCollection//tei:rs let $array := array{ for $hit in $hits - let $base := $hit/base-uri() - let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] - let $resolve := ixp:resolve-name($tguri) - return - map{ - "base": $base, - "tguri" : $tguri, - "title" : $resolve, - "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) - } + let $base := $hit/base-uri() + let $tguri := (substring-before($base, ".xml") => tokenize("/|\."))[last()] + let $resolve := ixp:resolve-name($tguri) + return + map{ + "base": $base, + "tguri" : $tguri, + "title" : $resolve, + "surface": $hit/ancestor::tei:surface[parent::tei:sourceDoc]/string(@n) + } } let $titles := $array?*?title => distinct-values() let $countNotebooks := count($titles) return element xhtml:li { attribute class { "links" }, - if($countNotebooks lt 2) then - 'In Notizbuch' - else - ('In den Notizbüchern ', - ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse) - ), + if($countNotebooks lt 2) then 'In Notizbuch' else ('In den Notizbüchern ', + ({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)), element xhtml:ul { (: main list :) for $title in $titles @@ -1212,7 +1209,6 @@ else let $bibl := $place/tei:bibl let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"] let $formerCurrentLocation := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] - let $entitiesWithin := ixp:get-entities-within-a-place($id) let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] return element xhtml:li { @@ -1288,7 +1284,6 @@ else (: links :) ixp:links($place), ixp:li-code($place), - $entitiesWithin, element xhtml:ul { for $plac in $place/tei:place let $sort := string($plac/*[1]) @@ -1354,14 +1349,14 @@ as element(xhtml:div) {
    - { - for $i in $wrkList//tei:item[not(tei:list)][@xml:id = $filter] - order by (lower-case(($i/tei:name[not(@type)]/text())[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") ) - return ixp:prepare-work($i) - } +{ +for $i in $wrkList//tei:item[not(tei:list)][@xml:id = $filter] +order by (lower-case(($i/tei:name[not(@type)]/text())[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") ) +return ixp:prepare-work($i) +}
@@ -1375,169 +1370,15 @@ as element(xhtml:div) { : prepares a single work item :) declare function ixp:prepare-work($work as element(tei:item)) as element(xhtml:li) { - (: check if the item points to another entity :) - if( not(exists($work/@xml:id)) ) then - (: pointer :) - ixp:pointer($work) - else - (: entity :) - let $id := $work/@xml:id - let $labelMain := $work/tei:name[1] - return - element xhtml:li { - attribute id { string($id) }, - ixp:entry-class($id), - (: link to this entry :) - ixp:entry-link($id), - local:make-work-main-label($labelMain), - element xhtml:ul { - local:make-work-commons($work), - for $listPlace in $work/tei:listPlace - return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPlace" }, - for $place in $listPlace/tei:place - let $sort := string($place/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-place($place) - } - } - } - } -}; - - -(:~ Some places like museums have entities within them which are referenced - : in the index of works. These entities should also be displayed when viewing - : a place on register.html. - : - : This function provides a list of entities that are located in a place. - : - : @author Michelle Weidling - : @param $work-id The current work ID as string, e.g. "Museum_Neuruppin" - : @return A xhtml:li with all the entities that are or have been located at the current place. - :) -declare function ixp:get-entities-within-a-place($work-id as xs:string) as -element(xhtml:li)* { - let $nodes := ixp:getNodes() - (: the 5th position of ixp:getNodes() is the work index, excluding Fontane's - works and periodicals. :) - let $work-index := array:get($nodes, 5) - let $items := $work-index//tei:link[@corresp = "http://erlangen-crm.org/current/P53_has_former_or_current_location"][substring-after(@target, " ") = "plc:" || $work-id]/ancestor::tei:item[1] - - for $item in $items return - ixp:prepare-minified-work($item) -}; - - -(:~ - : A minified index entry for a work. This function is only needed for displaying - : information of an entity that is located at a certain place. In comparison to - : ixp:prepare-work it lacks a list of places in which it is located since we'd - : run into a recursion if we'd invoked the full ixp:prepare-work. - : - : @author Michelle Weidling - : @param $work An entity that is located at a certain place - : @return A xhtml:li with the same information as ixp:prepare-work provides EXCEPT the entity's place - : :) -declare function ixp:prepare-minified-work($work as element(tei:item)) -as element(xhtml:li) { - (: check if the item points to another entity :) - if( not(exists($work/@xml:id)) ) then - (: pointer :) - ixp:pointer($work) - else - (: entity :) - let $id := $work/@xml:id - let $labelMain := $work/tei:name[1] - return - element xhtml:li { - attribute id { string($id) }, - ixp:entry-class($id), - (: link to this entry :) - ixp:entry-link($id), - local:make-work-main-label($labelMain), - element xhtml:ul { - local:make-work-commons($work) - } - } -}; - -declare function local:make-work-main-label($labelMain as element(tei:name)) -as element(xhtml:span) { - element xhtml:span { - attribute class { "label-main" }, - $labelMain/text() - } -}; - -declare function local:make-work-alt-labels($labelAlt as element(tei:name)*) -as element(xhtml:li)* { - for $l in $labelAlt return - element xhtml:li { - attribute class {"label-" || string($l/@type)}, - $l/text(), - if($l/@type = "variant") - then () - else ( - " ", - element xhtml:a { - attribute href { string($l/@xml:base) || string($l) }, - - } - ) - } -}; - -declare function local:make-dates($dates as element(tei:date)*) -as element(xhtml:li)* { - for $d in $dates return - element xhtml:li { - attribute class {"date"}, - $d/text() - } -}; - -declare function local:make-translations($translationOf as element(tei:link)*) -as element(xhtml:li)* { - for $link in $translationOf - let $url := $link/@target => substring-after(" ") - return - element xhtml:li { - attribute class {"translationOf"}, - "Übersetzung von ", - - { - ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) - } - - } -}; - -declare function local:make-work-list-person($work as element(tei:item)) -as element(xhtml:li)* { - for $listPerson in $work/tei:listPerson return - element xhtml:li { - element xhtml:ul { - attribute class { "work-listPerson" }, - for $person in $listPerson/tei:person - let $sort := string($person/*[1]) - => replace("ä", "ae") - => replace("ö", "oe") - => replace("ü", "ue") - order by $sort - return ixp:prepare-person($person) - - } - } -}; - -declare function local:make-work-commons($work as element(tei:item)) as -element(xhtml:li)+ { +(: check if the item points to another entity :) +if( not(exists($work/@xml:id)) ) +then + (: pointer :) + ixp:pointer($work) +else + (: entity :) + let $id := $work/@xml:id + let $labelMain := $work/tei:name[1] let $labelAlt := $work/tei:name[not(@type="variant")][position() gt 1] let $variant := $work/tei:name[@type="variant"] let $idnos := $work/tei:idno @@ -1559,33 +1400,96 @@ element(xhtml:li)+ { let $translationOf := $work/tei:linkGrp/tei:link[@corresp="http://purl.org/ontology/bibo/#translationOf"] let $formerCurrentLocation := $work/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] let $links := $work/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] - return - ( - (: variant :) - ixp:variant($variant), - (: secondary label :) - local:make-work-alt-labels($labelAlt), - (: idno :) - ixp:idno($idnos), - local:make-dates($date), - (: creator :) - if (not(exists($creator))) then - () - else + element xhtml:li { + attribute id { string($id) }, + ixp:entry-class($id), + (: link to this entry :) + ixp:entry-link($id), + element xhtml:span { + attribute class { "label-main" }, + $labelMain/text() + }, + element xhtml:ul { + (: variant :) + ixp:variant($variant), + (: secondary label :) + for $l in $labelAlt + return + element xhtml:li { + attribute class {"label-" || string($l/@type)}, + $l/text(), + if($l/@type = "variant") + then () + else ( + " ", + element xhtml:a { + attribute href { string($l/@xml:base) || string($l) }, + + } + ) + }, + (: idno :) + ixp:idno($idnos), + for $d in $date + return + element xhtml:li { + attribute class {"date"}, + $d/text() + }, + (: creator :) + if (not(exists($creator))) then () else ixp:creator($creator), - (: translationOf :) - local:make-translations($translationOf), - (: note :) - ixp:note($note), - (: bibl :) - ixp:bibl($bibl), - (: former_or_current_location :) - ixp:has-former-or-current-location($formerCurrentLocation), - (: links :) - ixp:links($work), - ixp:li-code($work), - (: further entities :) - local:make-work-list-person($work) - ) + (: translationOf :) + for $link in $translationOf + let $url := $link/@target => substring-after(" ") + return + element xhtml:li { + attribute class {"translationOf"}, + "Übersetzung von ", + { + ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.) + } + }, + (: note :) + ixp:note($note), + (: bibl :) + ixp:bibl($bibl), + (: former_or_current_location :) + ixp:has-former-or-current-location($formerCurrentLocation), + (: links :) + ixp:links($work), + ixp:li-code($work), + (: further entities :) + for $listPerson in $work/tei:listPerson + return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPerson" }, + for $person in $listPerson/tei:person + let $sort := string($person/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-person($person) + + } + }, + for $listPlace in $work/tei:listPlace + return + element xhtml:li { + element xhtml:ul { + attribute class { "work-listPlace" }, + for $place in $listPlace/tei:place + let $sort := string($place/*[1]) + => replace("ä", "ae") + => replace("ö", "oe") + => replace("ü", "ue") + order by $sort + return ixp:prepare-place($place) + } + } + } + } }; -- GitLab From 3d7f94b988798768232b42cd4cdde6224123df3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Thu, 21 Nov 2019 17:12:54 +0100 Subject: [PATCH 4/6] add work entries to place index --- modules/fontane/index-processor.xqm | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index c7f8d8ff..2a88b9a4 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -1210,6 +1210,15 @@ else let $tookPlaceAt := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P7_took_place_at"] let $formerCurrentLocation := $place/tei:linkGrp/tei:link[@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] let $links := $place/tei:linkGrp/tei:link[@corresp="https://schema.org/mentions"] + + let $itemRefs := $ixp:dataCollection//tei:link + [@corresp="http://erlangen-crm.org/current/P53_has_former_or_current_location"] + [ends-with(@target, " plc:" || $id)]/parent::tei:linkGrp/parent::tei:* + let $itemsRefNodes := for $item in $itemRefs + let $node := ixp:data-loader($item) + order by string($node) + return + $node return element xhtml:li { attribute id { string($id) }, @@ -1281,6 +1290,10 @@ else }, (: former_or_current_location :) ixp:has-former-or-current-location($formerCurrentLocation), + (: entries referencing this entity :) + if($itemsRefNodes) + then { $itemsRefNodes } + else (), (: links :) ixp:links($place), ixp:li-code($place), @@ -1493,3 +1506,28 @@ else } } }; + +declare function ixp:data-loader($targetNode as element()) +as element(xhtml:li) { + let $targetId := string($targetNode/@xml:id) + let $title := string($targetNode/*[1]) + return + element xhtml:li { + attribute class { "registerEintrag", $targetNode/local-name() }, + element xhtml:a { + attribute href { "register.html?e=" || string-join($targetId) }, + if($targetNode[2]) + then "two entities with same ID: " || $targetId + else $title + }, + text{ " " }, + element xhtml:span { + attribute class { "load-entity" }, + attribute data-load { $targetId }, + element xhtml:i { + attribute class {"fa fa-plus-square-o"}, + attribute aria-hidden {"true"} + } + } + } +}; -- GitLab From e82948901dc16bed82f16d1b0cae7d64d5f33db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Fri, 22 Nov 2019 13:16:55 +0100 Subject: [PATCH 5/6] add event/@where, event took place at and personGrp members --- modules/fontane/index-processor.xqm | 32 +++++------------------------ 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index 2a88b9a4..9593d385 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -779,16 +779,9 @@ return (: note :) ixp:note($note), (: where :) - for $where in $wheres return - element xhtml:li { - attribute class { "where" }, - element xhtml:a { - attribute href { "register.html?e="|| $where }, - , - " ", - $ixp:dataCollection/id($where)/*[1]/string() - } - }, + for $where in $wheres + return + ixp:data-loader($ixp:dataCollection/id($where)), (: bibl :) ixp:bibl($bibl), (: links :) @@ -1092,14 +1085,7 @@ else for $member in $members let $memberId := $members/@target => substring-after(" ") => substring-after("#") return - element xhtml:li { - element xhtml:a { - attribute href { "?e=" || $memberId }, - , - " ", - $ixp:dataCollection/id($memberId)/*[1]/string() - } - } + ixp:data-loader($ixp:dataCollection/id($memberId)) } }, if (not(exists($creator))) then () else @@ -1279,15 +1265,7 @@ else for $l in $tookPlaceAt let $id := $l/@target => substring-after(":") => substring-before(" ") return - element xhtml:li { - attribute class { "took-place-at" }, - element xhtml:a { - attribute href { "?e=" || $id }, - , - " ", - $ixp:dataCollection/id($id)/*[1]/string() - } - }, + ixp:data-loader($ixp:dataCollection/id($id)), (: former_or_current_location :) ixp:has-former-or-current-location($formerCurrentLocation), (: entries referencing this entity :) -- GitLab From 5d25dd4e52990d225eb2f900522acf99da8948ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Fri, 22 Nov 2019 13:21:15 +0100 Subject: [PATCH 6/6] add documentation --- modules/fontane/index-processor.xqm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/fontane/index-processor.xqm b/modules/fontane/index-processor.xqm index 9593d385..2ae151f0 100644 --- a/modules/fontane/index-processor.xqm +++ b/modules/fontane/index-processor.xqm @@ -1485,6 +1485,13 @@ else } }; +(:~ + : A generic list item that is enabled for loading the entry it points to + : via ajax call. + : @author Mathias Göbel + : @param $targetNode The TEI element to load in place + : @return a xhtml:li with the title and an icon to click for loading the entry +:) declare function ixp:data-loader($targetNode as element()) as element(xhtml:li) { let $targetId := string($targetNode/@xml:id) -- GitLab