Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SIL.Converters.Usj/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
Expand Down Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="ParatextData" Version="9.5.0.19" />
<!-- When updating Serval.Client consider that API changes must be released to Serval Prod
prior to testing on SF QA -->
<PackageReference Include="Serval.Client" Version="1.10.0" />
<PackageReference Include="Serval.Client" Version="1.12.0" />
<PackageReference Include="SIL.Machine" Version="3.7.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.6" />
Expand Down
4 changes: 3 additions & 1 deletion src/SIL.XForge.Scripture/Services/MachineProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,15 +1482,17 @@ out SFProjectSecret projectSecret
.ToArray() ?? [];
foreach (string corpusId in corpusIds)
{
// Delete the corpus
// Delete the legacy corpus
try
{
#pragma warning disable CS0612 // Type or member is obsolete
await translationEnginesClient.DeleteCorpusAsync(
translationEngineId,
corpusId,
deleteFiles: true,
cancellationToken
);
#pragma warning restore CS0612 // Type or member is obsolete
}
catch (ServalApiException e)
{
Expand Down
137 changes: 99 additions & 38 deletions src/SIL.XForge.Scripture/Services/PreTranslationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,35 @@ CancellationToken cancellationToken
List<PreTranslation> preTranslations = [];

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

// Get the pre-translation data from Serval
string textId = useParatextVerseRef ? GetTextId(bookNum) : GetTextId(bookNum, chapterNum);
foreach (
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
IList<Pretranslation> servalPreTranslations;
if (parallelCorpusId is not null)
{
servalPreTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
translationEngineId,
parallelCorpusId,
textId,
cancellationToken
);
}
else
{
// Retrieve the pre-translations from a legacy corpus
#pragma warning disable CS0612 // Type or member is obsolete
servalPreTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
translationEngineId,
corpusId,
textId,
cancellationToken
)
)
);
#pragma warning restore CS0612 // Type or member is obsolete
}

