Skip to content

Commit f265dc8

Browse files
committed
Updated based on code review feedback
1 parent d52c85f commit f265dc8

File tree

2 files changed

+19
-99
lines changed

2 files changed

+19
-99
lines changed

src/Serval/test/Serval.E2ETests/ServalApiTests.cs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ public async Task Nmt_Batch()
157157
],
158158
}
159159
];
160+
161+
// Validate that a build can be started and canceled twice
162+
await StartAndCancelTwiceAsync(engineId);
163+
164+
// Validate an NMT build using text files
160165
string buildId = await _helperClient.BuildEngineAsync(engineId);
161166
await Task.Delay(1000);
162167
IList<Pretranslation> lTrans1 = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
@@ -186,41 +191,6 @@ public async Task Nmt_Batch()
186191
Assert.That(lTrans2, Has.Count.EqualTo(13)); // just 2 John
187192
}
188193

189-
[Test]
190-
public async Task Nmt_CancelAndRestartBuild()
191-
{
192-
string engineId = await _helperClient.CreateNewEngineAsync("Nmt", "es", "en", "NMT2");
193-
(string parallelCorpusId, ParallelCorpusConfig parallelCorpusConfig) =
194-
await _helperClient.AddParatextCorpusToEngineAsync(engineId, "es", "en", false);
195-
_helperClient.TranslationBuildConfig.TrainOn =
196-
[
197-
new TrainingCorpusConfig
198-
{
199-
ParallelCorpusId = parallelCorpusId,
200-
SourceFilters =
201-
[
202-
new ParallelCorpusFilterConfig { CorpusId = parallelCorpusConfig.SourceCorpusIds.Single() },
203-
],
204-
TargetFilters =
205-
[
206-
new ParallelCorpusFilterConfig { CorpusId = parallelCorpusConfig.TargetCorpusIds.Single() },
207-
],
208-
}
209-
];
210-
_helperClient.TranslationBuildConfig.Pretranslate =
211-
[
212-
new PretranslateCorpusConfig
213-
{
214-
ParallelCorpusId = parallelCorpusId,
215-
SourceFilters =
216-
[
217-
new ParallelCorpusFilterConfig { CorpusId = parallelCorpusConfig.SourceCorpusIds.Single() },
218-
],
219-
}
220-
];
221-
await StartAndCancelTwiceAsync(engineId);
222-
}
223-
224194
[Test]
225195
public async Task Nmt_LargeBatchAndDownload()
226196
{
@@ -402,6 +372,9 @@ public async Task Smt(bool legacyCorpus)
402372
Assert.That(ex, Is.Not.Null);
403373
Assert.That(ex.StatusCode, Is.EqualTo(409));
404374

375+
// Validate that a build can be started and canceled twice
376+
await StartAndCancelTwiceAsync(engineId);
377+
405378
// Validate suggestion where one word is the corpus
406379
string corpusId1 = await _helperClient.AddTextCorpusToEngineAsync(
407380
engineId,
@@ -495,20 +468,6 @@ await _helperClient.AddTextCorpusToEngineAsync(
495468
);
496469
}
497470

498-
[Test]
499-
public async Task Smt_CancelAndRestartBuild()
500-
{
501-
string engineId = await _helperClient.CreateNewEngineAsync("SmtTransfer", "es", "en", "SMT2");
502-
await _helperClient.AddParatextCorpusToEngineAsync(engineId, "es", "en", false);
503-
504-
await StartAndCancelTwiceAsync(engineId);
505-
506-
// do a job normally and make sure it works.
507-
await _helperClient.BuildEngineAsync(engineId);
508-
TranslationResult tResult = await _helperClient.TranslationEnginesClient.TranslateAsync(engineId, "Espíritu");
509-
Assert.That(tResult.Translation.Contains("spirit"));
510-
}
511-
512471
[Test]
513472
public async Task WordAlignment()
514473
{

src/Serval/test/Serval.E2ETests/ServalClientHelper.cs

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -460,27 +460,15 @@ bool inference
460460
);
461461
}
462462

