Skip to content

Commit

Permalink
Implement Multiterm TBX
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-jung committed Jul 21, 2024
1 parent a365721 commit 30d3890
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 168 deletions.
1 change: 1 addition & 0 deletions frameworks/termentry/rng/termentryMod.rng
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<value>notRecommended</value><a:documentation>The term must not be used.</a:documentation>
<value>obsolete</value><a:documentation>The term is obsolete.</a:documentation>
<value>preferred</value><a:documentation>The term is preferred.</a:documentation>
<value>toBeDiscussed</value><a:documentation>The usage of the term is not yet clear.</a:documentation>
</choice>
</attribute>
</define>
Expand Down
4 changes: 0 additions & 4 deletions org.jung.terminology.xpr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<String>key.editor.open.option.pane</String>
<Boolean>false</Boolean>
</entry>
<entry>
<String>keys.context</String>
<String>${pdu}/samples/terminology.ditamap?oxycontextProjectParent=terminology.xml&amp;oxycontextID=terminology&amp;oxycontextName=Terminology&amp;oxycontextType=GlobalContext</String>
</entry>
<entry>
<String>scenario.associations</String>
<scenarioAssociation-array>
Expand Down
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@

<!-- Import Ant script -->
<feature extension="ant.import" file="ant/build_dita2multiterm-mtf.xml"/>
<feature extension="ant.import" file="ant/build_dita2multiterm-mtf-custom.xml"/>
<feature extension="ant.import" file="ant/build_dita2oxygen-termchecker_template.xml"/>
<feature extension="ant.import" file="ant/build_dita2tbx-basic-v2_template.xml"/>
<feature extension="ant.import" file="ant/build_dita2tbx-basic-v3_template.xml"/>
Expand Down
4 changes: 4 additions & 0 deletions samples/advancedDriverAssistanceSystem.dita
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<partOfSpeech value="noun"/>
<fullForm usage="preferred" language="en-GB">
<termVariant>advanced driver assistance systems</termVariant>
<termContext>
<termContextText>foo</termContextText>
<termContextSource>bar</termContextSource>
</termContext>
</fullForm>
<acronym language="en-GB" usage="preferred">
<termVariant>ADAS</termVariant>
Expand Down
87 changes: 4 additions & 83 deletions xsl/multiterm-custom/multiterm-custom.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
<!-- ================================================== -->
<!-- IMPORTS -->
<!-- ================================================== -->
<xsl:import href="multiterm-language-name.xsl"/>
<xsl:import href="multiterm-language-code.xsl"/>
<xsl:import href="../multiterm/multiterm-common.xsl"/>


<!-- ================================================== -->
Expand All @@ -29,92 +28,14 @@
<xsl:variable name="newline" select="'&#xa;'" as="xs:string"/>


<!-- ================================================== -->
<!-- MODES -->
<!-- ================================================== -->
<xsl:mode name="termref" on-no-match="shallow-skip"/>
<xsl:mode name="termentry" on-no-match="shallow-skip"/>
<xsl:mode name="termNotation" on-no-match="shallow-skip"/>
<xsl:mode name="termVariant" on-no-match="shallow-skip"/>
<xsl:mode name="definition" on-no-match="shallow-skip"/>
<xsl:mode name="definitionText" on-no-match="shallow-skip"/>
<xsl:mode name="definitionSource" on-no-match="shallow-skip"/>

<!-- ================================================== -->
<!-- TEMPLATES -->
<!-- ================================================== -->

<xsl:template match="/">
<Schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<mtf>
<xsl:apply-templates mode="termref"/>
</mtf>
</Schema>
</xsl:template>

<xsl:template match="*[contains(@class, ' termmap/termgroup ')]" mode="termref">
<xsl:apply-templates mode="termref"/>
</xsl:template>

<xsl:template match="*[contains(@class, ' termmap/termref ')][@href][@keys]" mode="termref">
<xsl:variable name="filename" select="@href" as="xs:string"/>
<xsl:variable name="t" select="xs:anyURI($dita.temp.dir.url || $filename)" as="xs:anyURI"/>
<xsl:variable name="conceptNumber" select="count(preceding-sibling::*[contains(@class, ' termmap/termref ')]) + 1" as="xs:integer"/>
<xsl:apply-templates select="document($t)" mode="termentry">
<xsl:with-param name="conceptNumber" select="$conceptNumber" as="xs:integer"/>
</xsl:apply-templates>
</xsl:template>

<!-- Create rules for all termentry topics -->
<xsl:template match="*[contains(@class, ' termentry/termentry ')]" mode="termentry">
<xsl:param name="conceptNumber" as="xs:integer" required="true"/>
<xsl:variable name="termentry-root" select="." as="node()"/>
<conceptGrp>
<concept><xsl:value-of select="$conceptNumber"/></concept>
<system type="entryClass"/>
<transacGrp>
<!--<transac type="origination">ST</transac>-->
<date><xsl:value-of select="current-dateTime()"/></date>
</transacGrp>
<xsl:apply-templates mode="definition"/>

