Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,6 +1,5 @@
import { ProjectScriptureRange } from 'realtime-server/lib/esm/scriptureforge/models/translate-config';
import { BuildStates } from './build-states';
import { QuotationAnalysis } from './quotation-denormalization';
import { ResourceDto } from './resource-dto';

export interface BuildDto extends ResourceDto {
Expand All @@ -26,5 +25,5 @@ export interface ServalBuildAdditionalInfo {
translationScriptureRanges: ProjectScriptureRange[];
trainingDataFileIds: string[];
requestedByUserId?: string;
quotationDenormalization: QuotationAnalysis;
canDenormalizeQuotes: boolean;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { SF_TYPE_REGISTRY } from '../../../core/models/sf-type-registry';
import { SFProjectService } from '../../../core/sf-project.service';
import { BuildDto } from '../../../machine-api/build-dto';
import { BuildStates } from '../../../machine-api/build-states';
import { QuotationAnalysis } from '../../../machine-api/quotation-denormalization';
import { ServalAdministrationService } from '../../../serval-administration/serval-administration.service';
import { provideQuillRegistrations } from '../../../shared/text/quill-editor-registration/quill-providers';
import { EDITOR_READY_TIMEOUT } from '../../../shared/text/text.component';
Expand Down Expand Up @@ -184,7 +183,7 @@ describe('DraftUsfmFormatComponent', () => {
}));

it('should initialize and default to best guess and automatic quotes', fakeAsync(async () => {
const env = new TestEnvironment({ quotationAnalysis: QuotationAnalysis.Successful });
const env = new TestEnvironment({ canDenormalizeQuotes: true });
expect(env.component.paragraphFormat.value).toBe(ParagraphBreakFormat.BestGuess);
expect(env.component.quoteFormat.value).toBe(QuoteFormat.Denormalized);
expect(await env.component.confirmLeave()).toBe(true);
Expand Down Expand Up @@ -278,7 +277,7 @@ describe('DraftUsfmFormatComponent', () => {
}));

it('shows a notice if unable to detect the quote convention for the project', fakeAsync(() => {
const env = new TestEnvironment({ quotationAnalysis: QuotationAnalysis.Unsuccessful });
const env = new TestEnvironment({ canDenormalizeQuotes: false });
expect(env.quoteFormatWarning).not.toBeNull();
}));
});
Expand All @@ -290,11 +289,11 @@ class TestEnvironment {
readonly projectId = 'project01';
onlineStatusService: TestOnlineStatusService;

constructor(args: { project?: Partial<SFProjectProfile>; quotationAnalysis?: QuotationAnalysis } = {}) {
constructor(args: { project?: Partial<SFProjectProfile>; canDenormalizeQuotes?: boolean } = {}) {
const userDoc = mock(UserDoc);
this.onlineStatusService = TestBed.inject(OnlineStatusService) as TestOnlineStatusService;
when(mockedDraftGenerationService.getLastCompletedBuild(anything())).thenReturn(
of(this.getTestBuildDto(args.quotationAnalysis ?? QuotationAnalysis.Successful))
of(this.getTestBuildDto(args.canDenormalizeQuotes ?? true))
);
when(mockedUserService.getCurrentUser()).thenResolve(userDoc);
when(mockedDraftHandlingService.getDraft(anything(), anything())).thenReturn(
Expand Down Expand Up @@ -369,7 +368,7 @@ class TestEnvironment {
when(mockedActivatedProjectService.projectDoc).thenReturn(projectDoc);
}

private getTestBuildDto(quotationAnalysis: QuotationAnalysis): BuildDto {
private getTestBuildDto(canDenormalizeQuotes: boolean): BuildDto {
return {
id: 'build01',
state: BuildStates.Completed,
Expand All @@ -387,7 +386,7 @@ class TestEnvironment {
translationScriptureRanges: [{ projectId: 'source01', scriptureRange: 'EXO' }],
trainingScriptureRanges: [{ projectId: 'source01', scriptureRange: 'GEN' }],
trainingDataFileIds: [] as string[],
quotationDenormalization: quotationAnalysis
canDenormalizeQuotes
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { OnlineStatusService } from 'xforge-common/online-status.service';
import { filterNullish, quietTakeUntilDestroyed } from 'xforge-common/util/rxjs-util';
import { TextDocId } from '../../../core/models/text-doc';
import { SFProjectService } from '../../../core/sf-project.service';
import { QuotationAnalysis } from '../../../machine-api/quotation-denormalization';
import { ServalAdministrationService } from '../../../serval-administration/serval-administration.service';
import { BookChapterChooserComponent } from '../../../shared/book-chapter-chooser/book-chapter-chooser.component';
import { NoticeComponent } from '../../../shared/notice/notice.component';
Expand Down Expand Up @@ -79,7 +78,7 @@ export class DraftUsfmFormatComponent extends DataLoadingComponent implements Af

private updateDraftConfig$: Subject<DraftUsfmConfig | undefined> = new Subject<DraftUsfmConfig | undefined>();
private lastSavedState?: DraftUsfmConfig;
private quotationDenormalization: QuotationAnalysis = QuotationAnalysis.Successful;
private canDenormalizeQuotes?: boolean = undefined;

constructor(
private readonly activatedRoute: ActivatedRoute,
Expand All @@ -100,10 +99,7 @@ export class DraftUsfmFormatComponent extends DataLoadingComponent implements Af
.pipe(filterNullish(), first(), quietTakeUntilDestroyed(this.destroyRef))
.subscribe(async projectId => {
const currentBuild = await firstValueFrom(this.draftGenerationService.getLastCompletedBuild(projectId));
this.quotationDenormalization =
currentBuild?.additionalInfo?.quotationDenormalization === QuotationAnalysis.Successful
? QuotationAnalysis.Successful
: QuotationAnalysis.Unsuccessful;
this.canDenormalizeQuotes = currentBuild?.additionalInfo?.canDenormalizeQuotes;
});
}

Expand All @@ -125,7 +121,7 @@ export class DraftUsfmFormatComponent extends DataLoadingComponent implements Af
}

get showQuoteFormatWarning(): boolean {
return this.quotationDenormalization !== QuotationAnalysis.Successful;
return this.canDenormalizeQuotes === false;
}

private get currentFormat(): DraftUsfmConfig | undefined {
Expand Down
13 changes: 1 addition & 12 deletions src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SIL.Converters.Usj;

namespace SIL.XForge.Scripture.Models;

Expand All @@ -20,13 +17,5 @@ public class ServalBuildAdditionalInfo
public HashSet<string> TrainingDataFileIds { get; init; } = [];
public string TranslationEngineId { get; init; } = string.Empty;
public HashSet<ProjectScriptureRange> TranslationScriptureRanges { get; init; } = [];

[JsonConverter(typeof(StringEnumConverter), typeof(LowerCaseNamingStrategy))]
public QuotationAnalysis QuotationDenormalization { get; set; } = QuotationAnalysis.Unsuccessful;
}

public enum QuotationAnalysis
{
Successful,
Unsuccessful,
public bool CanDenormalizeQuotes { get; set; } = false;
}
13 changes: 3 additions & 10 deletions src/SIL.XForge.Scripture/Services/MachineApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ string bookId in ScriptureRangeParser
private static ServalBuildDto CreateDto(TranslationBuild translationBuild)
{
string? parallelCorpusId = translationBuild.Pretranslate?.FirstOrDefault()?.ParallelCorpus?.Id;
var matchingCorpus = translationBuild.Analysis?.FirstOrDefault(a => a.ParallelCorpusRef == parallelCorpusId);

var buildDto = new ServalBuildDto
{
Id = translationBuild.Id,
Expand Down Expand Up @@ -2285,16 +2287,7 @@ .. translationBuild
.Where(id => !string.IsNullOrEmpty(id)) ?? [],
]
),
QuotationDenormalization =
parallelCorpusId is not null
&& translationBuild.Analysis?.FirstOrDefault(a =>
a.ParallelCorpusRef == parallelCorpusId
&& !string.IsNullOrEmpty(a.SourceQuoteConvention)
&& !string.IsNullOrEmpty(a.TargetQuoteConvention)
)
is not null
? QuotationAnalysis.Successful
: QuotationAnalysis.Unsuccessful,
CanDenormalizeQuotes = matchingCorpus?.CanDenormalizeQuotes == true,
DateFinished = translationBuild.DateFinished,
Step = translationBuild.Step,
TranslationEngineId = translationBuild.Engine.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,9 @@
new ParallelCorpusAnalysis
{
ParallelCorpusRef = parallelCorpusId1,
SourceQuoteConvention = "standard_english",

Check warning on line 990 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 990 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 990 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Production build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 990 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 990 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete
TargetQuoteConvention = "standard_english",
CanDenormalizeQuotes = true,
},
],
};
Expand Down Expand Up @@ -1027,7 +1028,7 @@
Assert.AreEqual(parallelCorpusId1, actual.AdditionalInfo.ParallelCorporaIds!.ElementAt(0));
Assert.AreEqual(parallelCorpusId2, actual.AdditionalInfo.ParallelCorporaIds.ElementAt(1));
Assert.AreEqual(TrainingDataId01, actual.AdditionalInfo.TrainingDataFileIds.Single());
Assert.AreEqual(actual.AdditionalInfo.QuotationDenormalization, QuotationAnalysis.Successful);
Assert.That(actual.AdditionalInfo.CanDenormalizeQuotes, Is.True);
}

[Test]
Expand Down Expand Up @@ -1272,8 +1273,9 @@
new ParallelCorpusAnalysis
{
ParallelCorpusRef = ParallelCorpusId01,
SourceQuoteConvention = "standard_english",

Check warning on line 1276 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 1276 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 1276 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Production build and test (ubuntu-22.04, 8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 1276 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete

Check warning on line 1276 in test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (8.0.x, 22.13.0, 10.9.2)

'ParallelCorpusAnalysis.SourceQuoteConvention' is obsolete
TargetQuoteConvention = "standard_english",
CanDenormalizeQuotes = true,
},
];
translationBuild.Pretranslate =
Expand Down Expand Up @@ -1361,7 +1363,7 @@
builds[0].AdditionalInfo.TrainingScriptureRanges.Single().ScriptureRange
);
Assert.AreEqual(TrainingDataId01, builds[0].AdditionalInfo.TrainingDataFileIds.Single());
Assert.AreEqual(builds[0].AdditionalInfo!.QuotationDenormalization, QuotationAnalysis.Successful);
Assert.That(builds[0].AdditionalInfo.CanDenormalizeQuotes, Is.True);
}

[Test]
Expand Down Expand Up @@ -1403,7 +1405,7 @@
trainingScriptureRange,
builds[0].AdditionalInfo?.TrainingScriptureRanges.Single().ScriptureRange
);
Assert.AreEqual(builds[0].AdditionalInfo!.QuotationDenormalization, QuotationAnalysis.Unsuccessful);
Assert.That(builds[0].AdditionalInfo!.CanDenormalizeQuotes, Is.False);
}

[Test]
Expand Down Expand Up @@ -1455,7 +1457,7 @@
trainingScriptureRange,
builds[0].AdditionalInfo?.TrainingScriptureRanges.Single().ScriptureRange
);
Assert.AreEqual(builds[0].AdditionalInfo!.QuotationDenormalization, QuotationAnalysis.Unsuccessful);
Assert.That(builds[0].AdditionalInfo!.CanDenormalizeQuotes, Is.False);
}

[Test]
Expand Down
Loading