Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/SIL.Machine/PunctuationAnalysis/Chapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace SIL.Machine.PunctuationAnalysis
{
public class Chapter
{
public Chapter(IEnumerable<Verse> verses)
public Chapter(IEnumerable<Verse> verses, int chapterNumber = 0)
{
Verses = verses.ToList();
ChapterNumber = chapterNumber;
}

public List<Verse> Verses { get; set; }
public List<Verse> Verses { get; private set; }
public int ChapterNumber { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ int depth in Enumerable.Range(1, Math.Min(oldQuoteConvention.NumLevels, newQuote
return true;
}

public List<QuotationMarkUpdateStrategy> FindBestChapterStrategies()
public List<(int ChapterNumber, QuotationMarkUpdateStrategy Strategy)> FindBestChapterStrategies()
{
var bestActionsByChapter = new List<QuotationMarkUpdateStrategy>();
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Machine/PunctuationAnalysis/TextSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int>();
_stringIndexBySurrogatePairIndex = new Dictionary<int, int>();
foreach ((int stringIndex, int surrogatePairIndex) in indexPairs)
Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Machine/PunctuationAnalysis/UsfmStructureExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public List<Chapter> GetChapters(IReadOnlyDictionary<int, List<int>> includeChap
{
if (currentChapterVerses.Count > 0)
{
chapters.Add(new Chapter(currentChapterVerses));
chapters.Add(new Chapter(currentChapterVerses, currentChapter));
}
currentChapterVerses = new List<Verse>();
}
Expand All @@ -176,7 +176,7 @@ public List<Chapter> GetChapters(IReadOnlyDictionary<int, List<int>> includeChap
}
if (currentChapterVerses.Count > 0)
{
chapters.Add(new Chapter(currentChapterVerses));
chapters.Add(new Chapter(currentChapterVerses, currentChapter));
}
return chapters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ of the field which Yahweh God had made.
);

UsfmParser.Parse(normalizedUsfm, quotationMarkDenormalizationFirstPass);
List<QuotationMarkUpdateStrategy> 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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ You shall not eat of any tree of the garden ? ""
Assert.That(expectedActions.SequenceEqual(observedActions));
}

public List<QuotationMarkUpdateStrategy> RunFirstPass(
private static List<QuotationMarkUpdateStrategy> RunFirstPass(
string normalizedUsfm,
string sourceQuoteConventionName,
string targetQuoteConventionName
Expand All @@ -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<string> verseTexts,
string sourceQuoteConventionName,
string targetQuoteConventionName
Expand All @@ -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);
Expand Down
Loading