/** * Based on the backtrace information, words are aligned as appropriate with insertions and deletions causing * asterisks to be placed in the word lists. This generates the alignedReferenceWords and alignedHypothesisWords * lists. * * @param backtrace the backtrace list created in backtrace */ void AlignWords(LinkedList <Integer> backtrace, IStringRenderer renderer) { var referenceWordsIterator = _referenceItems.GetEnumerator(); var hypothesisWordsIterator = _hypothesisItems.GetEnumerator(); string referenceWord; string hypothesisWord; Object a = null; Object b = null; _alignedReferenceWords = new LinkedList <string>(); _alignedHypothesisWords = new LinkedList <string>(); for (var m = backtrace.Count - 2; m >= 0; m--) { int backtraceEntry = backtrace.ElementAt(m); if (backtraceEntry != Insertion) { referenceWordsIterator.MoveNext(); a = referenceWordsIterator.Current; referenceWord = renderer.GetRef(a, b); } else { referenceWord = null; } if (backtraceEntry != Deletion) { hypothesisWordsIterator.MoveNext(); b = hypothesisWordsIterator.Current; hypothesisWord = renderer.GetHyp(a, b); } else { hypothesisWord = null; } switch (backtraceEntry) { case Substitution: { referenceWord = referenceWord.ToUpper(); hypothesisWord = hypothesisWord.ToUpper(); break; } case Insertion: { hypothesisWord = hypothesisWord.ToUpper(); break; } case Deletion: { referenceWord = referenceWord.ToUpper(); break; } case Ok: break; } // Expand the missing words out to be all *'s. // if (referenceWord == null) { referenceWord = Stars.Substring(0, hypothesisWord.Length); } if (hypothesisWord == null) { hypothesisWord = Stars.Substring(0, referenceWord.Length); } // Fill the words up with spaces so they are the same // Length. // if (referenceWord.Length > hypothesisWord.Length) { hypothesisWord = hypothesisWord + (Spaces.Substring(0, referenceWord.Length - hypothesisWord.Length)); } else if (referenceWord.Length < hypothesisWord.Length) { referenceWord = referenceWord + (Spaces.Substring(0, hypothesisWord.Length - referenceWord.Length)); } Java.Add(_alignedReferenceWords, referenceWord); Java.Add(_alignedHypothesisWords, hypothesisWord); } }