Skip to content

Commit 3e15d8f

Browse files
authored
Improve Quotation Denormalization Remark (#848)
* Specify chapters by chapter number not index; combine chapters into ranges; add special remarks for the none and all cases * Update machine version to 3.7.11
1 parent f5919f2 commit 3e15d8f

File tree

5 files changed

+82
-15
lines changed

5 files changed

+82
-15
lines changed

src/Machine/src/Serval.Machine.Shared/Serval.Machine.Shared.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
<PackageReference Include="Hangfire.Mongo" Version="1.11.6" />
3939
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
4040
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
41-
<PackageReference Include="SIL.Machine" Version="3.7.10" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
42-
<PackageReference Include="SIL.Machine.Morphology.HermitCrab" Version="3.7.10" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine.Morphology.HermitCrab\SIL.Machine.Morphology.HermitCrab.csproj')" />
43-
<PackageReference Include="SIL.Machine.Translation.Thot" Version="3.7.10" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine.Translation.Thot\SIL.Machine.Translation.Thot.csproj')" />
41+
<PackageReference Include="SIL.Machine" Version="3.7.11" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
42+
<PackageReference Include="SIL.Machine.Morphology.HermitCrab" Version="3.7.11" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine.Morphology.HermitCrab\SIL.Machine.Morphology.HermitCrab.csproj')" />
43+
<PackageReference Include="SIL.Machine.Translation.Thot" Version="3.7.11" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine.Translation.Thot\SIL.Machine.Translation.Thot.csproj')" />
4444
<PackageReference Include="SIL.WritingSystems" Version="14.1.1" />
4545
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
4646
<PackageReference Include="YamlDotNet" Version="11.2.1" />

src/Serval/src/Serval.Shared/Serval.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Grpc.Core.Api" Version="2.65.0" />
2020
<PackageReference Include="Grpc.HealthCheck" Version="2.65.0" />
2121
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.65.0" />
22-
<PackageReference Include="SIL.Machine" Version="3.7.10" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
22+
<PackageReference Include="SIL.Machine" Version="3.7.11" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
2323
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.5.0" />
2424
</ItemGroup>
2525

src/Serval/src/Serval.Translation/Services/PretranslationService.cs

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,44 @@ private static string DenormalizeQuotationMarks(string usfm, ParallelCorpusAnaly
320320
QuotationMarkDenormalizationFirstPass quotationMarkDenormalizationFirstPass = new(targetQuoteConvention);
321321

322322
UsfmParser.Parse(usfm, quotationMarkDenormalizationFirstPass);
323-
List<QuotationMarkUpdateStrategy> bestChapterStrategies =
323+
List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)> bestChapterStrategies =
324324
quotationMarkDenormalizationFirstPass.FindBestChapterStrategies();
325325

326326
QuotationMarkDenormalizationUsfmUpdateBlockHandler quotationMarkDenormalizer =
327-
new(targetQuoteConvention, new QuotationMarkUpdateSettings(chapterStrategies: bestChapterStrategies));
327+
new(
328+
targetQuoteConvention,
329+
new QuotationMarkUpdateSettings(
330+
chapterStrategies: bestChapterStrategies.Select(tuple => tuple.Strategy).ToList()
331+
)
332+
);
333+
int denormalizableChapterCount = bestChapterStrategies.Count(tup =>
334+
tup.Strategy != QuotationMarkUpdateStrategy.Skip
335+
);
328336
List<string> remarks = [];
329-
if (bestChapterStrategies.Any(s => s != QuotationMarkUpdateStrategy.Skip))
337+
string quotationDenormalizationRemark;
338+
if (denormalizableChapterCount == bestChapterStrategies.Count)
330339
{
331-
string quotationDenormalizationRemark =
340+
quotationDenormalizationRemark =
341+
"The quote style in all chapters has been automatically adjusted to match the rest of the project.";
342+
}
343+
else if (denormalizableChapterCount > 0)
344+
{
345+
quotationDenormalizationRemark =
332346
"The quote style in the following chapters has been automatically adjusted to match the rest of the project: "
333-
+ string.Join(
334-
", ",
347+
+ GetChapterRangesString(
335348
bestChapterStrategies
336-
.Select((strategy, index) => (strategy, index))
337-
.Where(tuple => tuple.strategy != QuotationMarkUpdateStrategy.Skip)
338-
.Select(tuple => tuple.index + 1)
349+
.Where(tuple => tuple.Strategy != QuotationMarkUpdateStrategy.Skip)
350+
.Select(tuple => tuple.ChapterNumber)
351+
.ToList()
339352
)
340353
+ ".";
341-
remarks.Add(quotationDenormalizationRemark);
342354
}
355+
else
356+
{
357+
quotationDenormalizationRemark =
358+
"The quote style was not automatically adjusted to match the rest of your project in any chapters.";
359+
}
360+
remarks.Add(quotationDenormalizationRemark);
343361

344362
var updater = new UpdateUsfmParserHandler(updateBlockHandlers: [quotationMarkDenormalizer], remarks: remarks);
345363
UsfmParser.Parse(usfm, updater);
@@ -348,6 +366,43 @@ private static string DenormalizeQuotationMarks(string usfm, ParallelCorpusAnaly
348366
return usfm;
349367
}
350368

369+
public static string GetChapterRangesString(List<int> chapterNumbers)
370+
{
371+
chapterNumbers = chapterNumbers.Order().ToList();
372+
int start = chapterNumbers[0];
373+
int end = chapterNumbers[0];
374+
List<string> chapterRangeStrings = [];
375+
foreach (int chapterNumber in chapterNumbers[1..])
376+
{
377+
if (chapterNumber == end + 1)
378+
{
379+
end = chapterNumber;
380+
}
381+
else
382+
{
383+
if (start == end)
384+
{
385+
chapterRangeStrings.Add(start.ToString(CultureInfo.InvariantCulture));
386+
}
387+
else
388+
{
389+
chapterRangeStrings.Add($"{start}-{end}");
390+
}
391+
start = chapterNumber;
392+
end = chapterNumber;
393+
}
394+
}
395+
if (start == end)
396+
{
397+
chapterRangeStrings.Add(start.ToString(CultureInfo.InvariantCulture));
398+
}
399+
else
400+
{
401+
chapterRangeStrings.Add($"{start}-{end}");
402+
}
403+
return string.Join(", ", chapterRangeStrings);
404+
}
405+
351406
/// <summary>
352407
/// Generate a natural sounding remark/comment describing marker placement.
353408
/// </summary>

src/Serval/test/Serval.Translation.Tests/Services/PretranslationServiceTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ public void GetUsfmAsync_BadPretranslationVerseRef()
425425
});
426426
}
427427

