Skip to content

Commit 644fefd

Browse files
Fix LT-22058: In XLingPaper interlinear export, texts get same IDs (#271)
* Fix LT-22058: In XLingPaper interlin export, multiple texts get same IDs * Include files from LT-22059 and LT-22060 * Add unit tests for LT-22058, LT-22059, and LT-22060 * Use TestCase to simplify the tests --------- Co-authored-by: Jake Oliver <jeoliver97@gmail.com>
1 parent 7a1d141 commit 644fefd

26 files changed

+73974
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Src/FwParatextLexiconPlugin/GeneratedParatextLexiconPluginRegistryHelper.cs
4040
Src/Common/FwUtils/GeneratedFwUtils.cs
4141
Src/CommonAssemblyInfo.cs
4242
Src/LangInst/InstallLanguageTests/timing.txt
43+
x64
4344

4445
# other files
4546
*.user

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPap.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Main template
5959
<textTitle><xsl:value-of select="item[@type='title']"/></textTitle>
6060
<shortTitle><xsl:value-of select="item[@type='title-abbreviation']"/></shortTitle>
6161
</textInfo>
62-
<xsl:apply-templates/>
62+
<xsl:apply-templates select="."/>
6363
</interlinear-text>
6464
</xsl:for-each>
6565
</appendix>
@@ -106,6 +106,7 @@ phrase
106106
-->
107107
<xsl:template match="phrase">
108108
<xsl:param name="sScriptureType"/>
109+
<xsl:param name="sThisTextId"/>
109110
<xsl:variable name="sLevel">
110111
<xsl:call-template name="OutputLevelContent">
111112
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapAllCommon.xsl

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<!-- This stylesheet contains the common components for XLingPaper output -->
44

55
<xsl:key name="ItemsLang" match="//item" use="@lang"/>
6-
<xsl:variable name="sThisTextId" select="substring-before(/document/interlinear-text/@guid,'-')"/>
76
<xsl:template match="interlinear-text">
87
<xsl:variable name="sScriptureType">
98
<xsl:variable name="sTitle" select="item[@type='title']"/>
@@ -29,26 +28,34 @@
2928
</xsl:otherwise>
3029
</xsl:choose>
3130
</xsl:variable>
31+
<xsl:variable name="sThisTextId" select="substring-before(@guid,'-')"/>
3232
<xsl:apply-templates>
3333
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>
34+
<xsl:with-param name="sThisTextId" select="$sThisTextId"/>
3435
</xsl:apply-templates>
3536
</xsl:template>
3637
<xsl:template match="paragraph">
3738
<xsl:param name="sScriptureType"/>
39+
<xsl:param name="sThisTextId"/>
3840
<xsl:apply-templates>
3941
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>
42+
<xsl:with-param name="sThisTextId" select="$sThisTextId"/>
4043
</xsl:apply-templates>
4144
</xsl:template>
4245
<xsl:template match="paragraphs">
4346
<xsl:param name="sScriptureType"/>
47+
<xsl:param name="sThisTextId"/>
4448
<xsl:apply-templates>
4549
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>
50+
<xsl:with-param name="sThisTextId" select="$sThisTextId"/>
4651
</xsl:apply-templates>
4752
</xsl:template>
4853
<xsl:template match="phrases">
4954
<xsl:param name="sScriptureType"/>
55+
<xsl:param name="sThisTextId"/>
5056
<xsl:apply-templates>
5157
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>
58+
<xsl:with-param name="sThisTextId" select="$sThisTextId"/>
5259
</xsl:apply-templates>
5360
</xsl:template>
5461
<xsl:template match="phrase[count(item)=0]">
@@ -182,6 +189,25 @@
182189
</xsl:choose>
183190
</xsl:attribute>
184191
</xsl:template>
192+
<!--
193+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194+
GetPortionBeforeLastHyphen
195+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
196+
-->
197+
<xsl:template name="GetPortionBeforeLastHyphen">
198+
<xsl:param name="pText"/>
199+
<xsl:param name="pDelim" select="'-'"/>
200+
<xsl:if test="contains($pText, $pDelim)">
201+
<xsl:value-of select="substring-before($pText, $pDelim)"/>
202+
<xsl:if test="contains(substring-after($pText, $pDelim), $pDelim)">
203+
<xsl:value-of select="$pDelim"/>
204+
</xsl:if>
205+
<xsl:call-template name="GetPortionBeforeLastHyphen">
206+
<xsl:with-param name="pText" select="substring-after($pText, $pDelim)"/>
207+
<xsl:with-param name="pDelim" select="$pDelim"/>
208+
</xsl:call-template>
209+
</xsl:if>
210+
</xsl:template>
185211
<!--
186212
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
187213
GetWordLangAttribute
@@ -216,10 +242,33 @@
216242
-->
217243
<xsl:template name="OutputLanguageElements">
218244
<xsl:variable name="firstMorphemes" select="//paragraphs/paragraph[1]/phrases[1]/phrase[1]/words[1]/word[1]/morphemes/morph[1]/item"/>
219-
<xsl:for-each select="//interlinear-text[1]/languages/language">
245+
<xsl:for-each select="//item[generate-id() = generate-id(key('ItemsLang', @lang)[1])]">
220246
<xsl:variable name="sLangId" select="@lang"/>
221247
<xsl:if test="key('ItemsLang',$sLangId)">
222-
<xsl:variable name="sFont" select="@font"/>
248+
<xsl:variable name="sBeforeLastHyphenId">
249+
<xsl:call-template name="GetPortionBeforeLastHyphen">
250+
<xsl:with-param name="pText" select="$sLangId"/>
251+
</xsl:call-template>
252+
</xsl:variable>
253+
<xsl:variable name="sBeforeFirstHyphenId">
254+
<xsl:value-of select="substring-before($sLangId,'-')"/>
255+
</xsl:variable>
256+
<xsl:variable name="sFont">
257+
<xsl:choose>
258+
<xsl:when test="//language[@lang=$sLangId]">
259+
<xsl:value-of select="//language[@lang=$sLangId]/@font"/>
260+
</xsl:when>
261+
<xsl:when test="//language[@lang=$sBeforeFirstHyphenId]">
262+
<xsl:value-of select="//language[@lang=$sBeforeFirstHyphenId]/@font"/>
263+
</xsl:when>
264+
<xsl:when test="//language[@lang=$sBeforeLastHyphenId]">
265+
<xsl:value-of select="//language[@lang=$sBeforeLastHyphenId]/@font"/>
266+
</xsl:when>
267+
<xsl:otherwise>
268+
<xsl:value-of select="//language[1]/@font"/>
269+
</xsl:otherwise>
270+
</xsl:choose>
271+
</xsl:variable>
223272
<xsl:if test="key('ItemsLang',$sLangId)[parent::phrase and @type='gls']">
224273
<language font-family="{$sFont}" id="{$sLangId}-free"/>
225274
</xsl:if>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapCommonConcatMorphemes.xsl

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Elements to ignore or are handled elsewhere
1515
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1616
-->
1717
<xsl:template name="OutputFreeWithAnyNotes">
18+
<xsl:variable name="sThisTextId" select="substring-before(ancestor::interlinear-text/@guid,'-')"/>
1819
<free>
1920
<xsl:call-template name="GetFreeLangAttribute"/>
2021
<xsl:apply-templates/>
@@ -62,8 +63,10 @@ Elements to ignore or are handled elsewhere
6263
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6364
-->
6465
<xsl:template name="OutputInterlinearContent">
66+
<!-- <xsl:for-each select="words/word[item/@type='txt' or morphemes][1]/descendant-or-self::item">
67+
-->
6568
<lineGroup>
66-
<xsl:for-each select="words/word[item/@type='txt' or morphemes][1]/descendant-or-self::item">
69+
<xsl:for-each select="words/word[item/@type='txt' or morphemes][1]/descendant-or-self::item | words/word/morphemes/morph[1][not(item)]">
6770
<xsl:variable name="sLang" select="@lang"/>
6871
<xsl:choose>
6972
<xsl:when test="parent::word ">
@@ -154,28 +157,18 @@ Elements to ignore or are handled elsewhere
154157
<xsl:with-param name="sLang" select="$sLang"/>
155158
</xsl:call-template>
156159
</xsl:when>
160+
<xsl:when test="name()='morph'">
161+
<!-- first word does not have an analysis -->
162+
<xsl:for-each select="ancestor::word/following-sibling::word[1]/morphemes/morph/item">
163+
<xsl:variable name="sLang2" select="@lang"/>
164+
<xsl:call-template name="ProcessMorphItem">
165+
<xsl:with-param name="sLang" select="$sLang2"/>
166+
</xsl:call-template>
167+
</xsl:for-each>
168+
</xsl:when>
157169
<xsl:when test="parent::morph[count(preceding-sibling::morph)=0]">
158-
<!-- morphemes -->
159-
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
160-
<xsl:with-param name="sType" select="'txt'"/>
161-
<xsl:with-param name="sLang" select="$sLang"/>
162-
</xsl:call-template>
163-
<!-- Lex Entries -->
164-
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
165-
<xsl:with-param name="sType" select="'cf'"/>
166-
<xsl:with-param name="sLang" select="$sLang"/>
167-
</xsl:call-template>
168-
<!-- Gloss -->
169-
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
170-
<xsl:with-param name="sType" select="'gls'"/>
171-
<xsl:with-param name="sLang" select="$sLang"/>
172-
<xsl:with-param name="bAddHyphen" select="'Y'"/>
173-
</xsl:call-template>
174-
<!-- msa -->
175-
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
176-
<xsl:with-param name="sType" select="'msa'"/>
170+
<xsl:call-template name="ProcessMorphItem">
177171
<xsl:with-param name="sLang" select="$sLang"/>
178-
<xsl:with-param name="bAddHyphen" select="'Y'"/>
179172
</xsl:call-template>
180173
</xsl:when>
181174
</xsl:choose>
@@ -201,6 +194,31 @@ Elements to ignore or are handled elsewhere
201194
</xsl:choose>
202195
</xsl:for-each>
203196
</xsl:template>
197+
<xsl:template name="ProcessMorphItem">
198+
<xsl:param name="sLang"/>
199+
<!-- morphemes -->
200+
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
201+
<xsl:with-param name="sType" select="'txt'"/>
202+
<xsl:with-param name="sLang" select="$sLang"/>
203+
</xsl:call-template>
204+
<!-- Lex Entries -->
205+
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
206+
<xsl:with-param name="sType" select="'cf'"/>
207+
<xsl:with-param name="sLang" select="$sLang"/>
208+
</xsl:call-template>
209+
<!-- Gloss -->
210+
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
211+
<xsl:with-param name="sType" select="'gls'"/>
212+
<xsl:with-param name="sLang" select="$sLang"/>
213+
<xsl:with-param name="bAddHyphen" select="'Y'"/>
214+
</xsl:call-template>
215+
<!-- msa -->
216+
<xsl:call-template name="OutputLineOfWrdElementsFromMorphs">
217+
<xsl:with-param name="sType" select="'msa'"/>
218+
<xsl:with-param name="sLang" select="$sLang"/>
219+
<xsl:with-param name="bAddHyphen" select="'Y'"/>
220+
</xsl:call-template>
221+
</xsl:template>
204222
<!--
205223
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206224
OutputLineOfWrdElementsFromMorphs
@@ -221,8 +239,29 @@ OutputLineOfWrdElementsFromMorphs
221239
<xsl:when test="morphemes[morph/item[@type=$sType and @lang=$sLang]]">
222240
<xsl:for-each select="morphemes[morph/item[@type=$sType and @lang=$sLang]]">
223241
<wrd>
242+
<xsl:variable name="vernacularLanguageMissingInPhase1">
243+
<xsl:variable name="sBeforeLastHyphenId">
244+
<xsl:call-template name="GetPortionBeforeLastHyphen">
245+
<xsl:with-param name="pText" select="$sLang"/>
246+
</xsl:call-template>
247+
</xsl:variable>
248+
<xsl:variable name="sBeforeFirstHyphenId">
249+
<xsl:value-of select="substring-before($sLang,'-')"/>
250+
</xsl:variable>
251+
<xsl:choose>
252+
<xsl:when test="//language[@lang=$sBeforeFirstHyphenId]/@vernacular='true'">
253+
<xsl:text>Y</xsl:text>
254+
</xsl:when>
255+
<xsl:when test="//language[@lang=$sBeforeLastHyphenId]/@vernacular='true'">
256+
<xsl:text>Y</xsl:text>
257+
</xsl:when>
258+
<xsl:otherwise>
259+
<xsl:text>N</xsl:text>
260+
</xsl:otherwise>
261+
</xsl:choose>
262+
</xsl:variable>
224263
<xsl:choose>
225-
<xsl:when test="key('Language',morph/item[@type=$sType and @lang=$sLang]/@lang)/@vernacular='true'">
264+
<xsl:when test="key('Language',morph/item[@type=$sType and @lang=$sLang]/@lang)/@vernacular='true' or $vernacularLanguageMissingInPhase1='Y'">
226265
<langData>
227266
<xsl:for-each select="morph/item[@type=$sType and @lang=$sLang]">
228267
<xsl:call-template name="GetMorphLangAttribute"/>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapConcatMorphemes.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<xsl:value-of select="item[@type='title-abbreviation']"/>
6666
</shortTitle>
6767
</textInfo>
68-
<xsl:apply-templates/>
68+
<xsl:apply-templates select="."/>
6969
</interlinear-text>
7070
</xsl:for-each>
7171
</appendix>
@@ -87,6 +87,7 @@
8787
-->
8888
<xsl:template match="phrase">
8989
<xsl:param name="sScriptureType"/>
90+
<xsl:param name="sThisTextId"/>
9091
<xsl:variable name="sLevel">
9192
<xsl:call-template name="OutputLevelContent">
9293
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapExamples.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ phrase
9494
-->
9595
<xsl:template match="phrase">
9696
<xsl:param name="sScriptureType"/>
97+
<xsl:param name="sThisTextId"/>
9798
<xsl:variable name="sLevel">
9899
<xsl:call-template name="OutputLevelContent">
99100
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapExamplesConcatMorphemes.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ phrase
7171
-->
7272
<xsl:template match="phrase">
7373
<xsl:param name="sScriptureType"/>
74+
<xsl:param name="sThisTextId"/>
7475
<xsl:variable name="sLevel">
7576
<xsl:call-template name="OutputLevelContent">
7677
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>

DistFiles/Language Explorer/Export Templates/Interlinear/xml2XLingPapListExamplesConcatMorphemes.xsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ paragraph[1]
7171
-->
7272
<xsl:template match="paragraphs" priority="100">
7373
<xsl:param name="sScriptureType"/>
74+
<xsl:param name="sThisTextId"/>
7475
<xsl:variable name="iCount" select="count(../preceding-sibling::interlinear-text)+1"/>
7576
<p>
7677
<xsl:text>paragraph </xsl:text>
7778
<xsl:value-of select="$iCount"/>
7879
</p>
79-
<example num="x{$iCount}">
80+
<example num="x{$sThisTextId}-{$iCount}">
8081
<xsl:apply-templates select="descendant::phrase">
8182
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>
83+
<xsl:with-param name="sThisTextId" select="$sThisTextId"/>
8284
</xsl:apply-templates>
8385
</example>
8486
</xsl:template>
@@ -89,6 +91,7 @@ phrase
8991
-->
9092
<xsl:template match="phrase">
9193
<xsl:param name="sScriptureType"/>
94+
<xsl:param name="sThisTextId"/>
9295
<xsl:variable name="sLevel">
9396
<xsl:call-template name="OutputLevelContent">
9497
<xsl:with-param name="sScriptureType" select="$sScriptureType"/>

Src/LexText/Interlinear/ITextDllTests/ITextDllTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
</Compile>
323323
<Compile Include="TextsTriStateTreeViewTests.cs" />
324324
<Compile Include="WordBreakGuesserTests.cs" />
325+
<Compile Include="XLingPaperExporterTests.cs" />
325326
</ItemGroup>
326327
<ItemGroup>
327328
<None Include="FlexTextImport\FlexTextExportOutput.flextext" />

0 commit comments

Comments
 (0)