From 24acee8378b581ee712e30ad50f2600b72aa4eed Mon Sep 17 00:00:00 2001 From: Oleg Belyaev Date: Fri, 21 Mar 2025 19:48:27 +0300 Subject: [PATCH] added glosses to entry API --- xq/restx_api.xq | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xq/restx_api.xq b/xq/restx_api.xq index 20d7094..90cc9d5 100644 --- a/xq/restx_api.xq +++ b/xq/restx_api.xq @@ -22,8 +22,22 @@ declare function api:ment-index($db-lang as xs:string) { (: Short entry info (only forms for now). Hash is used because URLs don't handle some Unicode characters very well in this system :) declare function api:entry-info-short($n as node()) -as map(xs:string, xs:string) { - map{'id': string(hash($n/@xml:id)), 'xmlid': $n/@xml:id, 'form': $n/text()} +as map(xs:string, item()) { + map{'id': string(hash($n/@xml:id)), + 'xmlid': string($n/@xml:id), + 'form': $n/text() + } +}; + +declare function api:entry-info-long($n as node(), $db-lang as xs:string) +as map(xs:string, item()) { + map:merge( + ( + api:entry-info-short($n), + map{'glosses': array:build(data(doc(`abaevdict_{$db-lang}/xml/{$n/@xml:id}.xml`) + /tei:entry[1]/tei:sense/(tei:sense|tei:sense/tei:sense|.)/tei:cit/tei:quote))} + ) +) }; (: Short language info -- for the language list :) @@ -168,8 +182,9 @@ declare %rest:path("{$db-lang}/api/entries/{$entry-id}") %rest:GET function api:entries($db-lang as xs:string, $entry-id as xs:string) { - api:entry-info-short( - $lookup/tei:table[1]/tei:entry[string(hash(@xml:id))=$entry-id]) + api:entry-info-long( + $lookup/tei:table[1]/tei:entry[string(hash(@xml:id))=$entry-id], + $db-lang) }; 0 \ No newline at end of file