Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use localizations for key terms #454

Merged
merged 17 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
return corpora;
}

public IEnumerable<ITextCorpus> CreateTermCorpora(IReadOnlyList<CorpusFile> files)
public IEnumerable<ITextCorpus> CreateTermCorpora(IReadOnlyList<CorpusFile> files, string? languageCode = null)
{
foreach (CorpusFile file in files)
{
switch (file.Format)
{
case FileFormat.Paratext:
yield return new ParatextBackupTermsCorpus(file.Location, ["PN"]);
yield return new ParatextBackupTermsCorpus(file.Location, ["PN"], languageCode: languageCode);

Check failure on line 46 in src/Machine/src/Serval.Machine.Shared/Services/CorpusService.cs

View workflow job for this annotation

GitHub Actions / Build

The best overload for 'ParatextBackupTermsCorpus' does not have a parameter named 'languageCode'

Check failure on line 46 in src/Machine/src/Serval.Machine.Shared/Services/CorpusService.cs

View workflow job for this annotation

GitHub Actions / Build

The best overload for 'ParatextBackupTermsCorpus' does not have a parameter named 'languageCode'
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface ICorpusService
{
IEnumerable<ITextCorpus> CreateTextCorpora(IReadOnlyList<CorpusFile> files);
IEnumerable<ITextCorpus> CreateTermCorpora(IReadOnlyList<CorpusFile> files);
IEnumerable<ITextCorpus> CreateTermCorpora(IReadOnlyList<CorpusFile> files, string? languageCode = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ protected override async Task DoWorkAsync(
CancellationToken cancellationToken
)
{
TranslationEngine? engine = await Engines.GetAsync(e => e.EngineId == engineId, cancellationToken);
if (engine is null)
throw new OperationCanceledException($"Engine {engineId} does not exist. Build canceled.");

bool sourceTagInBaseModel = ResolveLanguageCodeForBaseModel(engine.SourceLanguage, out string srcLang);
bool targetTagInBaseModel = ResolveLanguageCodeForBaseModel(engine.TargetLanguage, out string trgLang);

(int trainCount, int pretranslateCount) = await WriteDataFilesAsync(
buildId,
data,
buildOptions,
(engine.SourceLanguage, engine.TargetLanguage),
cancellationToken
);

// Log summary of build data
JsonObject buildPreprocessSummary =
new()
Expand All @@ -65,16 +72,10 @@ CancellationToken cancellationToken
{ "EngineId", engineId },
{ "BuildId", buildId },
{ "NumTrainRows", trainCount },
{ "NumPretranslateRows", pretranslateCount }
{ "NumPretranslateRows", pretranslateCount },
{ "SourceLanguageResolved", srcLang },
{ "TargetLanguageResolved", trgLang }
};
TranslationEngine? engine = await Engines.GetAsync(e => e.EngineId == engineId, cancellationToken);
if (engine is null)
throw new OperationCanceledException($"Engine {engineId} does not exist. Build canceled.");

bool sourceTagInBaseModel = ResolveLanguageCodeForBaseModel(engine.SourceLanguage, out string srcLang);
buildPreprocessSummary.Add("SourceLanguageResolved", srcLang);
bool targetTagInBaseModel = ResolveLanguageCodeForBaseModel(engine.TargetLanguage, out string trgLang);
buildPreprocessSummary.Add("TargetLanguageResolved", trgLang);
Logger.LogInformation("{summary}", buildPreprocessSummary.ToJsonString());

if (trainCount == 0 && (!sourceTagInBaseModel || !targetTagInBaseModel))
Expand Down Expand Up @@ -105,6 +106,7 @@ CancellationToken cancellationToken
string buildId,
IReadOnlyList<Corpus> corpora,
string? buildOptions,
(string, string) languageCodes,
CancellationToken cancellationToken
)
{
Expand Down Expand Up @@ -164,8 +166,13 @@ CancellationToken cancellationToken

if ((bool?)buildOptionsObject?["use_key_terms"] ?? true)
{
ITextCorpus? sourceTermCorpus = _corpusService.CreateTermCorpora(corpus.SourceFiles).FirstOrDefault();
ITextCorpus? targetTermCorpus = _corpusService.CreateTermCorpora(corpus.TargetFiles).FirstOrDefault();
(string sourceLanguageCode, string targetLanguageCode) = languageCodes;
ITextCorpus? sourceTermCorpus = _corpusService
.CreateTermCorpora(corpus.SourceFiles, sourceLanguageCode)
.FirstOrDefault();
ITextCorpus? targetTermCorpus = _corpusService
.CreateTermCorpora(corpus.TargetFiles, targetLanguageCode)
.FirstOrDefault();
if (sourceTermCorpus is not null && targetTermCorpus is not null)
{
IParallelTextCorpus parallelKeyTermsCorpus = sourceTermCorpus.AlignRows(targetTermCorpus);
Expand Down
Loading