Skip to content

Commit

Permalink
Rename year properties and make sure they provide years only
Browse files Browse the repository at this point in the history
even where a full ISO data may be given in the TEI.

see #179
  • Loading branch information
cmil committed Feb 4, 2023
1 parent 645ed31 commit dcc64e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions modules/api.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,17 @@ function api:corpus-index($corpusname) {
/tei:idno[@type="URL"][1]/string()
),
map:entry("yearNormalized", $yearNormalized),
map:entry("yearPrinted", $years?print),
map:entry("yearPremiered", $years?premiere),
map:entry("yearWritten", $years?written),
(:
FIXME: the following year properties are deprecated and should be
removed in a future release
:)
map:entry("printYear", $years?print),
map:entry("premiereYear", $years?premiere),
map:entry("writtenYear", $years?written),

map:entry("networkSize", $network-size),
map:entry("networkdataCsvUrl", $play-uri || "/networkdata/csv"),
map:entry("wikidataId", dutil:get-play-wikidata-id($tei))
Expand Down
20 changes: 16 additions & 4 deletions modules/util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ declare function dutil:get-segments ($tei as element()*) as element()* {
$tei//tei:body//tei:div[tei:sp or (@type="scene" and not(.//tei:sp))]
};

declare function local:get-year($iso-date as xs:string) as xs:string* {
let $parts := tokenize($iso-date, "-")
(:
When the first part after tokenizing is empty we have a negative, i.e. BCE,
year and prepend it with "-". Otherwise we consider the first part a CE
year.
:)
return if ($parts[1] eq "") then "-" || $parts[2] else $parts[1]
};

(:~
: Retrieve `written`, `premiere` and `print` years as ISO 8601 strings for the
: play passed in $tei.
Expand All @@ -301,13 +311,15 @@ declare function dutil:get-years-iso ($tei as element(tei:TEI)*) as map(*) {
for $d in $dates
let $type := $d/@type/string()
let $year := if ($d/@when) then
$d/@when/string()
local:get-year($d/@when/string())
else if ($d/@notBefore and $d/@notAfter) then
$d/@notBefore/string() || '/' || $d/@notAfter/string()
local:get-year($d/@notBefore/string()) ||
'/' ||
local:get-year($d/@notAfter/string())
else if ($d/@notAfter) then
'<' || $d/@notAfter/string()
'<' || local:get-year($d/@notAfter/string())
else
'>' || $d/@notBefore/string()
'>' || local:get-year($d/@notBefore/string())
return map:entry($type, $year)
)

Expand Down

0 comments on commit dcc64e2

Please sign in to comment.