Skip to content

Commit 9ffcdd1

Browse files
committed
Update Serval.Client to 1.12.1
1 parent 0e9d096 commit 9ffcdd1

File tree

8 files changed

+254
-74
lines changed

8 files changed

+254
-74
lines changed

src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
@@ -40,8 +40,8 @@
4040
<PackageReference Include="ParatextData" Version="9.5.0.19" />
4141
<!-- When updating Serval.Client consider that API changes must be released to Serval Prod
4242
prior to testing on SF QA -->
43-
<PackageReference Include="Serval.Client" Version="1.10.1" />
44-
<PackageReference Include="SIL.Machine" Version="3.7.7" />
43+
<PackageReference Include="Serval.Client" Version="1.12.1" />
44+
<PackageReference Include="SIL.Machine" Version="3.7.9" />
4545
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
4646
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.6" />
4747
</ItemGroup>

src/SIL.XForge.Scripture/Services/MachineProjectService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,15 +1455,17 @@ out SFProjectSecret projectSecret
14551455
.ToArray() ?? [];
14561456
foreach (string corpusId in corpusIds)
14571457
{
1458-
// Delete the corpus
1458+
// Delete the legacy corpus
14591459
try
14601460
{
1461+
#pragma warning disable CS0612 // Type or member is obsolete
14611462
await translationEnginesClient.DeleteCorpusAsync(
14621463
translationEngineId,
14631464
corpusId,
14641465
deleteFiles: true,
14651466
cancellationToken
14661467
);
1468+
#pragma warning restore CS0612 // Type or member is obsolete
14671469
}
14681470
catch (ServalApiException e)
14691471
{

src/SIL.XForge.Scripture/Services/PreTranslationService.cs

Lines changed: 103 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,35 @@ CancellationToken cancellationToken
3535
List<PreTranslation> preTranslations = [];
3636

3737
// Ensure we have the parameters to retrieve the pre-translation
38-
(string? translationEngineId, string corpusId, bool useParatextVerseRef) =
38+
(string? translationEngineId, string? corpusId, string? parallelCorpusId, bool useParatextVerseRef) =
3939
await GetPreTranslationParametersAsync(sfProjectId);
4040

4141
// Get the pre-translation data from Serval
4242
string textId = useParatextVerseRef ? GetTextId(bookNum) : GetTextId(bookNum, chapterNum);
43-
foreach (
44-
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
43+
IList<Pretranslation> servalPreTranslations;
44+
if (parallelCorpusId is not null)
45+
{
46+
servalPreTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
47+
translationEngineId,
48+
parallelCorpusId,
49+
textId,
50+
cancellationToken
51+
);
52+
}
53+
else
54+
{
55+
// Retrieve the pre-translations from a legacy corpus
56+
#pragma warning disable CS0612 // Type or member is obsolete
57+
servalPreTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
4558
translationEngineId,
4659
corpusId,
4760
textId,
4861
cancellationToken
49-
)
50-
)
62+
);
63+
#pragma warning restore CS0612 // Type or member is obsolete
64+
}
65+
66+
foreach (Pretranslation preTranslation in servalPreTranslations)
5167
{
5268
// A reference will be in one of the formats:
5369
// FileFormat.Text: "40_1:verse_001_002"
@@ -185,32 +201,59 @@ CancellationToken cancellationToken
185201
)
186202
{
187203
// Ensure we have the parameters to retrieve the pre-translation
188-
(string? translationEngineId, string corpusId, bool _) = await GetPreTranslationParametersAsync(sfProjectId);
204+
(string? translationEngineId, string? corpusId, string? parallelCorpusId, bool _) =
205+
await GetPreTranslationParametersAsync(sfProjectId);
206+
207+
// Generate the paragraph marker and quote normalization behaviors
208+
PretranslationUsfmMarkerBehavior paragraphMarkerBehavior = config.ParagraphFormat switch
209+
{
210+
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
211+
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
212+
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
213+
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
214+
};
215+
PretranslationNormalizationBehavior quoteNormalizationBehavior = config.QuoteFormat switch
216+
{
217+
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
218+
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
219+
_ => PretranslationNormalizationBehavior.Denormalized,
220+
};
189221

190222
// Get the USFM
191-
string usfm = await translationEnginesClient.GetPretranslatedUsfmAsync(
192-
id: translationEngineId,
193-
corpusId: corpusId,
194-
textId: GetTextId(bookNum),
195-
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
196-
template: PretranslationUsfmTemplate.Source,
197-
paragraphMarkerBehavior: config.ParagraphFormat switch
198-
{
199-
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
200-
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
201-
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
202-
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
203-
},
204-
quoteNormalizationBehavior: config.QuoteFormat switch
205-
{
206-
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
207-
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
208-
_ => PretranslationNormalizationBehavior.Denormalized,
209-
},
210-
embedBehavior: PretranslationUsfmMarkerBehavior.Strip,
211-
styleMarkerBehavior: PretranslationUsfmMarkerBehavior.Strip,
212-
cancellationToken: cancellationToken
213-
);
223+
string usfm;
224+
if (parallelCorpusId is not null)
225+
{
226+
usfm = await translationEnginesClient.GetPretranslatedUsfmAsync(
227+
id: translationEngineId,
228+
parallelCorpusId: parallelCorpusId,
229+
textId: GetTextId(bookNum),
230+
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
231+
template: PretranslationUsfmTemplate.Source,
232+
paragraphMarkerBehavior: paragraphMarkerBehavior,
233+
embedBehavior: PretranslationUsfmMarkerBehavior.Strip,
234+
styleMarkerBehavior: PretranslationUsfmMarkerBehavior.Strip,
235+
quoteNormalizationBehavior: quoteNormalizationBehavior,
236+
cancellationToken: cancellationToken
237+
);
238+
}
239+
else
240+
{
241+
// Retrieve the USFM from a legacy corpus
242+
#pragma warning disable CS0612 // Type or member is obsolete
243+
usfm = await translationEnginesClient.GetCorpusPretranslatedUsfmAsync(
244+
id: translationEngineId,
245+
corpusId: corpusId,
246+
textId: GetTextId(bookNum),
247+
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
248+
template: PretranslationUsfmTemplate.Source,
249+
paragraphMarkerBehavior: paragraphMarkerBehavior,
250+
embedBehavior: PretranslationUsfmMarkerBehavior.Strip,
251+
styleMarkerBehavior: PretranslationUsfmMarkerBehavior.Strip,
252+
quoteNormalizationBehavior: quoteNormalizationBehavior,
253+
cancellationToken: cancellationToken
254+
);
255+
#pragma warning restore CS0612 // Type or member is obsolete
256+
}
214257

215258
// Return the entire book
216259
if (chapterNum == 0)
@@ -243,19 +286,34 @@ public async Task UpdatePreTranslationStatusAsync(string sfProjectId, Cancellati
243286
}
244287

245288
// Ensure we have the parameters to retrieve the pre-translation
246-
(string? translationEngineId, string corpusId, bool useParatextVerseRef) =
289+
(string? translationEngineId, string corpusId, string parallelCorpusId, bool useParatextVerseRef) =
247290
await GetPreTranslationParametersAsync(sfProjectId);
248291

249292
// Get all the pre-translations and update the chapters
250-
Dictionary<int, HashSet<int>> bookChapters = [];
251-
foreach (
252-
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
293+
IList<Pretranslation> preTranslations;
294+
if (parallelCorpusId is not null)
295+
{
296+
preTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
297+
translationEngineId,
298+
parallelCorpusId,
299+
textId: null,
300+
cancellationToken
301+
);
302+
}
303+
else
304+
{
305+
// Retrieve the pre-translations from a legacy corpus
306+
#pragma warning disable CS0612 // Type or member is obsolete
307+
preTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
253308
translationEngineId,
254309
corpusId,
255310
textId: null,
256311
cancellationToken
257-
)
258-
)
312+
);
313+
#pragma warning restore CS0612 // Type or member is obsolete
314+
}
315+
Dictionary<int, HashSet<int>> bookChapters = [];
316+
foreach (Pretranslation preTranslation in preTranslations)
259317
{
260318
// Get the book and chapter number
261319
int bookNum;
@@ -341,7 +399,8 @@ await projectDoc.SubmitJson0OpAsync(op =>
341399
/// <exception cref="DataNotFoundException">The pre-translation engine is not configured, or the project secret cannot be found.</exception>
342400
protected internal virtual async Task<(
343401
string translationEngineId,
344-
string corpusId,
402+
string? corpusId,
403+
string? parallelCorpusId,
345404
bool useParatextVerseRef
346405
)> GetPreTranslationParametersAsync(string sfProjectId)
347406
{
@@ -352,11 +411,12 @@ bool useParatextVerseRef
352411
}
353412

354413
string translationEngineId = projectSecret.ServalData?.PreTranslationEngineId;
355-
string corpusId;
414+
string? corpusId = null;
415+
string? parallelCorpusId = null;
356416
bool useParatextVerseRef = false;
357417
if (!string.IsNullOrWhiteSpace(projectSecret.ServalData?.ParallelCorpusIdForPreTranslate))
358418
{
359-
corpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
419+
parallelCorpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
360420
useParatextVerseRef = true;
361421
}
362422
else
@@ -371,11 +431,14 @@ bool useParatextVerseRef
371431
}
372432
}
373433

