Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks in the registers module to better support the annotation of entities other than places and people #237

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 34 additions & 27 deletions modules/registers.xql
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ declare function rapi:save($request as map(*)) {
let $body := $request?body/*[1]

let $type := local-name($body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure $body is defined always e.g. by api.json?

let $type := if ($type = 'org') then "organization" else $type
let $type := switch($type)
case "org" return "organization"
case "bibl" return "work"
default return $type
let $id := ($body/@xml:id, $request?parameters?id)[1]

let $data := rapi:prepare-record($body, $user, $type)
Expand Down Expand Up @@ -101,6 +104,8 @@ declare function rapi:insert-point($type as xs:string) {
collection($config:register-root)/id($root)//tei:listOrg
case "term" return
collection($config:register-root)/id($root)//tei:taxonomy
case "work" return
collection($config:register-root)/id($root)//tei:listBibl
default return
collection($config:register-root)/id($root)//tei:listPerson
};
Expand All @@ -116,10 +121,7 @@ declare function rapi:prepare-record($node as item()*, $resp, $type) {
let $id := if ($node/@xml:id=$new) then rapi:next($type) else $node/@xml:id

return
typeswitch($node)
case element(tei:person)
return
element {node-name($node)} {
element {node-name($node)} {
(: copy attributes :)
for $att in $node/@* except ($node/@xml:id, $node/@resp, $node/@when)
return
Expand All @@ -134,27 +136,6 @@ declare function rapi:prepare-record($node as item()*, $resp, $type) {
for $child in $node/node()
return $child
}
case element(tei:place)
return
element {node-name($node)} {
(: copy attributes :)
for $att in $node/@* except ($node/@xml:id, $node/@resp, $node/@when)
return
$att
,
attribute xml:id {$id}
,
attribute when {format-date(current-date(), '[Y]-[M,2]-[D,2]')}
,
attribute resp {$resp}
,
for $child in $node/node()
return $child
}
(: all the rest pass it through :)
default
return $node

};

(:~
Expand All @@ -171,6 +152,12 @@ declare function rapi:next($type) {
switch ($type)
case 'place'
return collection($config:register-root)/id($config?id)//tei:place[starts-with(@xml:id, $config?prefix)]/substring-after(@xml:id, $config?prefix)
case 'organization'
return collection($config:register-root)/id($config?id)//tei:org[starts-with(@xml:id, $config?prefix)]/substring-after(@xml:id, $config?prefix)
case 'term'
return collection($config:register-root)/id($config?id)//tei:category[starts-with(@xml:id, $config?prefix)]/substring-after(@xml:id, $config?prefix)
case 'work'
return collection($config:register-root)/id($config?id)//(tei:bibl|tei:biblStruct)[starts-with(@xml:id, $config?prefix)]/substring-after(@xml:id, $config?prefix)
default
return collection($config:register-root)/id($config?id)//tei:person[starts-with(@xml:id, $config?prefix)]/substring-after(@xml:id, $config?prefix)

Expand All @@ -179,7 +166,7 @@ declare function rapi:next($type) {
try {
xs:integer($last) + 1
} catch * {
'_error'
1
}

return $config?prefix || rapi:pad($next, 6)
Expand Down Expand Up @@ -250,6 +237,15 @@ declare function rapi:query($type as xs:string, $query as xs:string?) {
"id": $term/@xml:id/string(),
"label": $term/tei:catDesc/string()
}
case "work" return
for $bibl in collection($config:register-root)//tei:bibl[ft:query(tei:title, $query)]
return
map {
"id": $bibl/@xml:id/string(),
"label": $bibl/tei:title[@type="main"]/string(),
"details": ``[`{$bibl/tei:author}`; `{$bibl/tei:note/string()}`]``,
"link": $bibl/tei:ptr/@target/string()
}
default return
()
} catch * {
Expand Down Expand Up @@ -337,6 +333,16 @@ declare function rapi:create-record($type as xs:string, $id as xs:string, $data
<category xmlns="http://www.tei-c.org/ns/1.0" xml:id="{$id}">
<catDesc>{$data?name}</catDesc>
</category>
case "work" return
<bibl xmlns="http://www.tei-c.org/ns/1.0" xml:id="{$id}">
<title type="main">{$data?name}</title>
{
rapi:process-array($data?firstAuthor, function($item) {
<author xmlns="http://www.tei-c.org/ns/1.0">{$item?label}</author>
})
}
<note>{$data?note}</note>
</bibl>
default return
()
};
Expand Down Expand Up @@ -379,6 +385,7 @@ declare function rapi:local-search-strings($type as xs:string, $entry as element
case "place" return $entry/tei:placeName/string()
case "organization" return $entry/tei:orgName/string()
case "term" return $entry/tei:catDesc/string()
case "work" return $entry/tei:title/string()
default return $entry/tei:persName/string()
};

Expand Down
Loading