Skip to content

Commit

Permalink
Fix missed copy-paste errors; throw error if deprecated corpusId is s…
Browse files Browse the repository at this point in the history
…et; add note to API
  • Loading branch information
Enkidu93 committed Feb 27, 2025
1 parent f399818 commit 520982c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7163,7 +7163,7 @@ public partial interface IWordAlignmentEnginesClient
/// Starts a build job for a engine.
/// </summary>
/// <remarks>
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used.
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used. Only parallel corpora are supported.
/// <br/>Paratext Projects, you may flag a subset of books for training by including their [abbreviations]
/// <br/>Paratext projects can be filtered by [book](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) using the textId for training.
/// <br/>Filters can also be supplied via scriptureRange parameter as ranges of biblical text. See [here](https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range)
Expand Down Expand Up @@ -8638,7 +8638,7 @@ public string BaseUrl
/// Starts a build job for a engine.
/// </summary>
/// <remarks>
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used.
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used. Only parallel corpora are supported.
/// <br/>Paratext Projects, you may flag a subset of books for training by including their [abbreviations]
/// <br/>Paratext projects can be filtered by [book](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) using the textId for training.
/// <br/>Filters can also be supplied via scriptureRange parameter as ranges of biblical text. See [here](https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Serval.WordAlignment.Controllers;

#pragma warning disable CS0612 // Type or member is obsolete