<!--<xsl:variable name="languages">
<xsl:for-each select="distinct-values(//@language)">
<xsl:value-of select="distinct-values(.) || ','"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="tokenize($languages, ',')">
<xsl:variable name="language" select="normalize-space(.)"/>
<xsl:if test="$language != ''">
<langSec xml:lang="{$language}">
<xsl:apply-templates select="$termentry-root//*[contains(@class, ' termentry/termNotation ')][@language = $language]" mode="termNotation"/>
</langSec>
</xsl:if>
</xsl:for-each>-->
</conceptGrp>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definition ')]" mode="definition">
<descripGrp>
<xsl:apply-templates mode="definitionText"/>
<xsl:apply-templates mode="definitionSource"/>
</descripGrp>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definitionText ')]" mode="definitionText">
<descrip type="Definition">
<xsl:value-of select="."/>
</descrip>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definitionSource ')]" mode="definitionSource">
<descripGrp>
<descrip type="Source">
<xsl:value-of select="."/>
</descrip>
</descripGrp>
<mtf>
<xsl:apply-templates mode="termref"/>
</mtf>
</xsl:template>


</xsl:stylesheet>
149 changes: 149 additions & 0 deletions xsl/multiterm/multiterm-common.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sj="https://stefan-jung.org"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="sj xs"
version="3.0">

<!-- This template is used by multiterm and multiterm-custom -->

<!-- ================================================== -->
<!-- IMPORTS -->
<!-- ================================================== -->
<xsl:import href="multiterm-language-name.xsl"/>
<xsl:import href="multiterm-language-code.xsl"/>
<xsl:import href="multiterm-usage.xsl"/>


<!-- ================================================== -->
<!-- PARAMETERS -->
<!-- ================================================== -->
<xsl:param name="dita.temp.dir.url" as="xs:string"/>

<!-- License info to be added to the header -->
<xsl:param name="license" as="xs:string" required="false" select="''"/>

<!-- The parameter $newline defines a line break. -->
<xsl:variable name="newline" select="'&#xa;'" as="xs:string"/>

<xsl:variable name="dateTimePattern" select="'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'" as="xs:string"/>


<!-- ================================================== -->
<!-- MODES -->
<!-- ================================================== -->
<xsl:mode name="definition" on-no-match="shallow-skip"/>
<xsl:mode name="definitionSource" on-no-match="shallow-skip"/>
<xsl:mode name="definitionText" on-no-match="shallow-skip"/>
<xsl:mode name="termVariant" on-no-match="shallow-skip"/>
<xsl:mode name="termcontext" on-no-match="shallow-skip"/>
<xsl:mode name="termentry" on-no-match="shallow-skip"/>
<xsl:mode name="termnotation" on-no-match="shallow-skip"/>
<xsl:mode name="termref" on-no-match="shallow-skip"/>


<!-- ================================================== -->
<!-- TEMPLATES -->
<!-- ================================================== -->
<xsl:template match="*[contains(@class, ' termmap/termgroup ')]" mode="termref">
<xsl:apply-templates mode="termref"/>
</xsl:template>

<xsl:template match="*[contains(@class, ' termmap/termref ')][@href][@keys]" mode="termref">
<xsl:variable name="filename" select="@href" as="xs:string"/>
<xsl:variable name="t" select="xs:anyURI($dita.temp.dir.url || $filename)" as="xs:anyURI"/>
<xsl:variable name="conceptNumber" select="count(preceding-sibling::*[contains(@class, ' termmap/termref ')]) + 1" as="xs:integer"/>
<xsl:apply-templates select="document($t)" mode="termentry">
<xsl:with-param name="conceptNumber" select="$conceptNumber" as="xs:integer"/>
</xsl:apply-templates>
</xsl:template>

<!-- Create rules for all termentry topics -->
<xsl:template match="*[contains(@class, ' termentry/termentry ')]" mode="termentry">
<xsl:param name="conceptNumber" as="xs:integer" required="true"/>
<xsl:variable name="termentry-root" select="." as="node()"/>
<conceptGrp>
<concept><xsl:value-of select="$conceptNumber"/></concept>
<system type="entryClass">Unspecified</system>
<transacGrp>
<transac type="origination">ST</transac>
<date><xsl:value-of select="format-dateTime(current-dateTime(), $dateTimePattern)"/></date>
</transacGrp>
<xsl:apply-templates mode="definition"/>
<xsl:apply-templates mode="termnotation">
<xsl:with-param name="part-of-speech" select="//*[contains(@class, ' termentry/partOfSpeech ')]/@value"/>
</xsl:apply-templates>

