Skip to content

Commit

Permalink
Remove IWordAlignmentEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Feb 10, 2025
1 parent d46b467 commit 92e62ca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 59 deletions.
30 changes: 0 additions & 30 deletions src/SIL.Machine/Translation/IWordAlignmentEngine.cs

This file was deleted.

29 changes: 24 additions & 5 deletions src/SIL.Machine/Translation/IWordAlignmentModel.cs
Original file line number Diff line number Diff line change
@@ -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<int> 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<AlignedWordPair> GetBestAlignedWordPairs(
IReadOnlyList<string> sourceSegment,
IReadOnlyList<string> targetSegment
);
void ComputeAlignedWordPairScores(
IReadOnlyList<string> sourceSegment,
IReadOnlyList<string> targetSegment,
IReadOnlyCollection<AlignedWordPair> wordPairs
);
}
}
14 changes: 7 additions & 7 deletions src/SIL.Machine/Translation/SymmetrizedWordAlignmentEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +28,7 @@ public SymmetrizationHeuristic Heuristic
set => _aligner.Heuristic = value;
}

public IWordAlignmentEngine DirectWordAlignmentEngine
public IWordAligner DirectWordAlignmentEngine
{
get
{
Expand All @@ -38,7 +38,7 @@ public IWordAlignmentEngine DirectWordAlignmentEngine
}
}

public IWordAlignmentEngine InverseWordAlignmentEngine
public IWordAligner InverseWordAlignmentEngine
{
get
{
Expand Down
18 changes: 1 addition & 17 deletions src/SIL.Machine/Translation/SymmetrizedWordAlignmentModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using SIL.Machine.Corpora;
using SIL.Machine.Corpora;

namespace SIL.Machine.Translation
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 92e62ca

Please sign in to comment.