428+
[Test]
429+
[TestCase(new int[] { 1, 2, 3 }, "1-3")]
430+
[TestCase(new int[] { 1, 3, 4 }, "1, 3-4")]
431+
[TestCase(new int[] { 2, 3, 4, 6, 8, 9 }, "2-4, 6, 8-9")]
432+
[TestCase(new int[] { 1, 3, 2 }, "1-3")]
433+
[TestCase(new int[] { 1 }, "1")]
434+
public void GetChapterRanges(int[] chapterNumbers, string expectedRangeString)
435+
{
436+
string actualRangeString = PretranslationService.GetChapterRangesString(chapterNumbers.ToList());
437+
Assert.That(actualRangeString, Is.EqualTo(expectedRangeString));
438+
}
439+
428440
private class TestEnvironment : IDisposable
429441
{
430442
public TestEnvironment()

src/ServiceToolkit/src/SIL.ServiceToolkit/SIL.ServiceToolkit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PackageReference Include="SIL.WritingSystems" Version="14.1.1" />
1919
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
2020
<PackageReference Include="SIL.Scripture" Version="12.0.1" />
21-
<PackageReference Include="SIL.Machine" Version="3.7.10" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
21+
<PackageReference Include="SIL.Machine" Version="3.7.11" Condition="!Exists('..\..\..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

0 commit comments

Comments
 (0)