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/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/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..58c5c5d6 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(tuple => tuple.ChapterNumber).SequenceEqual([1])); + var quotationMarkDenormalizer = new QuotationMarkDenormalizationUsfmUpdateBlockHandler( standardEnglishQuoteConvention, - new QuotationMarkUpdateSettings(chapterStrategies: bestChapterStrategies) + new QuotationMarkUpdateSettings( + chapterStrategies: bestChapterStrategies.Select(tuple => tuple.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..aabce3b3 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(tuple => tuple.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);