Skip to content

Commit 5714bd5

Browse files
committed
Update Serval.Client to 1.12
1 parent ef1f596 commit 5714bd5

File tree

8 files changed

+244
-61
lines changed

8 files changed

+244
-61
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<PackageReference Include="ParatextData" Version="9.5.0.14" />
4242
<!-- When updating Serval.Client consider that API changes must be released to Serval Prod
4343
prior to testing on SF QA -->
44-
<PackageReference Include="Serval.Client" Version="1.10.0" />
44+
<PackageReference Include="Serval.Client" Version="1.12.0" />
4545
<PackageReference Include="SharpZipLib" Version="1.4.2" />
4646
<PackageReference Include="SIL.Machine" Version="3.7.3" />
4747
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,15 +1482,17 @@ out SFProjectSecret projectSecret
14821482
.ToArray() ?? [];
14831483
foreach (string corpusId in corpusIds)
14841484
{
1485-
// Delete the corpus
1485+
// Delete the legacy corpus
14861486
try
14871487
{
1488+
#pragma warning disable CS0612 // Type or member is obsolete
14881489
await translationEnginesClient.DeleteCorpusAsync(
14891490
translationEngineId,
14901491
corpusId,
14911492
deleteFiles: true,
14921493
cancellationToken
14931494
);
1495+
#pragma warning restore CS0612 // Type or member is obsolete
14941496
}
14951497
catch (ServalApiException e)
14961498
{

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

Lines changed: 106 additions & 38 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,30 +201,62 @@ 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);
189206

190207
// 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-
cancellationToken: cancellationToken
211-
);
208+
string usfm;
209+
if (parallelCorpusId is not null)
210+
{
211+
usfm = await translationEnginesClient.GetPretranslatedUsfmAsync(
212+
id: translationEngineId,
213+
parallelCorpusId: parallelCorpusId,
214+
textId: GetTextId(bookNum),
215+
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
216+
template: PretranslationUsfmTemplate.Source,
217+
paragraphMarkerBehavior: config.ParagraphFormat switch
218+
{
219+
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
220+
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
221+
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
222+
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
223+
},
224+
quoteNormalizationBehavior: config.QuoteFormat switch
225+
{
226+
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
227+
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
228+
_ => PretranslationNormalizationBehavior.Denormalized,
229+
},
230+
cancellationToken: cancellationToken
231+
);
232+
}
233+
else
234+
{
235+
// Retrieve the USFM from a legacy corpus
236+
#pragma warning disable CS0612 // Type or member is obsolete
237+
usfm = await translationEnginesClient.GetCorpusPretranslatedUsfmAsync(
238+
id: translationEngineId,
239+
corpusId: corpusId,
240+
textId: GetTextId(bookNum),
241+
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
242+
template: PretranslationUsfmTemplate.Source,
243+
paragraphMarkerBehavior: config.ParagraphFormat switch
244+
{
245+
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
246+
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
247+
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
248+
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
249+
},
250+
quoteNormalizationBehavior: config.QuoteFormat switch
251+
{
252+
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
253+
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
254+
_ => PretranslationNormalizationBehavior.Denormalized,
255+
},
256+
cancellationToken: cancellationToken
257+
);
258+
#pragma warning restore CS0612 // Type or member is obsolete
259+
}
212260

213261
// Return the entire book
214262
if (chapterNum == 0)
@@ -241,19 +289,34 @@ public async Task UpdatePreTranslationStatusAsync(string sfProjectId, Cancellati
241289
}
242290

243291
// Ensure we have the parameters to retrieve the pre-translation
244-
(string? translationEngineId, string corpusId, bool useParatextVerseRef) =
292+
(string? translationEngineId, string corpusId, string parallelCorpusId, bool useParatextVerseRef) =
245293
await GetPreTranslationParametersAsync(sfProjectId);
246294

