diff --git a/vicav.xqm b/vicav.xqm index 5a4d90c..697a922 100644 --- a/vicav.xqm +++ b/vicav.xqm @@ -174,7 +174,7 @@ declare function vicav:get_featurelist() { } )) - return json:parse(serialize($result, map {"method": "json"}), map {"format": "direct"})/json/* + return json:parse(serialize($result, map {"method": "json", "indent": "no"}), map {"format": "direct"})/json/* }; declare @@ -1295,7 +1295,7 @@ declare function vicav:_get_bibl_markers_tei($query as xs:string, $scope as xs:s "target-type": "BiblioEntries", "current-query": $current-query }) - return serialize($renderedJson, map {"method": "json"}) + return serialize($renderedJson, map {"method": "json", "indent": "no"}) else {$out2} (: {$out} :) (: {$query} :) @@ -1342,7 +1342,7 @@ declare function vicav:_get_profile_markers() { then let $renderedJson := xslt:transform(<_>{$out}, 'xslt/bibl-markers-json.xslt', map{ "target-type": "Profile" }) - return serialize($renderedJson, map {"method": "json"}) + return serialize($renderedJson, map {"method": "json", "indent": "no"}) else {$out} }; @@ -1424,20 +1424,37 @@ declare function vicav:_get_sample_markers() { then let $renderedJson := xslt:transform(<_>{$out}, 'xslt/bibl-markers-json.xslt', map{"target-type": "SampleText"}) - return serialize($renderedJson, map {"method": "json"}) + return serialize($renderedJson, map {"method": "json", "indent": "no"}) else {$out} }; declare %rest:path("/vicav/feature_labels") %rest:GET - +%rest:produces("application/xml") +%rest:produces("application/json") +%rest:produces('application/problem+json') +%rest:produces('application/problem+xml') function vicav:get_feature_labels() { + api-problem:or_result (prof:current-ns(), + vicav:_get_feature_labels#0, [], map:merge((cors:header(()), vicav:return_content_header())) + ) +}; + +declare +function vicav:_get_feature_labels() { + let $accept-header := try { request:header("ACCEPT") } catch basex:http { 'application/xhtml+xml' } + let $features := collection('vicav_lingfeatures' || vicav:get_project_db())/descendant::tei:TEI//tei:cit[@type="featureSample"] let $out := for $ana in distinct-values($features/@ana) return {$features[./@ana = $ana][1]/tei:lbl/text()} - return + + return if (matches($accept-header, '[+/]json')) + then let $renderedJson := xslt:transform(<_>{$out}, + 'xslt/feature_labels-json.xslt') + return serialize($renderedJson, map {"method": "json", "indent": "no"}) + else (web:response-header(map {'method': 'xml'}, map:merge((cors:header(()), vicav:return_content_header()))), {$out}) }; @@ -1469,12 +1486,20 @@ declare %rest:path("/vicav/data_words") %rest:query-param("type", "{$type}") %rest:GET +%rest:produces("application/xml") +%rest:produces("application/json") +%rest:produces('application/problem+json') +%rest:produces('application/problem+xml') +function vicav:get_data_words($type as xs:string*) { + api-problem:or_result (prof:current-ns(), + vicav:_get_data_words#1, [$type], map:merge((cors:header(()), vicav:return_content_header())) + ) +}; -function vicav:get_sample_words($type as xs:string*) { +declare function vicav:_get_data_words($type as xs:string*) { + let $accept-header := try { request:header("ACCEPT") } catch basex:http { 'application/xhtml+xml' } let $type := if ($type = () or $type = '') then 'samples' else $type - - let $persons := if ($type = 'samples') then for $w in collection('vicav_' || $type || vicav:get_project_db())/tei:teiCorpus/tei:TEI/tei:text/tei:body/tei:div[@type="sampleText"]/tei:p/tei:s//tei:w/tei:fs/tei:f[@name="wordform"]/text() return replace(normalize-space($w), '[\s ]', '') @@ -1490,6 +1515,11 @@ function vicav:get_sample_words($type as xs:string*) { return + if (matches($accept-header, '[+/]json')) + then let $renderedJson := xslt:transform(<_>{$out}, + 'xslt/data_words-json.xslt') + return serialize($renderedJson, map {"method": "json", "indent": "no"}) + else (web:response-header(map {'method': 'xml'}, map:merge((cors:header(()), vicav:return_content_header()))), {$out}) }; @@ -1544,7 +1574,7 @@ declare function vicav:_get_feature_markers() { then let $renderedJson := xslt:transform(<_>{$out}, 'xslt/bibl-markers-json.xslt', map{"target-type": "Feature"}) - return serialize($renderedJson, map {"method": "json"}) + return serialize($renderedJson, map {"method": "json", "indent": "no"}) else {$out} }; @@ -1588,7 +1618,7 @@ declare function vicav:_get_all_data_markers() { return if (matches($accept-header, '[+/]json')) then let $renderedJson := xslt:transform(<_>{$out}, 'xslt/bibl-markers-json.xslt') - return serialize($renderedJson, map {"method": "json"}) + return serialize($renderedJson, map {"method": "json", "indent": "no"}) else {$out} }; @@ -1860,7 +1890,7 @@ declare function vicav:_search_corpus($query as xs:string, $print as xs:string?, return if (matches($accept-header, '[+/]json')) then let $transformedOutput := xslt:transform($hits, 'xslt/corpus_search_result_json.xslt', map{ 'query': $query}) - return serialize($transformedOutput, map {"method": "json"}) + return serialize($transformedOutput, map {"method": "json", "indent": "no"}) else let $out := vicav:transform($hits, $xslt, $print, map{ 'query': $query }) return $out @@ -1902,7 +1932,7 @@ declare function vicav:_corpus_text( let $out := xslt:transform($doc, 'xslt/corpus_utterances_json.xslt', map{ "hits_str": $hits_str }) - return serialize($out, map {"method": "json"}) + return serialize($out, map {"method": "json", "indent": "no"}) else let $out := vicav:transform($doc, 'corpus_utterances.xslt', $print, map{ "hits_str": $hits_str }) return $out @@ -2044,5 +2074,5 @@ declare function vicav:_get_dict_markers() { "name": "Baghdad", "hitCount": 1 }} - ], map{"method": "json"}) + ], map{"method": "json", "indent": "no"}) }; \ No newline at end of file diff --git a/xslt/data_words-json.xslt b/xslt/data_words-json.xslt new file mode 100644 index 0000000..921120e --- /dev/null +++ b/xslt/data_words-json.xslt @@ -0,0 +1,31 @@ + + + + + Created on: May 9, 2024 + Author:Maura Zsofia Abraham + + + + + + + + + + + + One word + + + <_ type="string"> + + + + \ No newline at end of file diff --git a/xslt/feature_labels-json.xslt b/xslt/feature_labels-json.xslt new file mode 100644 index 0000000..6e7d90c --- /dev/null +++ b/xslt/feature_labels-json.xslt @@ -0,0 +1,32 @@ + + + + + Created on: May 9, 2024 + Author:Maura Zsofia Abraham + + + + + + + + + + + + One marker + + + <_ type="object"> + + + + + \ No newline at end of file