Skip to content

Commit

Permalink
Fix test: Add ability to specify CorpusService mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Oct 16, 2024
1 parent 31a31c3 commit 5a61291
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ CancellationToken cancellationToken
int trainCount = 0;
int pretranslateCount = 0;
pretranslateWriter.WriteStartArray();
ParallelCorpusPreprocessor.PreprocessCorpora(
new ParallelCorpusPreprocessor() { CorpusService = CorpusService }.Preprocess(
corpora,
row =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace SIL.ServiceToolkit.Utils;

public class ParallelCorpusPreprocessor
{
private readonly ICorpusService _corpusService;
public ICorpusService CorpusService { get; init; }
private int _seed = 1234;
private Random _random;

public ParallelCorpusPreprocessor()
{
_corpusService = new CorpusService();
CorpusService = new CorpusService();
_random = new Random(_seed);
}

Expand Down Expand Up @@ -45,7 +45,7 @@ public void Preprocess(
foreach (ParallelCorpus corpus in corpora)
{
(MonolingualCorpus Corpus, ITextCorpus TextCorpus)[] sourceCorpora = corpus
.SourceCorpora.SelectMany(c => _corpusService.CreateTextCorpora(c.Files).Select(tc => (c, tc)))
.SourceCorpora.SelectMany(c => CorpusService.CreateTextCorpora(c.Files).Select(tc => (c, tc)))
.ToArray();
ITextCorpus[] sourceTrainingCorpora = sourceCorpora
.Select(sc =>
Expand Down Expand Up @@ -78,7 +78,7 @@ row.Ref is not ScriptureRef sr
.ToArray();

(MonolingualCorpus Corpus, ITextCorpus TextCorpus)[] targetCorpora = corpus
.TargetCorpora.SelectMany(c => _corpusService.CreateTextCorpora(c.Files).Select(tc => (c, tc)))
.TargetCorpora.SelectMany(c => CorpusService.CreateTextCorpora(c.Files).Select(tc => (c, tc)))
.ToArray();
ITextCorpus[] targetTrainingCorpora = targetCorpora
.Select(tc =>
Expand Down Expand Up @@ -138,10 +138,10 @@ row.Ref is not ScriptureRef sr

if (useKeyTerms)
{
ITextCorpus? sourceTermCorpus = _corpusService
ITextCorpus? sourceTermCorpus = CorpusService
.CreateTermCorpora(corpus.SourceCorpora.SelectMany(sc => sc.Files).ToList())
.FirstOrDefault();
ITextCorpus? targetTermCorpus = _corpusService
ITextCorpus? targetTermCorpus = CorpusService
.CreateTermCorpora(corpus.TargetCorpora.SelectMany(tc => tc.Files).ToList())
.FirstOrDefault();
if (sourceTermCorpus is not null && targetTermCorpus is not null)
Expand Down

0 comments on commit 5a61291

Please sign in to comment.