Commit 0297e9d8 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

Merge branch 'develop' of gitlab.gwdg.de:fontane-notizbuecher/SADE into develop

parents 188bb1a1 4967e1de
......@@ -20,8 +20,6 @@ import module namespace config="http://textgrid.de/ns/SADE/config" at "../config
import module namespace ixp="http://fontane-nb.dariah.eu/index-processor" at "index-processor.xqm";
import module namespace rest="http://exquery.org/ns/restxq";
declare variable $index:dataPath := "/db/sade-projects/textgrid/data/xml/data";
(:~
: resolves and lists all references on a given page based on their index data
:
......@@ -58,14 +56,14 @@ declare
function index:entites-per-page($uri as xs:string, $surface as xs:string)
as element(xhtml:ul)* {
let $docpath := $index:dataPath || "/" || $uri || ".xml"
let $docpath := $ixp:dataPath || $uri || ".xml"
let $surface := tokenize($surface, "-")
(: test for document available :)
return
if(not(doc-available($docpath)))
then
let $docsInDb := collection($index:dataPath)//tei:sourceDoc
let $docsInDb := $ixp:dataCollection//tei:sourceDoc
/replace(base-uri(), "\.xml|/|db|sade-projects|textgrid|data|xml", "")
=> string-join(", ")
return
......@@ -101,7 +99,7 @@ return
element xhtml:ul {
for $entity in $entities[substring-before(., ":") = $group]
let $ref := substring-after($entity, ":")
let $index := (collection($index:dataPath)/id($ref))[1]
let $index := ($ixp:dataCollection/id($ref))[1]
let $name := string($index/*[1])
let $list := index:get-list-by-id($ref)
let $href := "register.html?e=" || $ref
......@@ -159,7 +157,7 @@ declare
function index:get-list-by-id($id as xs:string)
as xs:string {
let $entity := collection($index:dataPath)/id($id)[ not(. instance of element(tei:handNote) ) ]
let $entity := $ixp:dataCollection/id($id)[ not(. instance of element(tei:handNote) ) ]
let $test := if($entity[2]) then error(QName("FONTANE", "INDEX-API3"), "Entity »" || $id || "« has more then one occurence." ) else ()
return
switch ( $entity/local-name() )
......@@ -214,7 +212,7 @@ declare
%test:assertTrue
function index:rendered-entity($id as xs:string)
as item()* {
let $node := collection($index:dataPath)/id($id)
let $node := $ixp:dataCollection/id($id)
let $type := $node/root()//tei:body/*[1]/local-name()
(: listEvent, listPlace, listOrg, listPerson or list :)
return
......@@ -252,6 +250,7 @@ declare
%test:name("simple search")
%test:arg("query", "Dom Karlos")
%test:arg("index", "listEvent,listOrg,listPerson,listPlace,list-works,list-Fontane,list-periodicals")
%test:assertXPath("array:size($result) = 2")
function index:search($query as xs:string, $index)
......@@ -261,12 +260,12 @@ return if(string-length($query) lt 2) then () else
let $prepare := tokenize($index, ",")
let $hits :=
(
collection($index:dataPath)//tei:person[contains(tei:persName, $query)],
collection($index:dataPath)//tei:personGrp[contains(tei:persName, $query)],
collection($index:dataPath)//tei:place[contains(tei:placeName, $query)],
collection($index:dataPath)//tei:org[contains(tei:orgName, $query)],
collection($index:dataPath)//tei:event[contains(tei:label, $query)],
collection($index:dataPath)//tei:item[tei:name/contains(., $query) = true()]
$ixp:dataCollection//tei:person[contains(tei:persName, $query)],
$ixp:dataCollection//tei:personGrp[contains(tei:persName, $query)],
$ixp:dataCollection//tei:place[contains(tei:placeName, $query)],
$ixp:dataCollection//tei:org[contains(tei:orgName, $query)],
$ixp:dataCollection//tei:event[contains(tei:label, $query)],
$ixp:dataCollection//tei:item[tei:name/contains(., $query) = true()]
)
return
array{
......@@ -300,9 +299,9 @@ declare
%test:arg("id", "Arnoldi-Denkmal")
%test:arg("type", "plc")
%test:assertTrue
%test:assertXPath("$result?1 => exists()")
function index:rendered-entity($type as xs:string, $id as xs:string)
as item()* {
as array(*) {
let $request :=
<hc:request
method="get"
......
......@@ -5,7 +5,7 @@ xquery version "3.1";
: the index for a single notebook.
: The corresponding viewer module is `index-viewer.xqm`.
: @author Mathias Göbel
: @version 1.0
: @version 1.0.1
: @see https://fontane-nb.dariah.eu/register.html
:)
module namespace ixp="http://fontane-nb.dariah.eu/index-processor";
......@@ -25,13 +25,14 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $ixp:metaCollection := '/db/sade-projects/textgrid/data/xml/meta/';
declare variable $ixp:targetStart := "http://textgridrep.org/textgrid:";
(: try/catch here, to pass the tests when no request object is available :)
(: try/catch here, to pass the tests where no request object is available :)
declare variable $ixp:getEntity := try {request:get-parameter('e', '')} catch * {""};
declare variable $ixp:getIndex := try {request:get-parameter('i', '')} catch * {""};
declare variable $ixp:notebookParam := try {request:get-parameter('nb', '')} catch * {""};
declare variable $ixp:getNotebook := $ixp:targetStart || $ixp:notebookParam;
declare variable $ixp:dataCollection := collection($config:data-root || "/data");
declare variable $ixp:dataPath := '/db/sade-projects/textgrid/data/xml/data/';
(:~
: Helper function to collect all main nodes from the index files.
......@@ -488,77 +489,19 @@ return
}
};
(:~
: a list item with a list of links
:)
declare function ixp:links($links as element(tei:link)*)
as element(xhtml:li) {
let $notebookUris :=
$links ! (substring-after(./@target, $ixp:targetStart) => substring(1,5) => distinct-values())
let $linkMap as map() :=
map:new(
for $nb in $notebookUris
return
map:entry($nb, $links[contains(@target, $nb)])
)
return
element xhtml:li {
attribute class { "links" },
if(count(map:keys($linkMap)) lt 2) then 'In Notizbuch' else 'In den Notizbüchern',
element xhtml:ul {
ixp:link($linkMap)
}
}
};
(:~
: create list items containing links
: :)
declare function ixp:link($map as map()*)
as element(xhtml:li)* {
for $tguri in map:keys($map)
let $resolve := ixp:resolve-name($tguri)
order by $resolve
return
element xhtml:li {
replace($resolve, "([A-E])0(\d)", "$1$2") || ": ",
element xhtml:ul {
attribute class {"link-list-horizontal"},
let $this-map := $map($tguri)
let $surface-sequence := $this-map ! (./@target => substring-after("surface[@n='") => substring-before("']/"))
for $link at $pos in $this-map
let $page := $link/@target => substring-after("surface[@n='") => substring-before("']/")
let $index-of := index-of($surface-sequence, $page)
let $count := count( $index-of )
where $pos = $index-of[1]
return
element xhtml:li {
element xhtml:a {
attribute href {
"edition.html?id=%2Fxml%2Fdata%2F" || $tguri
|| ".xml&amp;page=" || $page
|| "&amp;target=" || string($link/parent::tei:*/parent::tei:*/@xml:id)
},
f-misc:n-translate($page),
if($count eq 1) then ()
else (" ", <xhtml:span title="Anzahl an Vorkommnissen auf dieser Seite">({$count})</xhtml:span>)
}
}
}
}
};
(:~ renewed version of the linking function
: generates a XHTML list with all links without using the tei:link[@corresp]
: from the entity. it queries the database for what is really mentioned.
: @version 2.0
:)
declare function ixp:links-new($entity as element()) {
declare function ixp:links($entity as element()) {
let $id := string($entity/@xml:id)
let $prefix := ixp:get-prefix-by-entity($entity)
let $reference := $prefix || ":" || $id
let $hits := $ixp:dataCollection//tei:rs[contains(@ref, $reference)][not(@prev)]
let $hits := $ixp:dataCollection//tei:rs
[contains(@ref, $reference)]
[not(@prev)]
[@ref eq $reference]
let $array :=
array{
......@@ -848,7 +791,7 @@ return
(: bibl :)
ixp:bibl($bibl),
(: links :)
ixp:links-new($event),
ixp:links($event),
ixp:li-code($event)
}
}
......@@ -969,7 +912,7 @@ return
(: bibl :)
ixp:bibl($bibl),
(: links :)
ixp:links-new($org),
ixp:links($org),
ixp:li-code($org)
}
}
......@@ -1165,7 +1108,7 @@ else
(: bibl :)
ixp:bibl($bibl),
(: links :)
ixp:links-new($pers),
ixp:links($pers),
ixp:li-code($pers)
}
}
......@@ -1329,7 +1272,7 @@ else
(: former_or_current_location :)
ixp:has-former-or-current-location($formerCurrentLocation),
(: links :)
ixp:links-new($place),
ixp:links($place),
ixp:li-code($place),
element xhtml:ul {
for $plac in $place/tei:place
......@@ -1494,7 +1437,7 @@ else
(: former_or_current_location :)
ixp:has-former-or-current-location($formerCurrentLocation),
(: links :)
ixp:links-new($work),
ixp:links($work),
ixp:li-code($work),
(: further entities :)
for $listPerson in $work/tei:listPerson
......
......@@ -12,7 +12,7 @@ declare variable $f-misc:metadata-collection := collection("/db/sade-projects/t
declare
%test:arg("baseUri","textgrid:16b00") %test:assertEquals("Notizbuch C7")
%test:arg("baseUri","") %test:assertEquals("")
%test:arg("baseUri","") %test:assertEmpty
function f-misc:get-title-by-baseUri($baseUri as xs:string)
as xs:string? {
if($baseUri = "") then () else
......
Markdown is supported
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