foreach (Pretranslation preTranslation in servalPreTranslations)
{
// A reference will be in one of the formats:
// FileFormat.Text: "40_1:verse_001_002"
Expand Down Expand Up @@ -185,30 +201,55 @@ CancellationToken cancellationToken
)
{
// Ensure we have the parameters to retrieve the pre-translation
(string? translationEngineId, string corpusId, bool _) = await GetPreTranslationParametersAsync(sfProjectId);
(string? translationEngineId, string? corpusId, string? parallelCorpusId, bool _) =
await GetPreTranslationParametersAsync(sfProjectId);

// Generate the paragraph marker and quote normalization behaviors
PretranslationUsfmMarkerBehavior paragraphMarkerBehavior = config.ParagraphFormat switch
{
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
};
PretranslationNormalizationBehavior quoteNormalizationBehavior = config.QuoteFormat switch
{
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
_ => PretranslationNormalizationBehavior.Denormalized,
};

// Get the USFM
string usfm = await translationEnginesClient.GetPretranslatedUsfmAsync(
id: translationEngineId,
corpusId: corpusId,
textId: GetTextId(bookNum),
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
template: PretranslationUsfmTemplate.Source,
paragraphMarkerBehavior: config.ParagraphFormat switch
{
ParagraphBreakFormatOptions.Remove => PretranslationUsfmMarkerBehavior.Strip,
ParagraphBreakFormatOptions.BestGuess => PretranslationUsfmMarkerBehavior.PreservePosition,
ParagraphBreakFormatOptions.MoveToEnd => PretranslationUsfmMarkerBehavior.Preserve,
_ => PretranslationUsfmMarkerBehavior.PreservePosition,
},
quoteNormalizationBehavior: config.QuoteFormat switch
{
QuoteStyleOptions.Denormalized => PretranslationNormalizationBehavior.Denormalized,
QuoteStyleOptions.Normalized => PretranslationNormalizationBehavior.Normalized,
_ => PretranslationNormalizationBehavior.Denormalized,
},
cancellationToken: cancellationToken
);
string usfm;
if (parallelCorpusId is not null)
{
usfm = await translationEnginesClient.GetPretranslatedUsfmAsync(
id: translationEngineId,
parallelCorpusId: parallelCorpusId,
textId: GetTextId(bookNum),
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
template: PretranslationUsfmTemplate.Source,
paragraphMarkerBehavior: paragraphMarkerBehavior,
quoteNormalizationBehavior: quoteNormalizationBehavior,
cancellationToken: cancellationToken
);
}
else
{
// Retrieve the USFM from a legacy corpus
#pragma warning disable CS0612 // Type or member is obsolete
usfm = await translationEnginesClient.GetCorpusPretranslatedUsfmAsync(
id: translationEngineId,
corpusId: corpusId,
textId: GetTextId(bookNum),
textOrigin: PretranslationUsfmTextOrigin.OnlyPretranslated,
template: PretranslationUsfmTemplate.Source,
paragraphMarkerBehavior: paragraphMarkerBehavior,
quoteNormalizationBehavior: quoteNormalizationBehavior,
cancellationToken: cancellationToken
);
#pragma warning restore CS0612 // Type or member is obsolete
}

// Return the entire book
if (chapterNum == 0)
Expand Down Expand Up @@ -241,19 +282,34 @@ public async Task UpdatePreTranslationStatusAsync(string sfProjectId, Cancellati
}

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

// Get all the pre-translations and update the chapters
Dictionary<int, HashSet<int>> bookChapters = [];
foreach (
Pretranslation preTranslation in await translationEnginesClient.GetAllPretranslationsAsync(
IList<Pretranslation> preTranslations;
if (parallelCorpusId is not null)
{
preTranslations = await translationEnginesClient.GetAllPretranslationsAsync(
translationEngineId,
parallelCorpusId,
textId: null,
cancellationToken
);
}
else
{
// Retrieve the pre-translations from a legacy corpus
#pragma warning disable CS0612 // Type or member is obsolete
preTranslations = await translationEnginesClient.GetAllCorpusPretranslationsAsync(
translationEngineId,
corpusId,
textId: null,
cancellationToken
)
)
);
#pragma warning restore CS0612 // Type or member is obsolete
}
Dictionary<int, HashSet<int>> bookChapters = [];
foreach (Pretranslation preTranslation in preTranslations)
{
// Get the book and chapter number
int bookNum;
Expand Down Expand Up @@ -339,7 +395,8 @@ await projectDoc.SubmitJson0OpAsync(op =>
/// <exception cref="DataNotFoundException">The pre-translation engine is not configured, or the project secret cannot be found.</exception>
protected internal virtual async Task<(
string translationEngineId,
string corpusId,
string? corpusId,
string? parallelCorpusId,
bool useParatextVerseRef
)> GetPreTranslationParametersAsync(string sfProjectId)
{
Expand All @@ -350,11 +407,12 @@ bool useParatextVerseRef
}

string translationEngineId = projectSecret.ServalData?.PreTranslationEngineId;
string corpusId;
string? corpusId = null;
string? parallelCorpusId = null;
bool useParatextVerseRef = false;
if (!string.IsNullOrWhiteSpace(projectSecret.ServalData?.ParallelCorpusIdForPreTranslate))
{
corpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
parallelCorpusId = projectSecret.ServalData.ParallelCorpusIdForPreTranslate;
useParatextVerseRef = true;
}
else
Expand All @@ -369,11 +427,14 @@ bool useParatextVerseRef
}
}

if (string.IsNullOrWhiteSpace(translationEngineId) || string.IsNullOrWhiteSpace(corpusId))
if (
string.IsNullOrWhiteSpace(translationEngineId)
|| (string.IsNullOrWhiteSpace(corpusId) && string.IsNullOrWhiteSpace(parallelCorpusId))
)
{
throw new DataNotFoundException("The pre-translation engine is not configured.");
}

return (translationEngineId, corpusId, useParatextVerseRef);
return (translationEngineId, corpusId, parallelCorpusId, useParatextVerseRef);
}
}
8 changes: 4 additions & 4 deletions src/SIL.XForge.Scripture/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
},
"Serval.Client": {
"type": "Direct",
"requested": "[1.10.0, )",
"resolved": "1.10.0",
"contentHash": "iO/hdbHaHK1dFN947D+MTAmSrlY38ZcKMDI4jKdD0SzW3xxMT1Mm8YTg4QpmpQFceLmSjdmc1UMLBp+E2n8fJg==",
"requested": "[1.12.0, )",
"resolved": "1.12.0",
"contentHash": "lYcQFM6/mDzX/olxXLEKPoXDBmbyzQXAzVtpbU2pqtG9lW01PxzWmh4SBEElgK104QcI0I7a+EuyMXradgZPGw==",
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"System.ComponentModel.Annotations": "5.0.0"
Expand Down Expand Up @@ -2199,4 +2199,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/SIL.XForge/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1183,4 +1183,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@ await env
}

[Test]
[Obsolete("Tests legacy corpora")]
public async Task RemoveLegacyServalDataAsync_DoesNotCallServalIfNoTranslationEngineId()
{
// Set up test environment
Expand All @@ -2261,6 +2262,7 @@ await env
}

[Test]
[Obsolete("Tests legacy corpora")]
public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs()
{
// Set up test environment
Expand All @@ -2283,6 +2285,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnErrorWhenAServalErrorOccurs(
}

[Test]
[Obsolete("Tests legacy corpora")]
public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
{
// Set up test environment
Expand All @@ -2307,6 +2310,7 @@ public async Task RemoveLegacyServalDataAsync_LogsAnEventWhenTheFileIsNotFound()
}

[Test]
[Obsolete("Tests legacy corpora")]
public async Task RemoveLegacyServalDataAsync_OnlyRemovesRelevantCorpora()
{
// Set up test environment
Expand All @@ -2328,6 +2332,7 @@ await env
}

[Test]
[Obsolete("Tests legacy corpora")]
public async Task RemoveLegacyServalDataAsync_RemovesCorporaPropertyIfNoMoreCorpora()
{
// Set up test environment
Expand Down
Loading
Loading