374-
if (string.IsNullOrWhiteSpace(translationEngineId) || string.IsNullOrWhiteSpace(corpusId))
434+
if (
435+
string.IsNullOrWhiteSpace(translationEngineId)
436+
|| (string.IsNullOrWhiteSpace(corpusId) && string.IsNullOrWhiteSpace(parallelCorpusId))
437+
)
375438
{
376439
throw new DataNotFoundException("The pre-translation engine is not configured.");
377440
}
378441

379-
return (translationEngineId, corpusId, useParatextVerseRef);
442+
return (translationEngineId, corpusId, parallelCorpusId, useParatextVerseRef);
380443
}
381444
}

src/SIL.XForge.Scripture/packages.lock.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@
107107
},
108108
"Serval.Client": {
109109
"type": "Direct",
110-
"requested": "[1.10.1, )",
111-
"resolved": "1.10.1",
112-
"contentHash": "Fa05THT6PqRKAo+ZpYNf5/endZRBfF/i007+haGfbubxZTJ0NwR+E87+QqcQr7l9zdWTrk5kc4DyjwceJGFFDA==",
110+
"requested": "[1.12.1, )",
111+
"resolved": "1.12.1",
112+
"contentHash": "qRySQeyCJkFGMgotwzQac9HTasYqVGUjpgI1sMG1QyLT7oqEEpNMc0C33UEoXNBrSJJQFBs37AOQZaJxkO3oNA==",
113113
"dependencies": {
114114
"Newtonsoft.Json": "13.0.3",
115115
"System.ComponentModel.Annotations": "5.0.0"
116116
}
117117
},
118118
"SIL.Machine": {
119119
"type": "Direct",
120-
"requested": "[3.7.7, )",
121-
"resolved": "3.7.7",
122-
"contentHash": "ElGEz0nQqiMfHNxy49A05E1trMVvFsy2cCp7qWokEerYkt6jX9O3KXWrrztgupP9M9j+uPhnyI0N9rD7sFS0JQ==",
120+
"requested": "[3.7.9, )",
121+
"resolved": "3.7.9",
122+
"contentHash": "nXfj5MERE/gVWHYpAkUUrtQ58jMeDi+YwzZlWyoLppbL0odTJFsoBkjrhhmD7GZt9MPkxWI8Gv02kmbNhVhrVQ==",
123123
"dependencies": {
124124
"CaseExtensions": "1.1.0",
125125
"Newtonsoft.Json": "13.0.2",

test/SIL.XForge.Scripture.Tests/Services/MachineProjectServiceTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,7 @@ await env
22222222
}
22232223

22242224
[Test]
2225+
[Obsolete("Tests legacy corpora")]
22252226
public async Task RemoveLegacyServalDataAsync_DoesNotCallServalIfNoTranslationEngineId()
22262227
{
22272228
// Set up test environment
@@ -2237,6 +2238,7 @@ await env
22372238
}
22382239

22392240
[Test]
2241+
[Obsolete("Tests legacy corpora")]
22402242
public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs()
22412243
{
22422244
// Set up test environment
@@ -2259,6 +2261,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs(
22592261
}
22602262

22612263
[Test]
2264+
[Obsolete("Tests legacy corpora")]
22622265
public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
22632266
{
22642267
// Set up test environment
@@ -2283,6 +2286,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
22832286
}
22842287

22852288
[Test]
2289+
[Obsolete("Tests legacy corpora")]
22862290
public async Task RemoveLegacyServalDataAsync_OnlyRemovesRelevantCorpora()
22872291
{
22882292
// Set up test environment
@@ -2304,6 +2308,7 @@ await env
23042308
}
23052309

23062310
[Test]
2311+
[Obsolete("Tests legacy corpora")]
23072312
public async Task RemoveLegacyServalDataAsync_RemovesCorporaPropertyIfNoMoreCorpora()
23082313
{
23092314
// Set up test environment

0 commit comments

Comments
 (0)