Skip to content

Commit

Permalink
Fixes missed from previous PR (#367)
Browse files Browse the repository at this point in the history
* Fixes missed from previous PR

* Reviewer comments and failing tests
  • Loading branch information
johnml1135 authored Apr 17, 2024
1 parent df8d4a6 commit 7828e26
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Serval.Shared/Serval.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Grpc.Core.Api" Version="2.52.0" />
<PackageReference Include="Grpc.HealthCheck" Version="2.52.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.52.0" />
<PackageReference Include="SIL.Machine" Version="3.0.2" Condition="!Exists('..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
<PackageReference Include="SIL.Machine" Version="3.1.0" Condition="!Exists('..\..\..\machine\src\SIL.Machine\SIL.Machine.csproj')" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 15 additions & 6 deletions src/Serval.Translation/Services/PretranslationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ await GetAllAsync(engineId, modelRevision, corpusId, textId, cancellationToken)
.Select(p =>
(
(IReadOnlyList<ScriptureRef>)
p.Refs.Select(r => new ScriptureRef(new VerseRef(r, targetSettings.Versification))).ToList(),
p.Refs.Select(r => ScriptureRef.Parse(r, targetSettings.Versification)).ToList(),
p.Translation
)
)
Expand All @@ -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 "";
}
Expand All @@ -85,15 +94,15 @@ private static string UpdateUsfm(
string usfm,
IReadOnlyList<(IReadOnlyList<ScriptureRef>, 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);
Expand Down
1 change: 0 additions & 1 deletion src/Serval.Translation/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
global using Serval.Translation.Models;
global using Serval.Translation.Services;
global using SIL.DataAccess;
global using SIL.Scripture;
14 changes: 14 additions & 0 deletions tests/Serval.Translation.Tests/Services/PlatformServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ public TestEnvironment()
DataAccessContext = Substitute.For<IDataAccessContext>();
PublishEndpoint = Substitute.For<IPublishEndpoint>();
ServerCallContext = Substitute.For<ServerCallContext>();

DataAccessContext
.WithTransactionAsync(Arg.Any<Func<CancellationToken, Task>>(), Arg.Any<CancellationToken>())
.Returns(x =>
{
return ((Func<CancellationToken, Task>)x[0])((CancellationToken)x[1]);
});
DataAccessContext
.WithTransactionAsync(Arg.Any<Func<CancellationToken, Task<bool>>>(), Arg.Any<CancellationToken>())
.Returns(x =>
{
return ((Func<CancellationToken, Task>)x[0])((CancellationToken)x[1]);
});

PlatformService = new TranslationPlatformServiceV1(
Builds,
Engines,
Expand Down

0 comments on commit 7828e26

Please sign in to comment.