Commit 75db361a authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

prepare new register API

parent 112f27dd
......@@ -3,20 +3,60 @@ xquery version "3.1";
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 tei="http://www.tei-c.org/ns/1.0";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
declare function local:Links($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')
(: 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
if(contains($link/@target, $nb)) then
<li><a href="edition.html?id=/xml/data/{$baseUri}.xml&amp;page={$targetSf}">{$title} – {$targetSf}</a></li>
else ()
(map:entry($uri, string($title)),
map:entry("textgrid:"||$uri, string($title)))
);
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>
}
</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()) {
......@@ -175,45 +215,45 @@ return
</div>
<div class="panel-body">
<ul>
{ for $pers in $persList/tei:person|$persList/tei:personGrp
{for $pers in $persList/tei:person|$persList/tei:personGrp
let $classes := ("registerEintrag",
"reg-"||$pers/local-name(),
if($pers/@xml:id = request:get-parameter('e', '')) then 'fhighlighted' else ())
let $primaryName := string( $pers/tei:persName[1] )
let $isPointer := not(exists($pers/@xml:id))
let $pointer := if($isPointer) then local:pointer($pers//tei:ptr, $persList/ancestor::*//*[@xml:id = substring-after($pers//tei:ptr/@target, '#')]) else ()
where ($pers//tei:link/contains(@target, map:keys($fontaneregister:titles))) = true()
return
<li id="{$pers/@xml:id}" class="{ $classes }">
{ $primaryName }
{ if( $isPointer ) then $pointer else
(: Person :) (
let $registerLink :=
<span class="registerLink">
<a href="register.html?{replace(request:get-query-string(), '(&amp;)*e=.+(&amp;)*', '')||(if(request:get-query-string() = "") then () else "&amp;")}e={$pers/string(@xml:id)}"><i title="Link zu diesem Eintrag" class="fa fa-link"></i></a>
</span>
let $hasVariant := exists($pers/tei:persName[@type="variant"])
let $birthAndDeath := if( not($pers/tei:birth or $pers/tei:death) ) then () else
<li>{if($pers/tei:birth/node()) then ('&#8727;',$pers/tei:birth/text()) else ()} {if($pers/tei:death/node()) then ('✝',$pers/tei:death/text()) else()}</li>
(: test if we process for a specific notebook :)
(: if (not(
($pers//tei:link/contains(@target, request:get-parameter('nb', 'textgrid')) = true() )
)
) then () else
if(not(local:pointerTest(string(string($pers//tei:note/tei:ptr/@target)), request:get-parameter('nb', 'textgrid')))) then () else
:) <li id="{$pers/@xml:id}" class="registerEintrag reg-{$pers/local-name()} {if($pers/@xml:id = request:get-parameter('e', '')) then 'fhighlighted' else ()}">
{$pers/tei:persName[1]/text()}
{
if( not( exists($pers/@xml:id)) ) then local:pointer($pers//tei:ptr, $persList/ancestor::*//*[@xml:id = substring-after($pers//tei:ptr/@target, '#')])
else (
<span class="registerLink"> <a href="register.html?{replace(request:get-query-string(), '(&amp;)*e=.+(&amp;)*', '')||(if(request:get-query-string() = "") then () else "&amp;")}e={$pers/string(@xml:id)}"><i title="Link zu diesem Eintrag" class="fa fa-link"></i></a> </span>,
<ul>
{if(exists($pers/tei:persName[@type="variant"]))
then <li>im Text:
<ul>{ for $item in $pers/tei:persName[@type="variant"]/text() return <li> {$item} </li>} </ul>
</li> else ()}
{if($pers/tei:birth or $pers/tei:death)
then <li>{if($pers/tei:birth) then ('&#8727;',$pers/tei:birth/text()) else ()}{' '}{if($pers/tei:death) then ('✝',$pers/tei:death/text()) else()}</li>
else ()}
return ($registerLink,
<ul>{ if( not( $hasVariant) ) then () else
<li>im Text:
<ul>{ for $item in $pers/tei:persName[@type="variant"]/text() return <li> {$item} </li>} </ul>
</li>
}
{ $birthAndDeath }
{if($pers/tei:occupation) then <li>{$pers/tei:occupation/text()}</li> else ()}
<li>(<a href="http://d-nb.info/gnd/{$pers/tei:idno[@xml:base="http://d-nb.info/gnd/"]/text()}">GND</a>)</li>
<li>
<ul>
{if($pers/tei:note/text()) then <li>{$pers/tei:note/text()}</li> else ()}
<li>{if(count( distinct-values($pers//tei:link/substring(substring-after(@target, 'textgrid:'), 1, 5)) ) lt 2) then 'In Notizbuch' else 'In den Notizbüchern'}
<ul>
{for $link in $pers//tei:link[@corresp="https://schema.org/mentions"]
return local:Links($link)}
</ul>
{ local:links3($pers//tei:link) }
</li>
</ul>
</li>
</ul>
)}
</ul>))}
</li>
}
</ul>
......@@ -225,6 +265,7 @@ return
};
declare function fontaneregister:places($geoDoc) {
let $console := console:log($geoDoc/base-uri())
let $geoURI := tokenize($geoDoc/base-uri(), '/|\.')[8]
return
(: Ortsregister :)
......@@ -320,6 +361,7 @@ let $r := request:get-parameter('r', '')
let $e := request:get-parameter('e', '')
let $agg := '253st.xml'
let $uris := doc('/db/sade-projects/textgrid/data/xml/agg/'||$agg)//ore:aggregates/substring-after(@rdf:resource, 'textgrid:')
let $meta := for $uri in $uris
where doc-available( '/db/sade-projects/textgrid/data/xml/data/' || $uri ||'.xml')
return
......@@ -362,7 +404,7 @@ return
<div class="tab-content">
{ fontaneregister:events( $docs//tei:body/tei:listEvent ) }
{ fontaneregister:orgs( $docs//tei:body/tei:listOrg ) }
{ fontaneregister:places( $docs//tei:body/tei:listPlace ) }
<!-- { fontaneregister:places( $docs//tei:body/tei:listPlace ) } -->
{ fontaneregister:persons( $docs//tei:body/tei:listPerson ) }
{ fontaneregister:works( $docs//tei:body//tei:list[@type="works"] ) }
{ fontaneregister:works( $docs//tei:body//tei:list[@type="periodicals"] ) }
......
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