Commit 946db69f authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

added documentation

parent 3662d6d4
xquery version "3.1";
(:~
: This module prepares the index html.
: @author Mathias Göbel
: @version 1.0
: @see https://fontane-nb.dariah.eu/register.html
:)
module namespace fontaneregister="http://fontane-nb.dariah.eu/register";
import module namespace console="http://exist-db.org/xquery/console" at "java:org.exist.console.xquery.ConsoleModule";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
......@@ -9,18 +13,8 @@ declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
(: new stuff :)
declare variable $fontaneregister:metaCollection := '/db/sade-projects/textgrid/data/xml/meta/';
declare variable $fontaneregister:titles :=
map:new(
for $title in collection($fontaneregister:metaCollection)//tgmd:title[starts-with(., "Notizbuch ")]
let $uri := $title/base-uri() => substring-after($fontaneregister:metaCollection) => substring-before(".xml")
return
(map:entry($uri, string($title)),
map:entry("textgrid:"||$uri, string($title)))
);
declare variable $fontaneregister:get-entity := request:get-parameter('e', '');
declare variable $fontaneregister:get-register := request:get-parameter('r', '');
declare variable $fontaneregister:get-notebook := request:get-parameter('nb', 'all');
......@@ -31,7 +25,7 @@ declare variable $fontaneregister:get-notebook := request:get-parameter('nb', 'a
: TODO: may this function should be placed in a generic module
: :)
declare function local:resolve-name($uri as xs:string) {
let $title := string(doc('/db/sade-projects/textgrid/data/xml/meta/' || $uri || '.xml')//tgmd:title) => replace("0(\d)", "$1")
let $title := string(doc($fontaneregister:metaCollection || $uri || '.xml')//tgmd:title) => replace("0(\d)", "$1")
return
if($title = "") then $uri else $title
};
......@@ -45,71 +39,40 @@ declare function local:check-active($id as xs:string, $node as element(*)+) as x
$node//@xml:id = $id
};
(:~
: checks if a target entity is in the current node set
: @param $node – any node set
: :)
declare function local:check-entity($node as node()+) as xs:string? {
if(local:check-active($fontaneregister:get-entity, $node))
then "active"
else ()
};
declare function local:links3($links as element()*) {
let $uris :=
$links ! (substring-after(./@target, "textgrid:") => substring(1,5))
=> distinct-values()
return
if($uris = ()) then () else
<ul>
{ for $nb in $uris[.=map:keys($fontaneregister:titles)]
let $title := $fontaneregister:titles($nb)
let $surfaces := $links[contains(@target, $nb)]/substring-before(substring-after(@target, "@n='"), "'")
let $link2surfaces := $surfaces ! local:create-links($nb, .)
let $linksToTarget := ($link2surfaces[1], for $l in $link2surfaces[position() gt 1] return (", ", $l))
order by $title
return
<li>{ replace($title, "Notizbuch ([A-E])0(\d)", "$1$2") } ({ $linksToTarget })</li>
(:~
: creates a xhtml list item containing serialized code.
: @param $node – a single element
: :)
declare function local:li-code($node as element(*)) {
element {"xhtml:li"} {
attribute {"class"} {"register-code"},
element { "xhtml:span" } {
attribute { "class" } {"registerCode"},
<xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
},
element {"xhtml:pre"} {
element {"xhtml:code"} {
attribute {"class"}{"html"},
serialize($node) => replace("[ ]{2,}", " ")
}
</ul>
};
declare function local:create-links($uri as xs:string, $surface as xs:string) as element()? {
<a href="edition.html?id=/xml/data/{$uri}.xml&amp;page={ $surface }">{ $surface }</a>
};
(: END new stuff :)
declare function local:Links($links as element()*) {
(:let $links :=:)
(: for $link in $links:)
(: let $targetSf := substring-before(substring-after($link/string(@target), "surface[@n='"), "']"):)
(: let $baseUri := substring(substring-after($link/@target, 'textgrid:'), 1, 5):)
(: let $title := doc( '/db/sade-projects/textgrid/data/xml/meta/' || $baseUri || '.xml')//tgmd:title/text():)
(: let $nb := request:get-parameter('nb', 'textgrid'):)
(: order by $title:)
(: return:)
(: if(contains($link/@target, $nb)) then:)
(: <li><a href="edition.html?id=/xml/data/{$baseUri}.xml&amp;page={$targetSf}">{$title} – {$targetSf}</a></li>:)
(: else ():)
()
};
declare function local:Links2($link as element()) {
let $targetSf := substring-before(substring-after($link/string(@target), "surface[@n='"), "']")
let $baseUri := substring(substring-after($link/@target, 'textgrid:'), 1, 5)
let $title := doc( '/db/sade-projects/textgrid/data/xml/meta/' || $baseUri || '.xml')//tgmd:title/text()
let $nb := request:get-parameter('nb', 'textgrid')
return
if(contains($link/@target, $nb)) then
<a href="edition.html?id=/xml/data/{$baseUri}.xml&amp;page={$targetSf}">{$targetSf}</a>
else ()
};
declare function local:pointer($pointer, $targetNode) {
(:<ptr target="#Tizian"/>:)
<li> siehe <a href="register.html?{replace(request:get-query-string(), '(&amp;)*e=.+(&amp;)*', '')||(if(request:get-query-string() = "") then () else "&amp;")}e={$pointer/substring-after(@target, '#')}">{ ($targetNode//tei:persName)[1]/text() }</a> </li>
}
}
};
(:~
: parser for listEvents/event entities
: :)
declare function fontaneregister:events($eventDoc) {
declare function fontaneregister:events($eventDoc as element(tei:listEvent)) as element(xhtml:div) {
let $eventDoc-uri := tokenize($eventDoc/base-uri(), '/|\.')[8]
return
(: main tab :)
......@@ -230,7 +193,8 @@ return
element {"xhtml:ul"} {
local:links-event($link-map)
}
}
},
local:li-code($e)
}
}
};
......@@ -263,7 +227,7 @@ declare function local:links-event($map as map()) {
(:~
: parser for tei:listOrg
: :)
declare function fontaneregister:orgs($orgDoc) {
declare function fontaneregister:orgs($orgDoc as element(tei:listOrg)+) as element(xhtml:div) {
let $orgURI := tokenize($orgDoc/base-uri(), '/|\.')[8]
return
(: Koerperschaftenregister :)
......@@ -287,6 +251,10 @@ return
</div>
};
(:~
: transforms a single tei:org element to a xhtml:li
: @since 1.0
: :)
declare function local:prepare-org($org as element(tei:org), $uri as xs:string) as element(xhtml:li) {
let $id := $org/@xml:id
let $label-main := ($org/tei:orgName)[1]
......@@ -372,7 +340,8 @@ return
element {"xhtml:ul"} {
local:links-event($link-map)
}
}
},
local:li-code($org)
}
}
};
......@@ -458,7 +427,6 @@ else
return
map:entry($nb, $links[contains(@target, $nb)])
)
let $code := serialize($pers)
return
(: item :)
......@@ -565,28 +533,17 @@ else
local:links-event($link-map)
}
},
(: code :)
element {"xhtml:li"} {
attribute {"class"} {"register-code"},
element { "xhtml:span" } {
attribute { "class" } {"registerCode"},
<xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
},
element {"xhtml:pre"} {
element {"xhtml:code"} {
attribute {"class"}{"html"},
$code => replace("[ ]{2,}", " ")
}
}
}
local:li-code($pers)
}
}
};
(:~
: prepares the index of geographical references
: :)
declare function fontaneregister:places($listPlace as element(tei:listPlace)) {
let $geoURI := tokenize($listPlace/base-uri(), '/|\.')[8]
return
(: Ortsregister :)
<div id="r{ $geoURI }" class="tab-pane {local:check-entity($listPlace)}">
<div id="accordion{ $geoURI }" class="panel-group" aria-multiselectable="true" role="tablist">
<div class="panel panel-default">
......@@ -604,6 +561,8 @@ return
</div>
};
(:~
: transformation of a single geographical reference item :)
declare function local:prepare-place($place as element(tei:place)) as element(xhtml:ul) {
let $label-main := $place/tei:placeName[1]
return
......@@ -652,7 +611,6 @@ else
return
map:entry($nb, $links[contains(@target, $nb)])
)
let $code := serialize($place)
return
(: item :)
......@@ -739,20 +697,7 @@ else
local:links-event($link-map)
}
},
(: code :)
element {"xhtml:li"} {
attribute {"class"} {"register-code"},
element { "xhtml:span" } {
attribute { "class" } {"registerCode"},
<xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
},
element {"xhtml:pre"} {
element {"xhtml:code"} {
attribute {"class"}{"html"},
$code => replace("[ ]{2,}", " ")
}
}
},
local:li-code($place),
element {"xhtml:ul"} {
$place/tei:place ! local:prepare-place(.)
}
......@@ -760,32 +705,35 @@ else
}
};
(:~
: prepares the list of works :)
declare function fontaneregister:works($wrkDoc) {
let $wrkURI := tokenize($wrkDoc/base-uri(), '/|\.')[8]
return
(: Werkregister :)
<div id="r{ $wrkURI }-{$wrkDoc/string(@type)}" class="tab-pane {local:check-entity($wrkDoc)}">
<div id="accordion{ $wrkURI }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $wrkList in $wrkDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">{$wrkList/tei:head/text()}</a>
</h4>
</div>
<div class="panel-body">
<ul class="workList">
{ for $i in $wrkList//tei:item[not(tei:list)]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i) }
</ul>
</div>
</div>
}
<div id="r{ $wrkURI }-{$wrkDoc/string(@type)}" class="tab-pane {local:check-entity($wrkDoc)}">
<div id="accordion{ $wrkURI }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $wrkList in $wrkDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">{$wrkList/tei:head/text()}</a>
</h4>
</div>
<div class="panel-body">
<ul class="workList">
{ for $i in $wrkList//tei:item[not(tei:list)]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i) }
</ul>
</div>
</div>
}
</div>
</div>
};
(:~
: prepares a single work item :)
declare function local:prepare-work($work as element(tei:item)) as element(xhtml:li) {
let $label-main := $work/tei:name[1]
return
......@@ -834,7 +782,6 @@ else
return
map:entry($nb, $links[contains(@target, $nb)])
)
let $code := serialize($work)
return
(: item :)
......@@ -921,47 +868,11 @@ else
local:links-event($link-map)
}
},
(: code :)
element {"xhtml:li"} {
attribute {"class"} {"register-code"},
element { "xhtml:span" } {
attribute { "class" } {"registerCode"},
<xhtml:i title="Zeige XML" class="fa fa-code"></xhtml:i>
},
element {"xhtml:pre"} {
element {"xhtml:code"} {
attribute {"class"}{"html"},
$code => replace("[ ]{2,}", " ")
}
}
}
local:li-code($work)
}
}
};
declare function local:linkGroup($linkGrp as element()) {
let $nbs := distinct-values(
$linkGrp//tei:link[@corresp="https://schema.org/mentions"][not(contains(@target, "XXX"))]/substring(substring-after(@target, 'textgrid:'), 1, 5) )
return
for $nb in $nbs
let $title := doc( '/db/sade-projects/textgrid/data/xml/meta/' || $nb || '.xml')//tgmd:title/text()
let $links := for $link in $linkGrp//tei:link[contains(@target, $nb)] return local:Links2($link)
let $cntLinks := count($links)
return
<li onclick="javascript:;"> {$title}: {for $l at $pos in $links where $pos lt $cntLinks return ($l, ', '), $links[last()] } </li>
};
declare function local:pointerTest($ref, $nb) as xs:boolean {
let $id := substring-after($ref, "#")
let $target := string-join( collection("/db/sade-projects/textgrid/data/xml/data/")//*[@xml:id = $id]//tei:link/@target )
return
contains($target, $nb)
};
declare function fontaneregister:register($id){
let $r := request:get-parameter('r', '')
let $e := request:get-parameter('e', '')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment