Skip to content

Commit

Permalink
Merge pull request #79 from acdh-oeaw/data-lists-fix
Browse files Browse the repository at this point in the history
Label endpoints
  • Loading branch information
simar0at authored May 14, 2024
2 parents f9142bd + 39f6424 commit 5051e9a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 14 deletions.
58 changes: 44 additions & 14 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <rs type="{count($out2)}">{$out2}</rs>
(: <res>{$out}</res> :)
(: <res>{$query}</res> :)
Expand Down Expand Up @@ -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 <rs>{$out}</rs>
};

Expand Down Expand Up @@ -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 <rs>{$out}</rs>
};

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 <feature ana="{$ana}">{$features[./@ana = $ana][1]/tei:lbl/text()}</feature>

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()))),
<features>{$out}</features>)
};
Expand Down Expand Up @@ -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&#160;]', '')
Expand All @@ -1490,6 +1515,11 @@ function vicav:get_sample_words($type as xs:string*) {
</word>

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()))),
<words>{$out}</words>)
};
Expand Down Expand Up @@ -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 <rs>{$out}</rs>
};

Expand Down Expand Up @@ -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 <rs>{$out}</rs>
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2044,5 +2074,5 @@ declare function vicav:_get_dict_markers() {
"name": "Baghdad",
"hitCount": 1
}}
], map{"method": "json"})
], map{"method": "json", "indent": "no"})
};
31 changes: 31 additions & 0 deletions xslt/data_words-json.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:_="urn:_"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:err="http://www.w3.org/2005/xqt-errors"
exclude-result-prefixes="xd _ xs err"
version="3.1">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> May 9, 2024</xd:p>
<xd:p><xd:b>Author:</xd:b>Maura Zsofia Abraham</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>

<xsl:template match="/">
<json arrays="json">
<xsl:apply-templates select=".//word"/>
</json>
</xsl:template>

<xd:doc>
<xd:desc>One word</xd:desc>
</xd:doc>
<xsl:template match="word">
<_ type="string">
<xsl:value-of select="."/>
</_>
</xsl:template>
</xsl:stylesheet>
32 changes: 32 additions & 0 deletions xslt/feature_labels-json.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:_="urn:_"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:err="http://www.w3.org/2005/xqt-errors"
exclude-result-prefixes="xd _ xs err"
version="3.1">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> May 9, 2024</xd:p>
<xd:p><xd:b>Author:</xd:b>Maura Zsofia Abraham</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>

<xsl:template match="/">
<json arrays="json">
<xsl:apply-templates select=".//feature"/>
</json>
</xsl:template>

<xd:doc>
<xd:desc>One marker</xd:desc>
</xd:doc>
<xsl:template match="feature">
<_ type="object">
<value><xsl:value-of select="@ana" /></value>
<label><xsl:value-of select="."/></label>
</_>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 5051e9a

Please sign in to comment.