-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9720b46
commit 7d3b138
Showing
4 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIL.Machine.Translation | ||
{ | ||
public interface IWordAlignmentEngine : IWordAligner, IDisposable | ||
{ | ||
Task<WordAlignmentResult> GetBestAlignmentAsync( | ||
string sourceSegment, | ||
string targetSegment, | ||
CancellationToken cancellationToken = default | ||
); | ||
|
||
Task<WordAlignmentResult> GetBestAlignmentAsync( | ||
IReadOnlyList<string> sourceSegment, | ||
IReadOnlyList<string> targetSegment, | ||
CancellationToken cancellationToken = default | ||
); | ||
|
||
WordAlignmentResult GetBestAlignment(string sourceSegment, string targetSegment); | ||
|
||
WordAlignmentResult GetBestAlignment(IReadOnlyList<string> sourceSegment, IReadOnlyList<string> targetSegment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,9 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SIL.Machine.Corpora; | ||
using SIL.ObjectModel; | ||
using SIL.Machine.Corpora; | ||
|
||
namespace SIL.Machine.Translation | ||
{ | ||
public interface IWordAlignmentModel : IWordAligner, IDisposable | ||
public interface IWordAlignmentModel : IWordAlignmentEngine | ||
{ | ||
IWordVocabulary SourceWords { get; } | ||
IWordVocabulary TargetWords { get; } | ||
IReadOnlySet<int> SpecialSymbolIndices { get; } | ||
|
||
ITrainer CreateTrainer(IParallelTextCorpus corpus); | ||
|
||
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SIL.Machine.Translation | ||
{ | ||
public class WordAlignmentResult | ||
{ | ||
public WordAlignmentResult( | ||
IEnumerable<string> sourceTokens, | ||
IEnumerable<string> targetTokens, | ||
IEnumerable<double> confidences, | ||
WordAlignmentMatrix alignment | ||
) | ||
{ | ||
SourceTokens = sourceTokens.ToArray(); | ||
TargetTokens = targetTokens.ToArray(); | ||
Confidences = confidences.ToArray(); | ||
if (Confidences.Count != TargetTokens.Count) | ||
{ | ||
throw new ArgumentException( | ||
"The confidences must be the same length as the target segment.", | ||
nameof(confidences) | ||
); | ||
} | ||
Alignment = alignment; | ||
if (Alignment.RowCount != SourceTokens.Count) | ||
{ | ||
throw new ArgumentException( | ||
"The alignment source length must be the same length as the source segment.", | ||
nameof(alignment) | ||
); | ||
} | ||
if (Alignment.ColumnCount != TargetTokens.Count) | ||
{ | ||
throw new ArgumentException( | ||
"The alignment target length must be the same length as the target segment.", | ||
nameof(alignment) | ||
); | ||
} | ||
} | ||
|
||
public IReadOnlyList<string> SourceTokens { get; } | ||
public IReadOnlyList<string> TargetTokens { get; } | ||
public IReadOnlyList<double> Confidences { get; } | ||
public WordAlignmentMatrix Alignment { get; } | ||
} | ||
} |