Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word alignment try 2 #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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
29 changes: 29 additions & 0 deletions src/SIL.Machine/Translation/IWordAlignerEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace SIL.Machine.Translation
{
public interface IWordAlignerEngine : IDisposable
{
Task<TranslationResult> GetBestPhraseAlignmentAsync(
string sourceSegment,
string targetSegment,
CancellationToken cancellationToken = default
);

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

TranslationResult GetBestPhraseAlignment(string sourceSegment, string targetSegment);

TranslationResult GetBestPhraseAlignment(
IReadOnlyList<string> sourceSegment,
IReadOnlyList<string> targetSegment
);
}
}
Loading