Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/xql/getAnnotation.xql
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ return
</div>
</div>
<div class="contentBox">
<h1>{annotation:getTitle($annot, $lang)}</h1>
<h1>{eutil:getLocalizedName($annot, $lang)}</h1>
{annotation:getContent($annot, '', $edition)}
</div>

Expand Down
2 changes: 1 addition & 1 deletion data/xql/getAnnotationInfos.xql
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let $annots := $editionCollection//mei:annot[matches(@plist, $uri)] | $mei//mei:
let $categories :=
for $category in local:getDistinctCategories($annots)
let $categoryElement := ($editionCollection/id($category)[mei:label or mei:name])[1]
let $name := annotation:category_getName($categoryElement, edition:getLanguage($edition))
let $name := eutil:getLocalizedName($categoryElement, edition:getLanguage($edition))
order by $name
return
map {
Expand Down
2 changes: 1 addition & 1 deletion data/xql/getAnnotationText.xql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ return

<div class="annotView">
<div class="contentBox">
<h1>{annotation:getTitle($annot, $lang)}</h1>
<h1>{eutil:getLocalizedName($annot, $lang)}</h1>
{annotation:getContent($annot, '', $edition)}
</div>
</div>
86 changes: 5 additions & 81 deletions data/xqm/annotation.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@ declare namespace transform="http://exist-db.org/xquery/transform";

(: FUNCTION DECLARATIONS =================================================== :)

declare function annotation:getLocalizedLabel($node) {

let $lang := request:get-parameter('lang', '')
let $nodeName := local-name($node)

let $label :=
if($nodeName = 'category') then (
(: new style, i.e. //category/label :)
if ($node/mei:label[@xml:lang = $lang]) then
$node/mei:label[@xml:lang = $lang]/text()
else
$node/mei:label[1]/text()

) else if($nodeName = 'term') then(
(: old style, i.e. //term/name :)
eutil:getLocalizedName($node, $lang)

) else
($nodeName)

return $label
};

(:~
: Returns a JSON representation of all Annotations of a document
:
Expand All @@ -74,7 +51,7 @@ declare function annotation:toJSON($anno as element(), $edition as xs:string) as

let $id := $anno/string(@xml:id)
let $lang := request:get-parameter('lang', '')
let $title := annotation:getTitle($anno, $lang)
let $title := eutil:getLocalizedName($anno, $lang)

let $doc := $anno/root()
let $prio := annotation:getPriorityLabel($anno)
Expand Down Expand Up @@ -109,7 +86,7 @@ declare function annotation:toJSON($anno as element(), $edition as xs:string) as
let $cats :=
string-join(
for $u in $catURIs
return annotation:category_getName($doc/id($u), edition:getLanguage($edition))
return eutil:getLocalizedName($doc/id($u), edition:getLanguage($edition))
, ', ')

let $count := count($anno/preceding::mei:annot[@type = 'editorialComment']) + 1
Expand All @@ -125,19 +102,6 @@ declare function annotation:toJSON($anno as element(), $edition as xs:string) as
}
};

(:~
: Generates a title for annotation which have none
:
: @param $anno The Annotation to process
: @param $lang The language to use
: @return The string result
:)
declare function annotation:generateTitle($anno as element(), $lang as xs:string) {
let $mdiv.n := eutil:getLanguageString('Movement_n', string(count($anno/ancestor::mei:mdiv/preceding-sibling::mei:mdiv) + 1), $lang)
let $measure := eutil:getLanguageString('Bar_n', $anno/ancestor::mei:measure/string(@n), $lang)
return $mdiv.n || ', ' || $measure
};

(:~
: Returns a HTML representation of an Annotation's content
:
Expand Down Expand Up @@ -170,20 +134,6 @@ declare function annotation:getContent($anno as element(), $idPrefix as xs:strin
$html
};

(:~
: Returns an annotation's title as string
:
: @param $anno The annotation to process
: @param $lang The language to use
: @return The title
:)
declare function annotation:getTitle($anno as element(), $lang as xs:string) {

if($anno/mei:title or $anno/mei:name)
then(eutil:getLocalizedName($anno, $lang))
else(annotation:generateTitle($anno, $lang))
};

(:~
: Returns an Annotation's priority
:
Expand Down Expand Up @@ -219,7 +169,7 @@ declare function annotation:getPriorityLabel($anno) as xs:string* {

return
if($isPrioElemAlready) then
(annotation:getLocalizedLabel($anno))
(eutil:getLocalizedName($anno))

else if($oldEdiromStyle) then
(annotation:getPriority($anno))
Expand All @@ -237,24 +187,13 @@ declare function annotation:getPriorityLabel($anno) as xs:string* {
(doc(substring-before($uri,'#')))

let $prioElem := $doc/id(replace($uri,'#',''))
let $label := annotation:getLocalizedLabel($prioElem)
let $label := eutil:getLocalizedName($prioElem)
return $label

return string-join($labels,', ')
)
};

(:~
: Returns Annotation's categories
:
: @param $anno The Annotation to process
: @return The categories (as comma separated string)
:)
declare function annotation:getCategories($anno as element()) as xs:string {

string-join(annotation:getCategoriesAsArray($anno), ', ')
};

(:~
: Returns an array of Annotation's categories
:
Expand All @@ -270,7 +209,7 @@ declare function annotation:getCategoriesAsArray($anno as element()) as xs:strin

let $cats :=
for $u in $catURIs
return annotation:category_getName($doc/id($u),'')
return eutil:getLocalizedName($doc/id($u), '')


(:let $uris := tokenize($anno/mei:ptr[@type eq 'categories']/string(@target),' ')
Expand Down Expand Up @@ -302,18 +241,3 @@ declare function annotation:getParticipants($anno as element()) as xs:string* {

return $uris
};

(:~
: Returns an annotation category's name
:
: @param $category The category to process
: @return one name
:)
declare function annotation:category_getName($category as element(), $language as xs:string) {
annotation:getLocalizedLabel($category)
(:let $names := $category/mei:name
return
switch (count($names[@xml:lang = $language]))
case 1 return $names[@xml:lang = $language]
default return $names[1]:)
};
72 changes: 54 additions & 18 deletions data/xqm/eutil.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,71 @@ declare function eutil:getNamespace($node as node()) as xs:string {

};


(:~
: Returns a localized string
:
: @param $node The node to be processed
: @return The string
: @return The localized output string
:)
declare function eutil:getLocalizedName($node, $lang) {
declare function eutil:getLocalizedName($node as element()) as xs:string {

let $name :=
if ($node/mei:title) then (
if ($lang = $node/mei:title/@xml:lang) then
$node/mei:title[@xml:lang = $lang]/text()
else
$node/mei:title[1]/text()
eutil:getLocalizedName($node, request:get-parameter('lang', ''))

};


(:~
: Returns a localized string for a provided language
:
: @param $node The node to be processed
: @param $lang The language for the localized output
: @return The localized output string
:)
declare function eutil:getLocalizedName($node as element(), $lang as xs:string) as xs:string {

(: identify the context for further processing:)
let $case := ( 'child::mei:title'[$node/mei:title], 'child::mei:name'[$node/mei:name],
'child::mei:label'[$node/mei:label], 'child::edirom:names'[$node/edirom:names],
'self::mei:annot'[$node[self::mei:annot]], 'other' )[1]

) else if ($node/mei:name) then (
if ($lang = $node/mei:name/@xml:lang) then
$node/mei:name[@xml:lang = $lang]/text()
else
$node/mei:name[1]/text()

let $name :=

(: if current node has child mei:title or mei:name or mei:label :)
if ($case eq 'child::mei:title' or $case eq 'child::mei:name' or $case eq 'child::mei:label') then (

let $childNodes := $node/mei:*[local-name() = substring-after($case, 'mei:')]

(: return most appropriate string, either from children's text or empty string :)
return
(
string-join($childNodes[@xml:lang = $lang]/text(), ' ')[not(matches(., '^\s*$'))],
$childNodes[1]/text(),
''
)[1]
)

) else if ($node/edirom:names) then (
(: if current node has child edirom:names :)
else if ($case eq 'child::edirom:names') then (
if ($lang = $node/edirom:names/edirom:name/@xml:lang) then
$node/edirom:names/edirom:name[@xml:lang = $lang]/node()
$node/edirom:names/edirom:name[@xml:lang = $lang]/node() || ''
else
$node/edirom:names/edirom:name[1]/node()
$node/edirom:names/edirom:name[1]/node() || ''
)

) else
(normalize-space($node))
(: if current node is an mei:annot :)
else if ( $case eq 'self::mei:annot' ) then (
(: if $node is mei:annot and does not have child mei:title or mei:name (covered by cases above) :)
let $mdiv.n := eutil:getLanguageString('Movement_n', string(count($node/ancestor::mei:mdiv/preceding-sibling::mei:mdiv) + 1), $lang)
let $measure := eutil:getLanguageString('Bar_n', $node/ancestor::mei:measure/string(@n), $lang)
return $mdiv.n || ', ' || $measure
)

(: otherwise :)
else (
(normalize-space($node))
)

return
if($node/edirom:names) then
Expand Down
Loading