[ApiVersion(1.0)]
[Route("api/v{version:apiVersion}/word-alignment/engines")]
[OpenApiTag("Word Alignment Engines")]
Expand Down Expand Up @@ -323,7 +325,7 @@ CancellationToken cancellationToken
/// <response code="403">The authenticated client cannot perform the operation or does not own the engine.</response>
/// <response code="404">The engine or parallel corpus does not exist.</response>
/// <response code="503">A necessary service is currently unavailable. Check `/health` for more details.</response>
[Authorize(Scopes.ReadTranslationEngines)]
[Authorize(Scopes.ReadWordAlignmentEngines)]
[HttpGet("{id}/parallel-corpora/{parallelCorpusId}", Name = Endpoints.GetParallelWordAlignmentCorpus)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
Expand Down Expand Up @@ -531,7 +533,7 @@ CancellationToken cancellationToken
/// Starts a build job for a engine.
/// </summary>
/// <remarks>
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used.
/// Specify the corpora and textIds to train on. If no "trainOn" field is provided, all corpora will be used. Only parallel corpora are supported.
/// Paratext Projects, you may flag a subset of books for training by including their [abbreviations]
/// Paratext projects can be filtered by [book](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) using the textId for training.
/// Filters can also be supplied via scriptureRange parameter as ranges of biblical text. See [here](https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range)
Expand Down Expand Up @@ -740,7 +742,7 @@ private WordAlignmentParallelCorpusDto Map(string engineId, ParallelCorpus sourc
Engine = new ResourceLinkDto
{
Id = engineId,
Url = _urlService.GetUrl(Endpoints.GetTranslationEngine, new { id = engineId })
Url = _urlService.GetUrl(Endpoints.GetWordAlignmentEngine, new { id = engineId })
},
SourceCorpora = source
.SourceCorpora.Select(c => new ResourceLinkDto
Expand Down Expand Up @@ -802,7 +804,7 @@ private static Build Map(Engine engine, WordAlignmentBuildConfigDto source, stri
)
{
throw new InvalidOperationException(
$"Only the first source corpus in a parallel corpus may be filtered for pretranslation."
$"Only the first source corpus in a parallel corpus may be filtered for alignment."
);
}
wordAlignmentCorpora.Add(
Expand All @@ -826,9 +828,13 @@ private static Build Map(Engine engine, WordAlignmentBuildConfigDto source, stri
var trainingCorpora = new List<TrainingCorpus>();
foreach (TrainingCorpusConfigDto cc in source)
{
if (cc.CorpusId != null)
{
throw new InvalidOperationException($"CorpusId cannot be set. Only ParallelCorpusId is supported.");
}
if (cc.ParallelCorpusId == null)
{
throw new InvalidOperationException($"One of ParallelCorpusId and CorpusId must be set.");
throw new InvalidOperationException($"ParallelCorpusId must be set.");
}
if (!corpusIds.Contains(cc.ParallelCorpusId))
{
Expand Down Expand Up @@ -901,13 +907,16 @@ private WordAlignmentBuildDto Map(Build source)
return new WordAlignmentBuildDto
{
Id = source.Id,
Url = _urlService.GetUrl(Endpoints.GetTranslationBuild, new { id = source.EngineRef, buildId = source.Id }),
Url = _urlService.GetUrl(
Endpoints.GetWordAlignmentBuild,
new { id = source.EngineRef, buildId = source.Id }
),
Revision = source.Revision,
Name = source.Name,
Engine = new ResourceLinkDto
{
Id = source.EngineRef,
Url = _urlService.GetUrl(Endpoints.GetTranslationEngine, new { id = source.EngineRef })
Url = _urlService.GetUrl(Endpoints.GetWordAlignmentBuild, new { id = source.EngineRef })
},
TrainOn = source.TrainOn?.Select(s => Map(source.EngineRef, s)).ToList(),
WordAlignOn = source.WordAlignOn?.Select(s => Map(source.EngineRef, s)).ToList(),
Expand All @@ -933,7 +942,7 @@ private TrainingCorpusDto Map(string engineId, TrainingCorpus source)
{
Id = source.ParallelCorpusRef,
Url = _urlService.GetUrl(
Endpoints.GetParallelTranslationCorpus,
Endpoints.GetParallelWordAlignmentCorpus,
new { id = engineId, parallelCorpusId = source.ParallelCorpusRef }
)
}
Expand All @@ -953,7 +962,7 @@ private WordAlignmentCorpusDto Map(string engineId, WordAlignmentCorpus source)
{
Id = source.ParallelCorpusRef,
Url = _urlService.GetUrl(
Endpoints.GetParallelTranslationCorpus,
Endpoints.GetParallelWordAlignmentCorpus,
new { id = engineId, parallelCorpusId = source.ParallelCorpusRef }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ await _dataAccessContext.WithTransactionAsync(
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));

await _publishEndpoint.Publish(
new TranslationBuildStarted
new WordAlignmentBuildStarted
{
BuildId = build.Id,
EngineId = engine.Id,
Expand Down Expand Up @@ -84,14 +84,14 @@ await _dataAccessContext.WithTransactionAsync(
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));

// delete pretranslations created by the previous build
// delete alignments created by the previous build
await _wordAlignments.DeleteAllAsync(
p => p.EngineRef == engine.Id && p.ModelRevision < engine.ModelRevision,
ct
);

await _publishEndpoint.Publish(
new TranslationBuildFinished
new WordAlignmentBuildFinished
{
BuildId = build.Id,
EngineId = engine.Id,
Expand Down Expand Up @@ -133,14 +133,14 @@ await _dataAccessContext.WithTransactionAsync(
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));

// delete pretranslations that might have been created during the build
// delete word alignments that might have been created during the build
await _wordAlignments.DeleteAllAsync(
p => p.EngineRef == engine.Id && p.ModelRevision > engine.ModelRevision,
ct
);

await _publishEndpoint.Publish(
new TranslationBuildFinished
new WordAlignmentBuildFinished
{
BuildId = build.Id,
EngineId = engine.Id,
Expand Down Expand Up @@ -182,14 +182,14 @@ await _dataAccessContext.WithTransactionAsync(
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));

// delete pretranslations that might have been created during the build
// delete word alignments that might have been created during the build
await _wordAlignments.DeleteAllAsync(
p => p.EngineRef == engine.Id && p.ModelRevision > engine.ModelRevision,
ct
);

await _publishEndpoint.Publish(
new TranslationBuildFinished
new WordAlignmentBuildFinished
{
BuildId = build.Id,
EngineId = engine.Id,
Expand Down Expand Up @@ -228,7 +228,7 @@ await _dataAccessContext.WithTransactionAsync(
if (engine is null)
throw new RpcException(new Status(StatusCode.NotFound, "The engine does not exist."));

// delete pretranslations that might have been created during the build
// delete word alignments that might have been created during the build
await _wordAlignments.DeleteAllAsync(
p => p.EngineRef == engine.Id && p.ModelRevision > engine.ModelRevision,
ct
Expand Down

0 comments on commit 520982c

Please sign in to comment.