From e69b8879b7667dc85424868df8885044d4e7359e Mon Sep 17 00:00:00 2001 From: kisram Date: Thu, 28 Nov 2024 15:06:14 +0100 Subject: [PATCH] update wibarab eaturelist query --- listquery.xqm | 2 +- vicav.xqm | 52 +++++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/listquery.xqm b/listquery.xqm index eec9c438..49a7d30d 100644 --- a/listquery.xqm +++ b/listquery.xqm @@ -14,5 +14,5 @@ declare }; declare function _:_featurelist(){ - serialize({vicav:get_featurelist()/*}, map { "method": "json", "indent": "yes" }) + serialize({vicav:get_featurelist()}, map { "method": "json", "indent": "yes" }) }; diff --git a/vicav.xqm b/vicav.xqm index bd9b820c..73df9567 100644 --- a/vicav.xqm +++ b/vicav.xqm @@ -188,22 +188,43 @@ declare function vicav:get_variety_data() { collection("wibarab_varieties")//json/* }; -declare function vicav:get_featurelist() { +declare function vicav:get_categories($mainCategories){ + map:merge(( + for $category in $mainCategories + let $id := string($category/@xml:id) + let $title := string($category/tei:catDesc) + let $subcategories := $category/tei:category + return + if (empty($subcategories)) then + map:entry($id, map { "title": $title }) + else + map:entry($id, map { + "title": $title, + "subcategories": map:merge( + for $sub in $subcategories + return map:entry(string($sub/@xml:id), string($sub/tei:catDesc)) + ) + }) + )) +}; + +declare function vicav:get_featurelist(){ let $docs := collection('wibarab_features')//tei:TEI let $result := map:merge(( for $doc in $docs let $filename := fn:tokenize(base-uri($doc), '/')[last()] where starts-with($filename, 'feature') + let $mainCategories := $doc//tei:taxonomy/tei:category return map { string($doc/@xml:id): map { - "title": string($doc//tei:title), - "values": map:merge(( + "values": map:merge( let $items := $doc//tei:list[@type = "featureValues"]/tei:item for $item in $items - return map {string($item/@xml:id): string($item/tei:label)})) + return map:entry(string($item/tei:label),substring(string($item/@corresp), 2))), + "taxonomy": vicav:get_categories($mainCategories) } } )) @@ -215,26 +236,9 @@ declare function vicav:get_taxonomy() { let $docs := collection('wibarab_features')//tei:TEI let $dmp := $docs[fn:tokenize(base-uri(.), '/')[last()] = 'wibarab_dmp.xml'] let $mainCategories := $dmp//tei:taxonomy/tei:category - let $result := - map:merge(( - for $category in $mainCategories - let $id := string($category/@xml:id) - let $title := string($category/tei:catDesc) - let $subcategories := $category/tei:category - return - if (empty($subcategories)) then - map:entry($id, map { "title": $title }) - else - map:entry($id, map { - "title": $title, - "subcategories": map:merge( - for $sub in $subcategories - return map:entry(string($sub/@xml:id), string($sub/tei:catDesc)) - ) - }) - )) - - return json:parse(serialize($result, map {"method": "json", "indent": "no"}), map {"format": "direct"})/json/* + let $result := vicav:get_categories($mainCategories) + + return json:parse(serialize($result, map {"method": "json", "indent": "no"}), map {"format": "direct"})/json/* }; declare