From 7828e26d0b338803b343cdd747dd3b5436ebb58c Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 17 Apr 2024 11:55:10 -0400 Subject: [PATCH] Fixes missed from previous PR (#367) * Fixes missed from previous PR * Reviewer comments and failing tests --- src/Serval.Shared/Serval.Shared.csproj | 2 +- .../Services/PretranslationService.cs | 21 +++++++++++++------ src/Serval.Translation/Usings.cs | 1 - .../Services/PlatformServiceTests.cs | 14 +++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Serval.Shared/Serval.Shared.csproj b/src/Serval.Shared/Serval.Shared.csproj index 2294a529..c653e763 100644 --- a/src/Serval.Shared/Serval.Shared.csproj +++ b/src/Serval.Shared/Serval.Shared.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Serval.Translation/Services/PretranslationService.cs b/src/Serval.Translation/Services/PretranslationService.cs index 0c81b1a9..f264f2c9 100644 --- a/src/Serval.Translation/Services/PretranslationService.cs +++ b/src/Serval.Translation/Services/PretranslationService.cs @@ -60,7 +60,7 @@ await GetAllAsync(engineId, modelRevision, corpusId, textId, cancellationToken) .Select(p => ( (IReadOnlyList) - p.Refs.Select(r => new ScriptureRef(new VerseRef(r, targetSettings.Versification))).ToList(), + p.Refs.Select(r => ScriptureRef.Parse(r, targetSettings.Versification)).ToList(), p.Translation ) ) @@ -70,12 +70,21 @@ await GetAllAsync(engineId, modelRevision, corpusId, textId, cancellationToken) // Update the target book if it exists string? usfm = await _scriptureDataFileService.ReadParatextProjectBookAsync(targetFile.Filename, textId); if (usfm is not null) - return UpdateUsfm(targetSettings, usfm, pretranslations); + return UpdateUsfm(targetSettings, usfm, pretranslations, strictComparison: false); // Copy and update the source book if it exists usfm = await _scriptureDataFileService.ReadParatextProjectBookAsync(sourceFile.Filename, textId); if (usfm is not null) - return UpdateUsfm(sourceSettings, usfm, pretranslations, targetSettings.FullName, stripAllText: true); + { + return UpdateUsfm( + sourceSettings, + usfm, + pretranslations, + targetSettings.FullName, + stripAllText: true, + strictComparison: true + ); + } return ""; } @@ -85,15 +94,15 @@ private static string UpdateUsfm( string usfm, IReadOnlyList<(IReadOnlyList, string)> pretranslations, string? fullName = null, - bool stripAllText = false + bool stripAllText = false, + bool strictComparison = false ) { - // TODO: Update to most recent SIL.Machine version var updater = new UsfmTextUpdater( pretranslations, fullName is null ? null : $"- {fullName}", stripAllText, - strictComparison: false + strictComparison: strictComparison ); UsfmParser.Parse(usfm, updater, settings.Stylesheet, settings.Versification); return updater.GetUsfm(settings.Stylesheet); diff --git a/src/Serval.Translation/Usings.cs b/src/Serval.Translation/Usings.cs index 1fda2ed5..77bb4439 100644 --- a/src/Serval.Translation/Usings.cs +++ b/src/Serval.Translation/Usings.cs @@ -27,4 +27,3 @@ global using Serval.Translation.Models; global using Serval.Translation.Services; global using SIL.DataAccess; -global using SIL.Scripture; diff --git a/tests/Serval.Translation.Tests/Services/PlatformServiceTests.cs b/tests/Serval.Translation.Tests/Services/PlatformServiceTests.cs index 6e8161d1..cfa294a4 100644 --- a/tests/Serval.Translation.Tests/Services/PlatformServiceTests.cs +++ b/tests/Serval.Translation.Tests/Services/PlatformServiceTests.cs @@ -123,6 +123,20 @@ public TestEnvironment() DataAccessContext = Substitute.For(); PublishEndpoint = Substitute.For(); ServerCallContext = Substitute.For(); + + DataAccessContext + .WithTransactionAsync(Arg.Any>(), Arg.Any()) + .Returns(x => + { + return ((Func)x[0])((CancellationToken)x[1]); + }); + DataAccessContext + .WithTransactionAsync(Arg.Any>>(), Arg.Any()) + .Returns(x => + { + return ((Func)x[0])((CancellationToken)x[1]); + }); + PlatformService = new TranslationPlatformServiceV1( Builds, Engines,