Skip to content

Commit

Permalink
SF-2900 Mixed Source: Selecting books from each source (#2825)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman authored Dec 16, 2024
1 parent 3f93008 commit 86eaa35
Show file tree
Hide file tree
Showing 42 changed files with 5,227 additions and 3,313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ServalBuildAdditionalInfo {
buildId: string;
corporaIds?: string[];
dateFinished?: string;
parallelCorporaIds?: string[];
step: number;
translationEngineId: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ describe('DraftGenerationStepsComponent', () => {
fixture.detectChanges();

expect(component.done.emit).toHaveBeenCalledWith({
translationBooks,
trainingDataFiles,
trainingBooks: trainingBooks.filter(book => !translationBooks.includes(book)),
trainingDataFiles,
trainingScriptureRanges: [],
translationBooks,
translationScriptureRanges: [],
fastTraining: false
} as DraftGenerationStepsResult);
expect(component.isStepsCompleted).toBe(true);
Expand Down Expand Up @@ -402,7 +404,9 @@ describe('DraftGenerationStepsComponent', () => {
expect(component.done.emit).toHaveBeenCalledWith({
trainingBooks,
trainingDataFiles,
trainingScriptureRanges: [],
translationBooks,
translationScriptureRanges: [],
fastTraining: true
} as DraftGenerationStepsResult);
expect(generateDraftButton['disabled']).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { BookMultiSelectComponent } from '../../../shared/book-multi-select/book
import { SharedModule } from '../../../shared/shared.module';
import { NllbLanguageService } from '../../nllb-language.service';
import { ConfirmSourcesComponent } from '../confirm-sources/confirm-sources.component';
import { ProjectScriptureRange } from '../draft-generation';
import { DraftSource, DraftSourcesService } from '../draft-sources.service';
import { TrainingDataMultiSelectComponent } from '../training-data/training-data-multi-select.component';
import { TrainingDataUploadDialogComponent } from '../training-data/training-data-upload-dialog.component';
Expand All @@ -29,8 +30,10 @@ export interface DraftGenerationStepsResult {
trainingBooks: number[];
trainingDataFiles: string[];
trainingScriptureRange?: string;
trainingScriptureRanges: ProjectScriptureRange[];
translationBooks: number[];
translationScriptureRange?: string;
translationScriptureRanges: ProjectScriptureRange[];
fastTraining: boolean;
}

Expand Down Expand Up @@ -263,8 +266,10 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
this.isStepsCompleted = true;
this.done.emit({
trainingBooks: this.userSelectedTrainingBooks,
trainingScriptureRanges: [],
trainingDataFiles: this.selectedTrainingDataIds,
translationBooks: this.userSelectedTranslateBooks,
translationScriptureRanges: [],
fastTraining: this.fastTraining
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ <h1 class="mat-headline-4">
<strong>Corpora Ids:</strong>
{{ draftJob?.additionalInfo?.corporaIds?.join(", ") ?? "unknown" }}
</div>
<div>
<strong>Parallel Corpora Ids:</strong>
{{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") ?? "unknown" }}
</div>
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -1986,7 +1988,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
env.startedOrActiveBuild$.next(buildDto);
Expand All @@ -2003,7 +2007,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -2012,7 +2018,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
verify(mockDialogRef.getState()).never();
Expand All @@ -2028,7 +2036,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -2037,7 +2047,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
verify(mockDialogRef.getState()).never();
Expand All @@ -2053,7 +2065,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -2062,7 +2076,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
verify(mockDialogRef.getState()).never();
Expand All @@ -2079,7 +2095,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -2088,7 +2106,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
verify(mockDialogRef.close()).once();
Expand All @@ -2104,7 +2124,9 @@ describe('DraftGenerationComponent', () => {
env.component.startBuild({
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false,
projectId: projectId
});
Expand All @@ -2114,7 +2136,9 @@ describe('DraftGenerationComponent', () => {
projectId: projectId,
trainingBooks: [],
trainingDataFiles: [],
trainingScriptureRanges: [],
translationBooks: [],
translationScriptureRanges: [],
fastTraining: false
});
expect(mockAuthService.requestParatextCredentialUpdate).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,10 @@ export class DraftGenerationComponent extends DataLoadingComponent implements On
trainingBooks: result.trainingBooks,
trainingDataFiles: result.trainingDataFiles,
trainingScriptureRange: result.trainingScriptureRange,
trainingScriptureRanges: result.trainingScriptureRanges,
translationBooks: result.translationBooks,
translationScriptureRange: result.translationScriptureRange,
translationScriptureRanges: result.trainingScriptureRanges,
fastTraining: result.fastTraining
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe('DraftGenerationService', () => {
projectId,
trainingBooks: [],
trainingDataFiles: [],
translationScriptureRanges: [],
translationBooks: [],
trainingScriptureRanges: [],
fastTraining: false
};
const buildDto: BuildDto = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { InjectionToken } from '@angular/core';
import { BuildStates } from '../../machine-api/build-states';

/*
/**
* The build configuration for a pre-translation build.
*/
export interface BuildConfig {
projectId: string;
trainingBooks: number[];
trainingDataFiles: string[];
trainingScriptureRange?: string;
trainingScriptureRanges: ProjectScriptureRange[];
translationBooks: number[];
translationScriptureRange?: string;
translationScriptureRanges: ProjectScriptureRange[];
fastTraining: boolean;
}

/**
* A per-project scripture range.
*/
export interface ProjectScriptureRange {
projectId: string;
scriptureRange: string;
}

/**
* Dictionary of 'segmentRef -> segment text'.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@if (canShowAdditionalInfo) {
<div><strong>Build Id:</strong> {{ draftJob?.additionalInfo?.buildId }}</div>
<div><strong>Corpora Ids:</strong> {{ draftJob?.additionalInfo?.corporaIds?.join(", ") }}</div>
<div><strong>Parallel Corpora Ids:</strong> {{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") }}</div>
<div><strong>Date Finished:</strong> {{ draftJob?.additionalInfo?.dateFinished?.toLocaleString() }}</div>
<div><strong>Message:</strong> {{ draftJob?.message }}</div>
<div><strong>Percent Completed:</strong> {{ draftJob?.percentCompleted }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { TestRealtimeModule } from 'xforge-common/test-realtime.module';
import { configureTestingModule, TestTranslocoModule } from 'xforge-common/test-utils';
import { SFProjectProfileDoc } from '../../../core/models/sf-project-profile-doc';
import { SF_TYPE_REGISTRY } from '../../../core/models/sf-type-registry';
import { TextDocService } from '../../../core/text-doc.service';
import { SharedModule } from '../../../shared/shared.module';
import { EDITOR_READY_TIMEOUT } from '../../../shared/text/text.component';
import { DraftSegmentMap } from '../../draft-generation/draft-generation';
Expand All @@ -29,7 +28,6 @@ const mockActivatedProjectService = mock(ActivatedProjectService);
const mockDraftHandlingService = mock(DraftHandlingService);
const mockI18nService = mock(I18nService);
const mockDialogService = mock(DialogService);
const mockTextDocService = mock(TextDocService);

describe('EditorDraftComponent', () => {
let fixture: ComponentFixture<EditorDraftComponent>;
Expand All @@ -52,8 +50,7 @@ describe('EditorDraftComponent', () => {
{ provide: DraftHandlingService, useMock: mockDraftHandlingService },
{ provide: I18nService, useMock: mockI18nService },
{ provide: OnlineStatusService, useClass: TestOnlineStatusService },
{ provide: DialogService, useMock: mockDialogService },
{ provide: TextDocService, useMock: mockTextDocService }
{ provide: DialogService, useMock: mockDialogService }
]
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
"generate_draft_button": "Generate draft",
"generate_forward_translation_drafts_header": "Generate translation drafts",
"generate_new_draft": "New draft",
"go_to_draft_viewer": "Go to [link:draftViewerUrl]draft viewer[/link] to preview and apply the generated draft to chapters of your choice.",
"improved_learning_rate_notice": "Drafting is now much faster! Most drafts will now take about {1}{2} hours to complete instead of {3}{4}. Draft quality should be about the same as before, but please {5}contact us{6} if you notice any issues.",
"info_alert_different_additional_training_and_source_language": "The language for your additional training text ({{ additionalTrainingSourceLanguageDisplayName }}) must be the same as the training source language ({{ alternateTrainingSourceLanguageDisplayName }}). Select a different additional training text on the [link:projectSettingsUrl]settings page[/link].",
"info_alert_different_training_and_source_language": "The language for your alternate training text ({{ alternateTrainingSourceLanguageDisplayName }}) must be the same as the source language ({{ sourceLanguageDisplayName }}). Select a different alternate training text on the [link:projectSettingsUrl]settings page[/link].",
Expand Down
20 changes: 20 additions & 0 deletions src/SIL.XForge.Scripture/Models/BuildConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BuildConfig
/// </summary>
/// <value>The numbers of the books to use as the source texts for training.</value>
/// <remarks>
/// This property is for legacy client use.
/// You should not set this property and <see cref="TrainingScriptureRange"/> at the same time.
/// </remarks>
public HashSet<int> TrainingBooks { get; set; } = [];
Expand All @@ -34,16 +35,26 @@ public class BuildConfig
/// </summary>
/// <value>The book ids and chapter numbers separated by semicolons.</value>
/// <remarks>
/// This property is for legacy client use.
/// See https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range for syntax.
/// You should not set this property and <see cref="TrainingBooks"/> at the same time.
/// </remarks>
public string? TrainingScriptureRange { get; set; }

/// <summary>
/// Gets or sets the per-project books and chapters to use for training.
/// </summary>
/// <value>
/// A list containing the project identifiers and scripture ranges.
/// </value>
public HashSet<ProjectScriptureRange> TrainingScriptureRanges { get; set; } = [];

/// <summary>
/// Gets or sets the books to use for translation.
/// </summary>
/// <value>The numbers of the books to use as the source texts for training.</value>
/// <remarks>
/// This property is for legacy client use.
/// You should not set this property and <see cref="TranslationScriptureRange"/> at the same time.
/// </remarks>
public HashSet<int> TranslationBooks { get; set; } = [];
Expand All @@ -53,11 +64,20 @@ public class BuildConfig
/// </summary>
/// <value>The book ids and chapter numbers separated by semicolons.</value>
/// <remarks>
/// This property is for legacy client use.
/// See https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range for syntax.
/// You should not set this property and <see cref="TranslationBooks"/> at the same time.
/// </remarks>
public string? TranslationScriptureRange { get; set; }

/// <summary>
/// Gets or sets the per-project books and chapters to use for training.
/// </summary>
/// <value>
/// A list containing the project identifiers and scripture ranges.
/// </value>
public HashSet<ProjectScriptureRange> TranslationScriptureRanges { get; set; } = [];

/// <summary>
/// Gets or sets the project identifier.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/SIL.XForge.Scripture/Models/DraftConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class DraftConfig
public TranslateSource? AlternateTrainingSource { get; set; }
public IList<int> LastSelectedTrainingBooks { get; set; } = [];
public string? LastSelectedTrainingScriptureRange { get; set; }
public IList<ProjectScriptureRange> LastSelectedTrainingScriptureRanges { get; set; } = [];
public IList<string> LastSelectedTrainingDataFiles { get; set; } = [];
public IList<int> LastSelectedTranslationBooks { get; set; } = [];
public string? LastSelectedTranslationScriptureRange { get; set; }
public IList<ProjectScriptureRange> LastSelectedTranslationScriptureRanges { get; set; } = [];
public string? ServalConfig { get; set; }
}
1 change: 1 addition & 0 deletions src/SIL.XForge.Scripture/Models/MachineApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace SIL.XForge.Scripture.Models;
public static class MachineApi
{
public const string HttpClientName = "machine_api";
public const string TokenClientName = "machine_api_token";
public const string Namespace = "machine-api/v3";
public const string StartBuild = "translation/builds";
public const string GetBuild = "translation/builds/id:{sfProjectId}.{buildId?}";
Expand Down
22 changes: 22 additions & 0 deletions src/SIL.XForge.Scripture/Models/ProjectScriptureRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace SIL.XForge.Scripture.Models;

/// <summary>
/// A scripture range for a specific project.
/// This is used by <see cref="BuildConfig"/>.
/// </summary>
public record ProjectScriptureRange
{
/// <summary>
/// The project identifier.
/// </summary>
public string ProjectId { get; set; } = string.Empty;

/// <summary>
/// The scripture range.
/// </summary>
/// <value>The book ids and chapter numbers separated by semicolons.</value>
/// <remarks>
/// See https://github.com/sillsdev/serval/wiki/Filtering-Paratext-Project-Data-with-a-Scripture-Range for syntax.
/// </remarks>
public string ScriptureRange { get; set; } = string.Empty;
}
Loading

0 comments on commit 86eaa35

Please sign in to comment.