Skip to content

Commit

Permalink
update wibarab eaturelist query
Browse files Browse the repository at this point in the history
  • Loading branch information
kisram committed Nov 28, 2024
1 parent 4615f4f commit e69b887
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion listquery.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ declare
};

declare function _:_featurelist(){
serialize(<json type="object">{vicav:get_featurelist()/*}</json>, map { "method": "json", "indent": "yes" })
serialize(<json type="object">{vicav:get_featurelist()}</json>, map { "method": "json", "indent": "yes" })
};
52 changes: 28 additions & 24 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
))
Expand All @@ -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
Expand Down

0 comments on commit e69b887

Please sign in to comment.