From 8db0bad4092d6b70e9eb7df7982245dea1553393 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Tue, 26 Nov 2024 12:02:03 -0500 Subject: [PATCH] Make logic consistent; remove inconsistent error messages --- .../Services/PreprocessBuildJobTests.cs | 21 ++++++------------- .../ParallelCorpusPreprocessingService.cs | 12 ++++------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/Machine/test/Serval.Machine.Shared.Tests/Services/PreprocessBuildJobTests.cs b/src/Machine/test/Serval.Machine.Shared.Tests/Services/PreprocessBuildJobTests.cs index d39b5870..02669cb4 100644 --- a/src/Machine/test/Serval.Machine.Shared.Tests/Services/PreprocessBuildJobTests.cs +++ b/src/Machine/test/Serval.Machine.Shared.Tests/Services/PreprocessBuildJobTests.cs @@ -65,11 +65,7 @@ public async Task RunAsync_TrainAndPretranslateAll() await env.RunBuildJobAsync(corpus1); - Assert.That( - await env.GetPretranslateCountAsync(), - Is.EqualTo(2), - (await env.GetPretranslationsAsync())?.ToJsonString() - ); + Assert.That(await env.GetPretranslateCountAsync(), Is.EqualTo(2)); } [Test] @@ -107,7 +103,7 @@ public async Task RunAsync_PretranslateTextIdsOverlapWithTrainOnTextIds() Assert.Multiple(async () => { Assert.That((await env.GetTrainCountAsync()).Source1Count, Is.EqualTo(4)); - Assert.That(await env.GetPretranslateCountAsync(), Is.EqualTo(0)); + Assert.That(await env.GetPretranslateCountAsync(), Is.EqualTo(2)); }); } @@ -214,11 +210,7 @@ public async Task RunAsync_MixedSource_Paratext() Assert.That(trgCount, Is.EqualTo(1)); Assert.That(termCount, Is.EqualTo(0)); }); - Assert.That( - await env.GetPretranslateCountAsync(), - Is.EqualTo(15), - (await env.GetPretranslationsAsync())?.ToJsonString() - ); + Assert.That(await env.GetPretranslateCountAsync(), Is.EqualTo(15)); } [Test] @@ -296,7 +288,7 @@ public async Task RunAsync_RemoveFreestandingEllipses() ); JsonArray? pretranslations = await env.GetPretranslationsAsync(); Assert.That(pretranslations, Is.Not.Null); - Assert.That(pretranslations!.Count, Is.EqualTo(0)); + Assert.That(pretranslations!.Count, Is.EqualTo(1)); } [Test] @@ -508,11 +500,10 @@ public async Task ParallelCorpusLogic() trg ); Assert.That(pretranslations, Is.Not.Null); - Assert.That(pretranslations!.Count, Is.EqualTo(7), pretranslations.ToJsonString()); + Assert.That(pretranslations!.Count, Is.EqualTo(7)); Assert.That( pretranslations[2]!["translation"]!.ToString(), - Is.EqualTo("Source one, chapter twelve, verse one."), - pretranslations.ToJsonString() + Is.EqualTo("Source one, chapter twelve, verse one.") ); }); } diff --git a/src/ServiceToolkit/src/SIL.ServiceToolkit/Services/ParallelCorpusPreprocessingService.cs b/src/ServiceToolkit/src/SIL.ServiceToolkit/Services/ParallelCorpusPreprocessingService.cs index 9f1439ff..e75a2d59 100644 --- a/src/ServiceToolkit/src/SIL.ServiceToolkit/Services/ParallelCorpusPreprocessingService.cs +++ b/src/ServiceToolkit/src/SIL.ServiceToolkit/Services/ParallelCorpusPreprocessingService.cs @@ -116,19 +116,13 @@ private static ITextCorpus FilterPretranslateCorpora(MonolingualCorpus corpus, I textCorpus = textCorpus.Transform(CleanSegment); if (corpus.PretranslateTextIds is not null) { - return textCorpus.FilterTexts(corpus.PretranslateTextIds.Except(corpus.TrainOnTextIds ?? new())); + return textCorpus.FilterTexts(corpus.PretranslateTextIds); } if (corpus.PretranslateChapters is not null) { return textCorpus .FilterTexts(corpus.PretranslateChapters.Keys) - .Where(row => - row.Ref is not ScriptureRef sr - || ( - IsInChapters(sr, corpus.PretranslateChapters) - && !IsInChapters(sr, corpus.TrainOnChapters ?? new()) - ) - ); + .Where(row => row.Ref is not ScriptureRef sr || IsInChapters(sr, corpus.PretranslateChapters)); } return textCorpus; } @@ -137,7 +131,9 @@ private static ITextCorpus FilterTrainingCorpora(MonolingualCorpus corpus, IText { textCorpus = textCorpus.Transform(CleanSegment); if (corpus.TrainOnTextIds is not null) + { return textCorpus.FilterTexts(corpus.TrainOnTextIds); + } if (corpus.TrainOnChapters is not null) { return textCorpus