Skip to content

Commit

Permalink
Add word alignment to hybrid engine
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Nov 5, 2024
1 parent 16fb76d commit 08a2719
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions src/SIL.Machine/Translation/HybridTranslationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,49 @@ public void TrainSegment(
InteractiveEngine.TrainSegment(sourceSegment, targetSegment, sentenceStart);
}

public TranslationResult GetBestPhraseAlignment(
IReadOnlyList<string> sourceSegment,
IReadOnlyList<string> targetSegment
)
{
CheckDisposed();

return InteractiveEngine.GetBestPhraseAlignment(sourceSegment, targetSegment);
}

public TranslationResult GetBestPhraseAlignment(string sourceSegment, string targetSegment)
{
CheckDisposed();

return InteractiveEngine.GetBestPhraseAlignment(sourceSegment, targetSegment);
}

async Task<TranslationResult> IWordAlignerEngine.GetBestPhraseAlignmentAsync(
string sourceSegment,
string targetSegment,
CancellationToken cancellationToken
)
{
CheckDisposed();

return await InteractiveEngine
.GetBestPhraseAlignmentAsync(sourceSegment, targetSegment, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TranslationResult> GetBestPhraseAlignmentAsync(
IReadOnlyList<string> sourceSegment,
IReadOnlyList<string> targetSegment,
CancellationToken cancellationToken = default
)
{
CheckDisposed();

return await InteractiveEngine
.GetBestPhraseAlignmentAsync(sourceSegment, targetSegment, cancellationToken)
.ConfigureAwait(false);
}

private TranslationResult Merge(TranslationResult interactiveResult, TranslationResult ruleResult)
{
var mergedTargetSegment = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SIL.Machine.Translation
{
public interface IInteractiveTranslationEngine : ITranslationEngine
public interface IInteractiveTranslationEngine : ITranslationEngine, IWordAlignerEngine
{
Task<WordGraph> GetWordGraphAsync(string segment, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SIL.Machine.Translation
{
public interface IInteractiveTranslationModel : IInteractiveTranslationEngine, IWordAlignerEngine, ITranslationModel
public interface IInteractiveTranslationModel : IInteractiveTranslationEngine, ITranslationModel
{
Task SaveAsync(CancellationToken cancellationToken = default);
void Save();
Expand Down

0 comments on commit 08a2719

Please sign in to comment.