Skip to content

Commit

Permalink
Merge pull request #105 from acdh-oeaw/audio-filtes
Browse files Browse the repository at this point in the history
Audio file url for curpus text utterances
  • Loading branch information
simar0at authored Jan 9, 2025
2 parents 8255d6b + 56525c3 commit 0bed899
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
23 changes: 20 additions & 3 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -2394,6 +2394,19 @@ declare function vicav:_corpus_text(
let $s := if (empty($size)) then 10 else $size

let $hits_str := if (not(empty($hits))) then $hits else ""

(: TODO: use this and replace assets root :)
let $assetsBaseURIpattern := collection("vicav_corpus")
/tei:teiCorpus/tei:teiHeader/tei:encodingDesc/tei:listPrefixDef
/tei:prefixDef[@ident="assets"]/@matchPattern
let $assetsBaseURIto := collection("vicav_corpus")
/tei:teiCorpus/tei:teiHeader/tei:encodingDesc/tei:listPrefixDef
/tei:prefixDef[@ident="assets"]/@replacementPattern
(: let $assetsBaseURI := replace(
concat("assets:", $assetsBaseURIpattern), $assetsBaseURIto
) :)

let $baseURI := try { replace(util:get-base-uri-public(), '/vicav/corpus_text', '/static/sound/') } catch basex:http { '' }

let $teiDoc := collection('vicav_corpus')
//tei:TEI[./tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[ends-with(@type, 'CorpusID')]/text() = $docId],
Expand Down Expand Up @@ -2434,11 +2447,15 @@ declare function vicav:_corpus_text(
return if (matches($accept-header, '[+/]json'))
then
let $out := xslt:transform($doc, 'xslt/corpus_utterances_json.xslt', map{
"hits_str": $hits_str
"hits_str": $hits_str, "assetsBaseURIpattern": $assetsBaseURIpattern,
"assetsBaseURIto": $assetsBaseURIto
})
return serialize($out, map {"method": "json", "indent": "no"})
else
let $out := vicav:transform($doc, 'corpus_utterances.xslt', $print, map{ "hits_str": $hits_str })
let $out := vicav:transform($doc, 'corpus_utterances.xslt', $print,
map{ "hits_str": $hits_str,
"assetsBaseURIpattern": $assetsBaseURIpattern,
"assetsBaseURIto": $assetsBaseURIto })
return $out
};

Expand Down Expand Up @@ -2579,4 +2596,4 @@ declare function vicav:_get_dict_markers() {
"hitCount": 1
}}
], map{"method": "json", "indent": "no"})
};
};
16 changes: 13 additions & 3 deletions xslt/corpus_utterances_json.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<xsl:preserve-space elements="span"/>

<xsl:param name="hits_str"/>
<xsl:param name="assetsBaseURIpattern" />
<xsl:param name="assetsBaseURIto" />

<xsl:template match="/">
<json objects="json" arrays="utterances">
Expand All @@ -19,10 +21,10 @@
<xsl:variable name="hits" select="tokenize($hits_str, ',')" />
<xsl:variable name="html">
<div class="u">
<xsl:attribute name="id" select="$u/@xml:id"/>
<!-- <xsl:attribute name="id" select="$u/@xml:id"/>
<div class="xml-id">
<xsl:value-of select="$u/@xml:id"/>
</div>
</div> -->
<div class="content">
<xsl:variable name="ana-exists" select="exists($u//@ana)"/>
<xsl:for-each select="$u/*">
Expand Down Expand Up @@ -72,11 +74,19 @@
<xsl:for-each select="./tei:u">
<_ type="object">
<id><xsl:value-of select="@xml:id"/></id>
<audio>
<xsl:if test="./tei:media[@mimeType='audio/mp3']">
<xsl:value-of select="replace(
replace(./tei:media[@mimeType='audio/mp3'][1]/@url, 'assets:', ''),
$assetsBaseURIpattern,
$assetsBaseURIto)" />
</xsl:if>
</audio>
<content>
<xsl:apply-templates select="acdh:render-u(.)"/>
</content>
</_>
</xsl:for-each>
</utterances>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

0 comments on commit 0bed899

Please sign in to comment.