public double GetAlignmentProbability(int sourceLen, int prevSourceIndex, int sourceIndex, int targetLen, int prevTargetIndex, int targetIndex) { double alignProb = _directWordAlignmentModel.GetAlignmentProbability(sourceLen, prevSourceIndex, sourceIndex, targetLen, prevTargetIndex, targetIndex); double invAlignProb = _inverseWordAlignmentModel.GetAlignmentProbability(targetLen, prevTargetIndex, targetIndex, sourceLen, prevSourceIndex, sourceIndex); return(Math.Max(alignProb, invAlignProb)); }
public IEnumerable <AlignedWordPair> GetAlignedWordPairs(IWordAlignmentModel model, IReadOnlyList <string> sourceSegment, IReadOnlyList <string> targetSegment) { foreach (AlignedWordPair wordPair in GetAlignedWordPairs(out IReadOnlyList <int> sourceIndices, out IReadOnlyList <int> targetIndices)) { string sourceWord = sourceSegment[wordPair.SourceIndex]; string targetWord = targetSegment[wordPair.TargetIndex]; wordPair.TranslationProbability = model.GetTranslationProbability(sourceWord, targetWord); int prevSourceIndex = wordPair.TargetIndex == 0 ? -1 : sourceIndices[wordPair.TargetIndex - 1]; int prevTargetIndex = wordPair.SourceIndex == 0 ? -1 : targetIndices[wordPair.SourceIndex - 1]; wordPair.AlignmentProbability = model.GetAlignmentProbability(sourceSegment.Count, prevSourceIndex, wordPair.SourceIndex, targetSegment.Count, prevTargetIndex, wordPair.TargetIndex); yield return(wordPair); } }