247295
// Get all the pre-translations and update the chapters
248-
Dictionary<int, HashSet<int>> bookChapters = [];
249-
foreach (
250-
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
296+
IList<Pretranslation> preTranslations;
297+
if (parallelCorpusId is not null)
298+
{
299+
preTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
300+
translationEngineId,
301+
parallelCorpusId,
302+
textId: null,
303+
cancellationToken
304+
);
305+
}
306+
else
307+
{
308+
// Retrieve the pre-translations from a legacy corpus
309+
#pragma warning disable CS0612 // Type or member is obsolete
310+
preTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
251311
translationEngineId,
252312
corpusId,
253313
textId: null,
254314
cancellationToken
255-
)
256-
)
315+
);
316+
#pragma warning restore CS0612 // Type or member is obsolete
317+
}
318+
Dictionary<int, HashSet<int>> bookChapters = [];
319+
foreach (Pretranslation preTranslation in preTranslations)
257320
{
258321
// Get the book and chapter number
259322
int bookNum;
@@ -339,7 +402,8 @@ await projectDoc.SubmitJson0OpAsync(op =>
339402
/// <exception cref="DataNotFoundException">The pre-translation engine is not configured, or the project secret cannot be found.</exception>
340403
protected internal virtual async Task<(
341404
string translationEngineId,
342-
string corpusId,
405+
string? corpusId,
406+
string? parallelCorpusId,
343407
bool useParatextVerseRef
344408
)> GetPreTranslationParametersAsync(string sfProjectId)
345409
{
@@ -350,11 +414,12 @@ bool useParatextVerseRef
350414
}
351415

352416
string translationEngineId = projectSecret.ServalData?.PreTranslationEngineId;
353-
string corpusId;
417+
string? corpusId = null;
418+
string? parallelCorpusId = null;
354419
bool useParatextVerseRef = false;
355420
if (!string.IsNullOrWhiteSpace(projectSecret.ServalData?.ParallelCorpusIdForPreTranslate))
356421
{
357-
corpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
422+
parallelCorpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
358423
useParatextVerseRef = true;
359424
}
360425
else
@@ -369,11 +434,14 @@ bool useParatextVerseRef
369434
}
370435
}
371436

372-
if (string.IsNullOrWhiteSpace(translationEngineId) || string.IsNullOrWhiteSpace(corpusId))
437+
if (
438+
string.IsNullOrWhiteSpace(translationEngineId)
439+
|| (string.IsNullOrWhiteSpace(corpusId) && string.IsNullOrWhiteSpace(parallelCorpusId))
440+
)
373441
{
374442
throw new DataNotFoundException("The pre-translation engine is not configured.");
375443
}
376444

377-
return (translationEngineId, corpusId, useParatextVerseRef);
445+
return (translationEngineId, corpusId, parallelCorpusId, useParatextVerseRef);
378446
}
379447
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@
159159
},
160160
"Serval.Client": {
161161
"type": "Direct",
162-
"requested": "[1.10.0, )",
163-
"resolved": "1.10.0",
164-
"contentHash": "iO/hdbHaHK1dFN947D+MTAmSrlY38ZcKMDI4jKdD0SzW3xxMT1Mm8YTg4QpmpQFceLmSjdmc1UMLBp+E2n8fJg==",
162+
"requested": "[1.12.0, )",
163+
"resolved": "1.12.0",
164+
"contentHash": "lYcQFM6/mDzX/olxXLEKPoXDBmbyzQXAzVtpbU2pqtG9lW01PxzWmh4SBEElgK104QcI0I7a+EuyMXradgZPGw==",
165165
"dependencies": {
166166
"Newtonsoft.Json": "13.0.3",
167167
"System.ComponentModel.Annotations": "5.0.0"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,7 @@ await env
22462246
}
22472247

22482248
[Test]
2249+
[Obsolete("Tests legacy corpora")]
22492250
public async Task RemoveLegacyServalDataAsync_DoesNotCallServalIfNoTranslationEngineId()
22502251
{
22512252
// Set up test environment
@@ -2261,6 +2262,7 @@ await env
22612262
}
22622263

22632264
[Test]
2265+
[Obsolete("Tests legacy corpora")]
22642266
public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs()
22652267
{
22662268
// Set up test environment
@@ -2283,6 +2285,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs(
22832285
}
22842286

22852287
[Test]
2288+
[Obsolete("Tests legacy corpora")]
22862289
public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
22872290
{
22882291
// Set up test environment
@@ -2307,6 +2310,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
23072310
}
23082311

23092312
[Test]
2313+
[Obsolete("Tests legacy corpora")]
23102314
public async Task RemoveLegacyServalDataAsync_OnlyRemovesRelevantCorpora()
23112315
{
23122316
// Set up test environment
@@ -2328,6 +2332,7 @@ await env
23282332
}
23292333

23302334
[Test]
2335+
[Obsolete("Tests legacy corpora")]
23312336
public async Task RemoveLegacyServalDataAsync_RemovesCorporaPropertyIfNoMoreCorpora()
23322337
{
23332338
// Set up test environment

0 commit comments

Comments
 (0)