Commit 09e82c16 authored by mrodzis's avatar mrodzis 🌎 Committed by Mathias Goebel
Browse files

Implement entities in work index, general formatting

parent a6d11661
......@@ -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 },
<xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
"&#160;",
$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 },
<xhtml:i class="fa fa-map-marker" aria-hidden="true"></xhtml:i>,
"&#160;",
$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 ',
<span style="color:gray">({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)</span>),
if($countNotebooks lt 2) then
'In Notizbuch'
else
('In den Notizbüchern ',
<span style="color:gray">({$countNotebooks} Notizbücher, insgesamt {array:size($array)} Vorkommnisse)</span>
),
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) {
</xhtml:div>
<xhtml:div class="panel-body">
<ul class="workList">
{
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)
}
</ul>
</xhtml:div>
</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 (
"&#160;",
element xhtml:a {
attribute href { string($l/@xml:base) || string($l) },
<xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
}
)
}
};
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 ",
<a href="{$url}">
{
ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.)
}
</a>
}
};
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 (
"&#160;",
element xhtml:a {
attribute href { string($l/@xml:base) || string($l) },
<xhtml:i title="Link zu externer Ressource" class="fa fa-external-link"></xhtml:i>
}
)
},
(: 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 ",
<a href="{$url}">{
ixp:get-gnd-data($url)//gndo:preferredNameForTheWork/string(.)
}</a>
},
(: 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)
)
};
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