Skip to content

Commit aa22af2

Browse files
committed
Update Serval.Client to 1.12
1 parent 5c09f90 commit aa22af2

File tree

10 files changed

+241
-65
lines changed

10 files changed

+241
-65
lines changed

src/SIL.Converters.Usj/packages.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
}
2525
}
2626
}
27-
}
27+
}

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

Lines changed: 2 additions & 2 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,7 +40,7 @@
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.0" />
43+
<PackageReference Include="Serval.Client" Version="1.12.0" />
4444
<PackageReference Include="SIL.Machine" Version="3.7.7" />
4545
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
4646
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.6" />

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: 99 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,55 @@ 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-
cancellationToken: cancellationToken
211-
);
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+
quoteNormalizationBehavior: quoteNormalizationBehavior,
234+
cancellationToken: cancellationToken
235+
);
236+
}
237+
else
238+
{
239+
// Retrieve the USFM from a legacy corpus
240+
#pragma warning disable CS0612 // Type or member is obsolete
241+
usfm = await translationEnginesClient.GetCorpusPretranslatedUsfmAsync(
242+
id: translationEngineId,
243+
corpusId: corpusId,
244+
textId: GetTextId(bookNum),
245+
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
246+
template: PretranslationUsfmTemplate.Source,
247+
paragraphMarkerBehavior: paragraphMarkerBehavior,
248+
quoteNormalizationBehavior: quoteNormalizationBehavior,
249+
cancellationToken: cancellationToken
250+
);
251+
#pragma warning restore CS0612 // Type or member is obsolete
252+
}
212253

213254
// Return the entire book
214255
if (chapterNum == 0)
@@ -241,19 +282,34 @@ public async Task UpdatePreTranslationStatusAsync(string sfProjectId, Cancellati
241282
}
242283

243284
// Ensure we have the parameters to retrieve the pre-translation
244-
(string? translationEngineId, string corpusId, bool useParatextVerseRef) =
285+
(string? translationEngineId, string corpusId, string parallelCorpusId, bool useParatextVerseRef) =
245286
await GetPreTranslationParametersAsync(sfProjectId);
246287

247288
// Get all the pre-translations and update the chapters
248-
Dictionary<int, HashSet<int>> bookChapters = [];
249-
foreach (
250-
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
289+
IList<Pretranslation> preTranslations;
290+
if (parallelCorpusId is not null)
291+
{
292+
preTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
293+
translationEngineId,
294+
parallelCorpusId,
295+
textId: null,
296+
cancellationToken
297+
);
298+
}
299+
else
300+
{
301+
// Retrieve the pre-translations from a legacy corpus
302+
#pragma warning disable CS0612 // Type or member is obsolete
303+
preTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
251304
translationEngineId,
252305
corpusId,
253306
textId: null,
254307
cancellationToken
255-
)
256-
)
308+
);
309+
#pragma warning restore CS0612 // Type or member is obsolete
310+
}
311+
Dictionary<int, HashSet<int>> bookChapters = [];
312+
foreach (Pretranslation preTranslation in preTranslations)
257313
{
258314
// Get the book and chapter number
259315
int bookNum;
@@ -339,7 +395,8 @@ await projectDoc.SubmitJson0OpAsync(op =>
339395
/// <exception cref="DataNotFoundException">The pre-translation engine is not configured, or the project secret cannot be found.</exception>
340396
protected internal virtual async Task<(
341397
string translationEngineId,
342-
string corpusId,
398+
string? corpusId,
399+
string? parallelCorpusId,
343400
bool useParatextVerseRef
344401
)> GetPreTranslationParametersAsync(string sfProjectId)
345402
{
@@ -350,11 +407,12 @@ bool useParatextVerseRef
350407
}
351408

352409
string translationEngineId = projectSecret.ServalData?.PreTranslationEngineId;
353-
string corpusId;
410+
string? corpusId = null;
411+
string? parallelCorpusId = null;
354412
bool useParatextVerseRef = false;
355413
if (!string.IsNullOrWhiteSpace(projectSecret.ServalData?.ParallelCorpusIdForPreTranslate))
356414
{
357-
corpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
415+
parallelCorpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
358416
useParatextVerseRef = true;
359417
}
360418
else
@@ -369,11 +427,14 @@ bool useParatextVerseRef
369427
}
370428
}
371429

372-
if (string.IsNullOrWhiteSpace(translationEngineId) || string.IsNullOrWhiteSpace(corpusId))
430+
if (
431+
string.IsNullOrWhiteSpace(translationEngineId)
432+
|| (string.IsNullOrWhiteSpace(corpusId) && string.IsNullOrWhiteSpace(parallelCorpusId))
433+
)
373434
{
374435
throw new DataNotFoundException("The pre-translation engine is not configured.");
375436
}
376437

377-
return (translationEngineId, corpusId, useParatextVerseRef);
438+
return (translationEngineId, corpusId, parallelCorpusId, useParatextVerseRef);
378439
}
379440
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@
107107
},
108108
"Serval.Client": {
109109
"type": "Direct",
110-
"requested": "[1.10.0, )",
111-
"resolved": "1.10.0",
112-
"contentHash": "iO/hdbHaHK1dFN947D+MTAmSrlY38ZcKMDI4jKdD0SzW3xxMT1Mm8YTg4QpmpQFceLmSjdmc1UMLBp+E2n8fJg==",
110+
"requested": "[1.12.0, )",
111+
"resolved": "1.12.0",
112+
"contentHash": "lYcQFM6/mDzX/olxXLEKPoXDBmbyzQXAzVtpbU2pqtG9lW01PxzWmh4SBEElgK104QcI0I7a+EuyMXradgZPGw==",
113113
"dependencies": {
114114
"Newtonsoft.Json": "13.0.3",
115115
"System.ComponentModel.Annotations": "5.0.0"
@@ -2199,4 +2199,4 @@
21992199
}
22002200
}
22012201
}
2202-
}
2202+
}

src/SIL.XForge/packages.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,4 +1183,4 @@
11831183
}
11841184
}
11851185
}
1186-
}
1186+
}

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)