From 16de57a3c6e9972acf069d9d12e36ca9999218f6 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Wed, 17 Dec 2025 10:19:30 -0500 Subject: [PATCH 1/2] Expose the Chapter's chapter number when returning the chapter QD strategies --- src/SIL.Machine/PunctuationAnalysis/Chapter.cs | 6 ++++-- .../PunctuationAnalysis/QuotationMarkUpdateFirstPass.cs | 6 +++--- .../PunctuationAnalysis/UsfmStructureExtractor.cs | 4 ++-- .../PunctuationAnalysis/QuotationDenormalizationTests.cs | 8 ++++++-- .../QuotationMarkUpdateFirstPassTests.cs | 8 ++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/SIL.Machine/PunctuationAnalysis/Chapter.cs b/src/SIL.Machine/PunctuationAnalysis/Chapter.cs index a5c5bc62..c5d4d5f9 100644 --- a/src/SIL.Machine/PunctuationAnalysis/Chapter.cs +++ b/src/SIL.Machine/PunctuationAnalysis/Chapter.cs @@ -5,11 +5,13 @@ namespace SIL.Machine.PunctuationAnalysis { public class Chapter { - public Chapter(IEnumerable verses) + public Chapter(IEnumerable verses, int chapterNumber = 0) { Verses = verses.ToList(); + ChapterNumber = chapterNumber; } - public List Verses { get; set; } + public List Verses { get; private set; } + public int ChapterNumber { get; private set; } } } diff --git a/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateFirstPass.cs b/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateFirstPass.cs index 866fafc9..a4ff1565 100644 --- a/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateFirstPass.cs +++ b/src/SIL.Machine/PunctuationAnalysis/QuotationMarkUpdateFirstPass.cs @@ -46,12 +46,12 @@ int depth in Enumerable.Range(1, Math.Min(oldQuoteConvention.NumLevels, newQuote return true; } - public List FindBestChapterStrategies() + public List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)> FindBestChapterStrategies() { - var bestActionsByChapter = new List(); + var bestActionsByChapter = new List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)>(); foreach (Chapter chapter in GetChapters()) { - bestActionsByChapter.Add(FindBestStrategyForChapter(chapter)); + bestActionsByChapter.Add((chapter.ChapterNumber, FindBestStrategyForChapter(chapter))); } return bestActionsByChapter; } diff --git a/src/SIL.Machine/PunctuationAnalysis/UsfmStructureExtractor.cs b/src/SIL.Machine/PunctuationAnalysis/UsfmStructureExtractor.cs index cf8cf27f..685c5d58 100644 --- a/src/SIL.Machine/PunctuationAnalysis/UsfmStructureExtractor.cs +++ b/src/SIL.Machine/PunctuationAnalysis/UsfmStructureExtractor.cs @@ -164,7 +164,7 @@ public List GetChapters(IReadOnlyDictionary> includeChap { if (currentChapterVerses.Count > 0) { - chapters.Add(new Chapter(currentChapterVerses)); + chapters.Add(new Chapter(currentChapterVerses, currentChapter)); } currentChapterVerses = new List(); } @@ -176,7 +176,7 @@ public List GetChapters(IReadOnlyDictionary> includeChap } if (currentChapterVerses.Count > 0) { - chapters.Add(new Chapter(currentChapterVerses)); + chapters.Add(new Chapter(currentChapterVerses, currentChapter)); } return chapters; } diff --git a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs index 117e2ac7..0d258456 100644 --- a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs +++ b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs @@ -41,12 +41,16 @@ of the field which Yahweh God had made. ); UsfmParser.Parse(normalizedUsfm, quotationMarkDenormalizationFirstPass); - List bestChapterStrategies = + List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)> bestChapterStrategies = quotationMarkDenormalizationFirstPass.FindBestChapterStrategies(); + Assert.That(bestChapterStrategies.Select(tup => tup.ChapterNumber).SequenceEqual([1])); + var quotationMarkDenormalizer = new QuotationMarkDenormalizationUsfmUpdateBlockHandler( standardEnglishQuoteConvention, - new QuotationMarkUpdateSettings(chapterStrategies: bestChapterStrategies) + new QuotationMarkUpdateSettings( + chapterStrategies: bestChapterStrategies.Select(tup => tup.Strategy).ToList() + ) ); var updater = new UpdateUsfmParserHandler(updateBlockHandlers: [quotationMarkDenormalizer]); diff --git a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs index df37f803..ccdc816f 100644 --- a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs +++ b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs @@ -730,7 +730,7 @@ You shall not eat of any tree of the garden ? "" Assert.That(expectedActions.SequenceEqual(observedActions)); } - public List RunFirstPass( + private static List RunFirstPass( string normalizedUsfm, string sourceQuoteConventionName, string targetQuoteConventionName @@ -749,10 +749,10 @@ string targetQuoteConventionName var firstPassAnalyzer = new QuotationMarkUpdateFirstPass(sourceQuoteConvention, targetQuoteConvention); UsfmParser.Parse(normalizedUsfm, firstPassAnalyzer); - return firstPassAnalyzer.FindBestChapterStrategies(); + return firstPassAnalyzer.FindBestChapterStrategies().Select(tup => tup.Strategy).ToList(); } - public QuotationMarkUpdateStrategy RunFirstPassOnChapter( + private static QuotationMarkUpdateStrategy RunFirstPassOnChapter( List verseTexts, string sourceQuoteConventionName, string targetQuoteConventionName @@ -777,7 +777,7 @@ string targetQuoteConventionName return firstPassAnalyzer.FindBestStrategyForChapter(chapter); } - public QuoteConvention GetQuoteConventionByName(string name) + private static QuoteConvention GetQuoteConventionByName(string name) { QuoteConvention quoteConvention = QuoteConventions.Standard.GetQuoteConventionByName(name); Assert.IsNotNull(quoteConvention); From 1a029403352abfa4293ee3f655208fbb35cae79a Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Wed, 17 Dec 2025 10:26:24 -0500 Subject: [PATCH 2/2] Consistent tuple variable naming --- src/SIL.Machine/PunctuationAnalysis/TextSegment.cs | 4 ++-- .../PunctuationAnalysis/QuotationDenormalizationTests.cs | 4 ++-- .../PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SIL.Machine/PunctuationAnalysis/TextSegment.cs b/src/SIL.Machine/PunctuationAnalysis/TextSegment.cs index 229aec56..ccad7e91 100644 --- a/src/SIL.Machine/PunctuationAnalysis/TextSegment.cs +++ b/src/SIL.Machine/PunctuationAnalysis/TextSegment.cs @@ -189,8 +189,8 @@ public SurrogatePairString(string stringValue) _stringValue = stringValue; IEnumerable<(int StringIndex, int SurrogatePairIndex)> indexPairs = _stringValue .Select((c, stringIndex) => (c, stringIndex)) - .Where(tup => !char.IsLowSurrogate(tup.c)) - .Select((tup, surrogatePairIndex) => (tup.stringIndex, surrogatePairIndex)); + .Where(tuple => !char.IsLowSurrogate(tuple.c)) + .Select((tuple, surrogatePairIndex) => (tuple.stringIndex, surrogatePairIndex)); _surrogatePairIndexByStringIndex = new Dictionary(); _stringIndexBySurrogatePairIndex = new Dictionary(); foreach ((int stringIndex, int surrogatePairIndex) in indexPairs) diff --git a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs index 0d258456..58c5c5d6 100644 --- a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs +++ b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationDenormalizationTests.cs @@ -44,12 +44,12 @@ of the field which Yahweh God had made. List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)> bestChapterStrategies = quotationMarkDenormalizationFirstPass.FindBestChapterStrategies(); - Assert.That(bestChapterStrategies.Select(tup => tup.ChapterNumber).SequenceEqual([1])); + Assert.That(bestChapterStrategies.Select(tuple => tuple.ChapterNumber).SequenceEqual([1])); var quotationMarkDenormalizer = new QuotationMarkDenormalizationUsfmUpdateBlockHandler( standardEnglishQuoteConvention, new QuotationMarkUpdateSettings( - chapterStrategies: bestChapterStrategies.Select(tup => tup.Strategy).ToList() + chapterStrategies: bestChapterStrategies.Select(tuple => tuple.Strategy).ToList() ) ); diff --git a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs index ccdc816f..aabce3b3 100644 --- a/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs +++ b/tests/SIL.Machine.Tests/PunctuationAnalysis/QuotationMarkUpdateFirstPassTests.cs @@ -749,7 +749,7 @@ string targetQuoteConventionName var firstPassAnalyzer = new QuotationMarkUpdateFirstPass(sourceQuoteConvention, targetQuoteConvention); UsfmParser.Parse(normalizedUsfm, firstPassAnalyzer); - return firstPassAnalyzer.FindBestChapterStrategies().Select(tup => tup.Strategy).ToList(); + return firstPassAnalyzer.FindBestChapterStrategies().Select(tuple => tuple.Strategy).ToList(); } private static QuotationMarkUpdateStrategy RunFirstPassOnChapter(