sbsdev / dtbook2sbsform

Convert DTBook to SBSForm, an intermediate format to produce formatted braille
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Fehlerhafte Übersetzung bei mixed emphasis, wenn Fortsetzungspunkte vorkommen #11

Closed egli closed 5 years ago

egli commented 6 years ago

Eingabe:

<p><em>kursiv</em>blo</p>
<p>bla<em>kursiv</em></p>
<p>bla<em>kursiv</em>blo</p>

<p><em>kursiv</em>...blo</p>
<p>bla...<em>kursiv</em></p>
<p>bla...<em>kursiv</em>...blo</p>

Ausgabe g2 IST:

y P
 _KURSIV'.BLO         richtig
y P
 BLA'_KURSIV          richtig
y P
 BLA'_KURSIV'.BLO     richtig
y P
 _KURSIV...BLO        falsch
y P
 BLA..._KURSIV        falsch
y P
 BLA..._KURSIV...BLO  falsch

Ausgabe g2 SOLL:

y P
 _KURSIV'.BLO
y P
 BLA'_KURSIV
y P
 BLA'_KURSIV'.BLO
y P
 _KURSIV'....BLO
y P
 BLA...'_KURSIV
y P
 BLA...'_KURSIV'....BLO 

Mögliches Vorgehen: Anpassung von dtbook2sbsform.xsl (template match="dtb:strong|dtb:em|brl:emph|dtb:dfn")

IST:

<!-- Its a single word. Insert a single word announcement unless it is within a word -->
<xsl:choose>
  <!-- emph is at the beginning of the word -->
  <xsl:when
    test="my:ends-with-non-word(preceding-sibling::text()[1]) and my:starts-with-word(following-sibling::text()[1])">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255F;')"/>
    <xsl:apply-templates/>
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x2561;')"/>
  </xsl:when>
  <!-- emph is at the end of the word -->
  <xsl:when
    test="my:ends-with-word(preceding-sibling::text()[1]) and my:starts-with-non-word(following-sibling::text()[1])">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255E;')"/>
    <xsl:apply-templates/>
  </xsl:when>
  <!-- emph is inside the word -->
  <xsl:when
    test="my:ends-with-word(preceding-sibling::text()[1]) and my:starts-with-word(following-sibling::text()[1])">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255E;')"/>
    <xsl:apply-templates/>
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x2561;')"/>
  </xsl:when>
<xsl:otherwise>

SOLL:

<!-- Its a single word. Insert a single word announcement unless it is within a word -->
<xsl:choose>
  <!-- emph is inside the word -->
  <xsl:when
    test="matches(preceding-sibling::text()[1],'\w$|\.\.\.$') and matches(following-sibling::text()[1],'^\w|^\.\.\.')">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255E;')"/>
    <xsl:apply-templates/>
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x2561;')"/>
  </xsl:when>
  <!-- emph is at the beginning of the word -->
  <xsl:when
    test="my:ends-with-non-word(preceding-sibling::text()[1]) and matches(following-sibling::text()[1],'^\w|^\.\.\.')">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255F;')"/>
    <xsl:apply-templates/>
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x2561;')"/>
  </xsl:when>
  <!-- emph is at the end of the word -->
  <xsl:when
    test="matches(preceding-sibling::text()[1],'\w$|\.\.\.$') and matches(following-sibling::text()[1],'^\w|^\.\.\.')">
    <xsl:value-of select="louis:translate(string($braille_tables), '&#x255E;')"/>
    <xsl:apply-templates/>
  </xsl:when>
<xsl:otherwise>
  1. Bedingung 3 (emph is inside the word) vorwegnehmen, weil sonst Bedingungen 1 bzw. 2 zuerst wahr sind.
  2. my:ends-with-word(preceding-sibling::text()[1]) --> matches(preceding-sibling::text()[1],'\w$|\.\.\.$')
  3. my:starts-with-word(following-sibling::text()[1]) --> matches(following-sibling::text()[1],'^\w|^\.\.\.')
egli commented 5 years ago

The last option, to let liblouis handle the emphasis, probably isn't really a real option: Since we send each xml fragment separately to liblouis I doubt we'd get correct results if an emphasis goes across xml nodes such as in the follwoing example:

<p>This is a <em>tiny example of an <abbr>ICU</abbr></em>