463-
var sourceFileConfig = new List<TranslationCorpusFileConfig>();
464-
465-
if (sourceLanguage == targetLanguage && !inference)
466-
{
467-
// if it's the same language, and we are not pretranslating, do nothing (echo for suggestions)
468-
// if pretranslating, we need to upload the source separately
469-
// if different languages, we are not echoing.
470-
}
471-
else
472-
{
473-
sourceFileConfig.AddRange(
474-
sourceFiles.Select((s, i) => new TranslationCorpusFileConfig { FileId = s.Id, TextId = filesToAdd[i] })
475-
);
476-
}
477-
478463
TranslationCorpus response = await TranslationEnginesClient.AddCorpusAsync(
479464
id: engineId,
480465
new TranslationCorpusConfig
481466
{
482467
Name = "None",
483-
SourceFiles = sourceFileConfig,
468+
SourceFiles =
469+
[
470+
.. sourceFiles.Select((s, i) => new TranslationCorpusFileConfig { FileId = s.Id, TextId = filesToAdd[i] })
471+
],
484472
SourceLanguage = sourceLanguage,
485473
TargetFiles = targetFileConfig,
486474
TargetLanguage = targetLanguage
@@ -526,29 +514,17 @@ bool inference
526514
Corpus? targetCorpus =
527515
targetCorpusConfig.Files.Count > 0 ? await CorporaClient.CreateAsync(targetCorpusConfig) : null;
528516

529-
var sourceFileConfig = new List<CorpusFileConfig>();
530-
531-
if (sourceLanguage == targetLanguage && !inference)
532-
{
533-
// if it's the same language, and we are not pretranslating, do nothing (echo for suggestions)
534-
// if pretranslating, we need to upload the source separately
535-
// if different languages, we are not echoing.
536-
}
537-
else
538-
{
539-
DataFile sourceFile = await DataFilesClient.CreateAsync(
540-
file: new FileParameter(data: File.OpenRead(sourceZipFile), fileName: Path.GetFileName(sourceZipFile)),
541-
format: FileFormat.Paratext,
542-
name: $"{_prefix}{sourceLanguage}_zip"
543-
);
544-
sourceFileConfig.Add(new CorpusFileConfig { FileId = sourceFile.Id, TextId = "test_data" });
545-
}
517+
DataFile sourceFile = await DataFilesClient.CreateAsync(
518+
file: new FileParameter(data: File.OpenRead(sourceZipFile), fileName: Path.GetFileName(sourceZipFile)),
519+
format: FileFormat.Paratext,
520+
name: $"{_prefix}{sourceLanguage}_zip"
521+
);
546522

547523
var sourceCorpusConfig = new CorpusConfig()
548524
{
549525
Name = $"{_prefix}Source",
550526
Language = sourceLanguage,
551-
Files = sourceFileConfig
527+
Files = [new CorpusFileConfig { FileId = sourceFile.Id, TextId = "test_data" }]
552528
};
553529

554530
Corpus sourceCorpus = await CorporaClient.CreateAsync(sourceCorpusConfig);
@@ -588,26 +564,11 @@ bool inference
588564
Corpus? targetCorpus =
589565
targetCorpusConfig.Files.Count > 0 ? await CorporaClient.CreateAsync(targetCorpusConfig) : null;
590566

591-
var sourceFileConfig = new List<CorpusFileConfig>();
592-
593-
if (sourceLanguage == targetLanguage && !inference)
594-
{
595-
// if it's the same language, and we are not pretranslating, do nothing (echo for suggestions)
596-
// if pretranslating, we need to upload the source separately
597-
// if different languages, we are not echoing.
598-
}
599-
else
600-
{
601-
sourceFileConfig.AddRange(
602-
sourceFiles.Select((s, i) => new CorpusFileConfig { FileId = s.Id, TextId = filesToAdd[i] })
603-
);
604-
}
605-
606567
var sourceCorpusConfig = new CorpusConfig()
607568
{
608569
Name = $"{_prefix}Source",
609570
Language = sourceLanguage,
610-
Files = sourceFileConfig
571+
Files = [.. sourceFiles.Select((s, i) => new CorpusFileConfig { FileId = s.Id, TextId = filesToAdd[i] })]
611572
};
612573

613574
Corpus sourceCorpus = await CorporaClient.CreateAsync(sourceCorpusConfig);

0 commit comments

Comments
 (0)