<!--<xsl:variable name="languages">
<xsl:for-each select="distinct-values(//@language)">
<xsl:value-of select="distinct-values(.) || ','"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="tokenize($languages, ',')">
<xsl:variable name="language" select="normalize-space(.)"/>
<xsl:if test="$language != ''">
<langSec xml:lang="{$language}">
<xsl:apply-templates select="$termentry-root//*[contains(@class, ' termentry/termNotation ')][@language = $language]" mode="termNotation"/>
</langSec>
</xsl:if>
</xsl:for-each>-->
</conceptGrp>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definition ')]" mode="definition">
<descripGrp>
<xsl:apply-templates mode="definitionText"/>
<xsl:apply-templates mode="definitionSource"/>
</descripGrp>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definitionText ')]" mode="definitionText" expand-text="yes">
<descrip type="Definition">{.}</descrip>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/definitionSource ')]" mode="definitionSource" expand-text="yes">
<descripGrp>
<descrip type="Source">{.}</descrip>
</descripGrp>
</xsl:template>

<!--<fullForm usage="preferred" language="en-GB">
<termVariant>advanced driver assistance systems</termVariant>
</fullForm>-->
<xsl:template match="*[contains(@class, ' termentry/termNotation ')]" mode="termnotation" expand-text="yes">
<xsl:param name="part-of-speech" select="'noun'"/>
<languageGrp type="{sj:language-name(@language)}" lang="{sj:language-code(@language)}">
<termGrp>
<term><xsl:value-of select="*[contains(@class, ' termentry/termVariant ')]"/></term>
<transacGrp>
<transac type="origination">ST</transac>
<date><xsl:value-of select="format-dateTime(current-dateTime(), $dateTimePattern)"/></date>
</transacGrp>
<descripGrp>
<descrip type="Usage">{sj:usage(@usage)}</descrip>
</descripGrp>
<descripGrp>
<descrip type="Part of Speech">{$part-of-speech}</descrip>
</descripGrp>
<xsl:apply-templates mode="termcontext"/>
<!--<descripGrp>
<descrip type="Context"></descrip>
<descripGrp>
<descrip type="Source"></descrip>
</descripGrp>
</descripGrp>-->
</termGrp>
</languageGrp>
</xsl:template>

<xsl:template match="*[contains(@class, ' termentry/termContext ')]" mode="termcontext" expand-text="yes">
<descripGrp>
<descrip type="Context">{*[contains(@class, ' termentry/termContextText ')]/text()}</descrip>
<descripGrp>
<descrip type="Source">{*[contains(@class, ' termentry/termContextSource ')]/text()}</descrip>
</descripGrp>
</descripGrp>
</xsl:template>

</xsl:stylesheet>
4 changes: 2 additions & 2 deletions xsl/multiterm/multiterm-language-code.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<xsl:param name="language-code" as="xs:string"/>
<xsl:sequence select="
if ($language-code = 'en-US') then 'EN-US'
else if ($language-code = 'fi-IF') then 'FI-FI'
else if ($language-code = 'fi-FI') then 'FI-FI'
else if ($language-code = 'fr-FR') then 'FR-FR'
else if ($language-code = 'cs-CZ') then 'CS-CZ'
else if ($language-code = 'da-DK') then 'DA-DK'
Expand Down Expand Up @@ -53,7 +53,7 @@
else if ($language-code = 'th-TH') then 'TH-TH'
else if ($language-code = 'vi-VN') then 'VI-VN'
else if ($language-code = 'en-GB') then 'EN-GB'
else 'UNDEFINED'
else $language-code || ' UNDEFINED'
"/>
</xsl:function>

Expand Down
2 changes: 1 addition & 1 deletion xsl/multiterm/multiterm-language-name.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
else if ($language-code = 'th-TH') then 'Thai (Thailand)'
else if ($language-code = 'vi-VN') then 'Vietnamese (Vietnam)'
else if ($language-code = 'en-GB') then 'English (Great Britain)'
else 'UNDEFINED'
else $language-code || ' UNDEFINED'
"/>
</xsl:function>

Expand Down
20 changes: 20 additions & 0 deletions xsl/multiterm/multiterm-usage.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sj="https://stefan-jung.org"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">

<xsl:function name="sj:usage" as="xs:string">
<xsl:param name="usage" as="xs:string"/>
<xsl:sequence select="
if ($usage = 'admitted') then 'allowed'
else if ($usage = 'notRecommended') then 'not recommended'
else if ($usage = 'obsolete') then 'obsolete'
else if ($usage = 'preferred') then 'recommended'
else if ($usage = 'toBeDiscussed') then 'to be discussed'
else $usage || ' UNDEFINED'
"/>
</xsl:function>

</xsl:stylesheet>
Loading

0 comments on commit 30d3890

Please sign in to comment.