From b1e9732c9cf68918b34151a9a6b312d513918d5b Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Sun, 4 May 2025 14:30:42 -0400 Subject: [PATCH 1/2] Add ability to add remarks --- .../Corpora/ParatextProjectTextUpdaterBase.cs | 6 ++++-- .../Corpora/UpdateUsfmParserHandler.cs | 21 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs b/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs index 5e0d9dfd..08334644 100644 --- a/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs +++ b/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs @@ -27,7 +27,8 @@ public string UpdateUsfm( UpdateUsfmMarkerBehavior paragraphBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior embedBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior styleBehavior = UpdateUsfmMarkerBehavior.Strip, - IReadOnlyCollection preserveParagraphStyles = null + IReadOnlyCollection preserveParagraphStyles = null, + IReadOnlyList remarks = null ) { string fileName = _settings.GetBookFileName(bookId); @@ -47,7 +48,8 @@ public string UpdateUsfm( paragraphBehavior, embedBehavior, styleBehavior, - preserveParagraphStyles + preserveParagraphStyles, + remarks ); try { diff --git a/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs b/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs index 4ce564a0..3caea660 100644 --- a/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs +++ b/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs @@ -33,6 +33,7 @@ public class UpdateUsfmParserHandler : ScriptureRefUsfmParserHandlerBase private readonly UpdateUsfmMarkerBehavior _embedBehavior; private readonly UpdateUsfmMarkerBehavior _styleBehavior; private readonly HashSet _preserveParagraphStyles; + private readonly List _remarks; private readonly Stack _replace; private int _rowIndex; private int _tokenIndex; @@ -47,7 +48,8 @@ public UpdateUsfmParserHandler( UpdateUsfmMarkerBehavior paragraphBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior embedBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior styleBehavior = UpdateUsfmMarkerBehavior.Strip, - IReadOnlyCollection preserveParagraphStyles = null + IReadOnlyCollection preserveParagraphStyles = null, + IReadOnlyCollection remarks = null ) { _rows = rows ?? Array.Empty<(IReadOnlyList, string)>(); @@ -60,10 +62,11 @@ public UpdateUsfmParserHandler( _paragraphBehavior = paragraphBehavior; _embedBehavior = embedBehavior; _styleBehavior = styleBehavior; - if (preserveParagraphStyles == null) - _preserveParagraphStyles = new HashSet { "r", "rem" }; - else - _preserveParagraphStyles = new HashSet(preserveParagraphStyles); + _preserveParagraphStyles = + preserveParagraphStyles == null + ? new HashSet { "r", "rem" } + : new HashSet(preserveParagraphStyles); + _remarks = remarks == null ? new List() : remarks.ToList(); _embedUpdated = false; _embedRowTexts = new List(); } @@ -82,6 +85,14 @@ public override void StartBook(UsfmParserState state, string marker, string code var startBookTokens = new List(); if (_idText != null) startBookTokens.Add(new UsfmToken(_idText + " ")); + if (_remarks.Count > 0) + { + foreach (string remark in _remarks) + { + startBookTokens.Add(new UsfmToken(UsfmTokenType.Paragraph, "rem", null, null)); + startBookTokens.Add(new UsfmToken(remark)); + } + } PushNewTokens(startBookTokens); base.StartBook(state, marker, code); From 3d1ca71d963ba559663585d7648ea5853f7fef41 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Wed, 7 May 2025 10:13:12 -0400 Subject: [PATCH 2/2] Use IEnumerable --- src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs | 2 +- src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs b/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs index 08334644..06faf34a 100644 --- a/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs +++ b/src/SIL.Machine/Corpora/ParatextProjectTextUpdaterBase.cs @@ -28,7 +28,7 @@ public string UpdateUsfm( UpdateUsfmMarkerBehavior embedBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior styleBehavior = UpdateUsfmMarkerBehavior.Strip, IReadOnlyCollection preserveParagraphStyles = null, - IReadOnlyList remarks = null + IEnumerable remarks = null ) { string fileName = _settings.GetBookFileName(bookId); diff --git a/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs b/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs index 3caea660..532a89f0 100644 --- a/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs +++ b/src/SIL.Machine/Corpora/UpdateUsfmParserHandler.cs @@ -49,7 +49,7 @@ public UpdateUsfmParserHandler( UpdateUsfmMarkerBehavior embedBehavior = UpdateUsfmMarkerBehavior.Preserve, UpdateUsfmMarkerBehavior styleBehavior = UpdateUsfmMarkerBehavior.Strip, IReadOnlyCollection preserveParagraphStyles = null, - IReadOnlyCollection remarks = null + IEnumerable remarks = null ) { _rows = rows ?? Array.Empty<(IReadOnlyList, string)>(); @@ -85,7 +85,7 @@ public override void StartBook(UsfmParserState state, string marker, string code var startBookTokens = new List(); if (_idText != null) startBookTokens.Add(new UsfmToken(_idText + " ")); - if (_remarks.Count > 0) + if (_remarks.Count() > 0) { foreach (string remark in _remarks) {