Skip to content

Commit

Permalink
Merge branch '82-corpus-query-and-layout-fixes' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
simar0at committed Jul 18, 2024
2 parents eb2df40 + 0999d02 commit 90a5cb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1915,15 +1915,15 @@ declare function vicav:_search_corpus($query as xs:string, $print as xs:string?,
let $docId := tokenize($line/Refs/_[2], '=')[2]
(:$docUandIds := if not((map:contains($docUandIds, $key))) then map:put($docUandIds, $key, []) else $docUandIds:)
let $tokenId := if (count($line/Kwic/_) > 0) then
tokenize($line/Kwic/_[1]/str/text(), '\s')
tokenize(normalize-space($line/Kwic/_[1]/str/text()), '\s')
else if (count($line/Left/_) > 0) then
$line/Left/_[1]/text()
else if (count($line/Right/_) > 0) then
$line/Right/_[1]/text() else ""
let $u := collection('vicav_corpus')
/descendant::tei:TEI[./tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[ends-with(@type, "CorpusID")]/text() = $docId]
/tei:text/tei:body/tei:div/tei:annotationBlock/tei:u[@xml:id = $uId]
return <hit u="{$uId}" doc="{$docId}">{$u}{$tokenId!<token>{normalize-space(.)}</token>}</hit>}</hits>
return <hit u="{$uId}" doc="{$docId}">{$u}{$tokenId!<token>{.}</token>}</hit>}</hits>
(: , $_ := admin:write-log(serialize($hits), 'INFO') :)
(: , $_ := file:write(file:resolve-path('hits.xml', file:base-dir()), $hits, map { "method": "xml"}) :)

Expand Down
44 changes: 28 additions & 16 deletions xslt/corpus_search_result_json.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:acdh="http://acdh.oeaw.ac.at"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="tei acdh"
version="2.0">

<xsl:output method="xml" indent="yes"/>
<xsl:param name="query"></xsl:param>
<xsl:param name="exit-on-node-index-not-found">no</xsl:param>

<xsl:function name="acdh:index-of-node">
<xsl:function name="acdh:index-of-node" as="xs:int">
<xsl:param name="nodes"></xsl:param>
<xsl:param name="search"></xsl:param>
<xsl:variable name="ret" as="xs:int?">
<xsl:for-each select="$nodes">
<xsl:variable name="pos" select="position()"/>
<xsl:if test=". is $search">
<xsl:value-of select="$pos"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$ret"><xsl:value-of select="$ret"/></xsl:when>
<xsl:otherwise>
<xsl:message terminate="{$exit-on-node-index-not-found}">Could not find index of node with xml:id <xsl:value-of select="$search/@xml:id"/></xsl:message>
0
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="acdh:render-hit">
<xsl:param name="hit"/>

<xsl:variable name="token" select="$hit/token/text()"/>
<xsl:variable name="w" select="$hit/tei:u/tei:w[@xml:id = $token]"/>
<xsl:variable name="w" select="$hit//tei:w[@xml:id = $token]"/>

<xsl:variable select="acdh:index-of-node($hit/tei:u/tei:w, $w[1])" name="word_pos_start"/>
<xsl:variable select="acdh:index-of-node($hit/tei:u/tei:w, $w[last()])" name="word_pos_end"/>
Expand Down Expand Up @@ -91,24 +102,25 @@
</xsl:template>

<xsl:template match="hits">
<xsl:variable select="." name="hits"/>
<query><xsl:value-of select="$query"/></query>
<hits>

<xsl:for-each select="./hit">
<xsl:variable select="." name="hit"/>
<_ type="object">
<xsl:apply-templates select="./@*"/>
<docHits>
<xsl:for-each select="$hits/hit[./@doc = $hit/@doc]/token">
<_ type="string"><xsl:value-of select="."/></_>
</xsl:for-each>
</docHits>
<content><xsl:sequence select="acdh:render-hit(.)"/></content>
</_>
</xsl:for-each>
<xsl:apply-templates select="./hit"/>
</hits>
</xsl:template>

<xsl:template match="hit">
<xsl:variable select=".." name="hits"/>
<xsl:variable select="." name="hit"/>
<_ type="object">
<xsl:apply-templates select="./@*"/>
<docHits>
<xsl:for-each select="$hits/hit[./@doc = $hit/@doc]/token">
<_ type="string"><xsl:value-of select="."/></_>
</xsl:for-each>
</docHits>
<content><xsl:sequence select="acdh:render-hit(.)"/></content>
</_>
</xsl:template>

<xsl:template match="@*">
<xsl:element name="{local-name()}"><xsl:value-of select="."/></xsl:element>
Expand Down

0 comments on commit 90a5cb0

Please sign in to comment.