From 92e62ca719baa4f7f0506a5e383fe25181a20ccf Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Mon, 10 Feb 2025 09:57:56 -0500 Subject: [PATCH] Remove IWordAlignmentEngine --- .../Translation/IWordAlignmentEngine.cs | 30 ------------------- .../Translation/IWordAlignmentModel.cs | 29 ++++++++++++++---- .../SymmetrizedWordAlignmentEngine.cs | 14 ++++----- .../SymmetrizedWordAlignmentModel.cs | 18 +---------- 4 files changed, 32 insertions(+), 59 deletions(-) delete mode 100644 src/SIL.Machine/Translation/IWordAlignmentEngine.cs diff --git a/src/SIL.Machine/Translation/IWordAlignmentEngine.cs b/src/SIL.Machine/Translation/IWordAlignmentEngine.cs deleted file mode 100644 index b033bb9ff..000000000 --- a/src/SIL.Machine/Translation/IWordAlignmentEngine.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using SIL.Machine.Corpora; -using SIL.ObjectModel; - -namespace SIL.Machine.Translation -{ - public interface IWordAlignmentEngine : IWordAligner, IDisposable - { - IWordVocabulary SourceWords { get; } - IWordVocabulary TargetWords { get; } - IReadOnlySet SpecialSymbolIndices { get; } - - IEnumerable<(string TargetWord, double Score)> GetTranslations(string sourceWord, double threshold = 0); - IEnumerable<(int TargetWordIndex, double Score)> GetTranslations(int sourceWordIndex, double threshold = 0); - - double GetTranslationScore(string sourceWord, string targetWord); - double GetTranslationScore(int sourceWordIndex, int targetWordIndex); - - IReadOnlyCollection GetBestAlignedWordPairs( - IReadOnlyList sourceSegment, - IReadOnlyList targetSegment - ); - void ComputeAlignedWordPairScores( - IReadOnlyList sourceSegment, - IReadOnlyList targetSegment, - IReadOnlyCollection wordPairs - ); - } -} diff --git a/src/SIL.Machine/Translation/IWordAlignmentModel.cs b/src/SIL.Machine/Translation/IWordAlignmentModel.cs index ed5297a78..483f47d30 100644 --- a/src/SIL.Machine/Translation/IWordAlignmentModel.cs +++ b/src/SIL.Machine/Translation/IWordAlignmentModel.cs @@ -1,13 +1,32 @@ -using System.Threading; -using System.Threading.Tasks; +using System; +using System.Collections.Generic; using SIL.Machine.Corpora; +using SIL.ObjectModel; namespace SIL.Machine.Translation { - public interface IWordAlignmentModel : IWordAlignmentEngine + public interface IWordAlignmentModel : IWordAligner, IDisposable { + IWordVocabulary SourceWords { get; } + IWordVocabulary TargetWords { get; } + IReadOnlySet SpecialSymbolIndices { get; } + ITrainer CreateTrainer(IParallelTextCorpus corpus); - Task SaveAsync(CancellationToken cancellationToken = default); - void Save(); + + IEnumerable<(string TargetWord, double Score)> GetTranslations(string sourceWord, double threshold = 0); + IEnumerable<(int TargetWordIndex, double Score)> GetTranslations(int sourceWordIndex, double threshold = 0); + + double GetTranslationScore(string sourceWord, string targetWord); + double GetTranslationScore(int sourceWordIndex, int targetWordIndex); + + IReadOnlyCollection GetBestAlignedWordPairs( + IReadOnlyList sourceSegment, + IReadOnlyList targetSegment + ); + void ComputeAlignedWordPairScores( + IReadOnlyList sourceSegment, + IReadOnlyList targetSegment, + IReadOnlyCollection wordPairs + ); } } diff --git a/src/SIL.Machine/Translation/SymmetrizedWordAlignmentEngine.cs b/src/SIL.Machine/Translation/SymmetrizedWordAlignmentEngine.cs index 924d908b9..3591f30f1 100644 --- a/src/SIL.Machine/Translation/SymmetrizedWordAlignmentEngine.cs +++ b/src/SIL.Machine/Translation/SymmetrizedWordAlignmentEngine.cs @@ -6,15 +6,15 @@ namespace SIL.Machine.Translation { - public class SymmetrizedWordAlignmentEngine : DisposableBase, IWordAlignmentEngine + public class SymmetrizedWordAlignmentEngine : DisposableBase, IWordAligner { - private readonly IWordAlignmentEngine _directWordAlignmentEngine; - private readonly IWordAlignmentEngine _inverseWordAlignmentEngine; + private readonly IWordAlignmentModel _directWordAlignmentEngine; + private readonly IWordAlignmentModel _inverseWordAlignmentEngine; private readonly SymmetrizedWordAligner _aligner; public SymmetrizedWordAlignmentEngine( - IWordAlignmentEngine directWordAlignmentEngine, - IWordAlignmentEngine inverseWordAlignmentEngine + IWordAlignmentModel directWordAlignmentEngine, + IWordAlignmentModel inverseWordAlignmentEngine ) { _directWordAlignmentEngine = directWordAlignmentEngine; @@ -28,7 +28,7 @@ public SymmetrizationHeuristic Heuristic set => _aligner.Heuristic = value; } - public IWordAlignmentEngine DirectWordAlignmentEngine + public IWordAligner DirectWordAlignmentEngine { get { @@ -38,7 +38,7 @@ public IWordAlignmentEngine DirectWordAlignmentEngine } } - public IWordAlignmentEngine InverseWordAlignmentEngine + public IWordAligner InverseWordAlignmentEngine { get { diff --git a/src/SIL.Machine/Translation/SymmetrizedWordAlignmentModel.cs b/src/SIL.Machine/Translation/SymmetrizedWordAlignmentModel.cs index fe48d0b0d..a98e8e666 100644 --- a/src/SIL.Machine/Translation/SymmetrizedWordAlignmentModel.cs +++ b/src/SIL.Machine/Translation/SymmetrizedWordAlignmentModel.cs @@ -1,6 +1,4 @@ -using System.Threading; -using System.Threading.Tasks; -using SIL.Machine.Corpora; +using SIL.Machine.Corpora; namespace SIL.Machine.Translation { @@ -29,20 +27,6 @@ public ITrainer CreateTrainer(IParallelTextCorpus corpus) return new SymmetrizedWordAlignmentModelTrainer(directTrainer, inverseTrainer); } - public void Save() - { - CheckDisposed(); - _directWordAlignmentModel.Save(); - _inverseWordAlignmentModel.Save(); - } - - public async Task SaveAsync(CancellationToken cancellationToken = default) - { - CheckDisposed(); - await _directWordAlignmentModel.SaveAsync(cancellationToken); - await _inverseWordAlignmentModel.SaveAsync(cancellationToken); - } - protected override void DisposeManagedResources() { _directWordAlignmentModel.Dispose();