/** * Backtraces through the penalty table. This starts at the "lower right" corner (i.e., the last word of the longer * of the reference vs. hypothesis strings) and works its way backwards. * * @param backtraceTable created from call to createBacktraceTable * @return a linked list of Integers representing the backtrace */ LinkedList <Integer> Backtrace(int[,] backtraceTable) { var list = new LinkedList <Integer>(); var i = _referenceItems.Count; var j = _hypothesisItems.Count; while ((i >= 0) && (j >= 0)) { Java.Add(list, backtraceTable[i, j]); switch (backtraceTable[i, j]) { case Ok: i--; j--; break; case Substitution: i--; j--; _substitutions++; break; case Insertion: j--; _insertions++; break; case Deletion: i--; _deletions++; break; } } return(list); }
/// <summary> /// Puts the probability into the map. /// </summary> /// <param name="wordSequence">The tag for the prob.</param> /// <param name="logProb">The probability in log math base.</param> /// <param name="logBackoff">The backoff probability in log math base.</param> private void Put(WordSequence wordSequence, float logProb, float logBackoff) { // System.out.println("Putting " + wordSequence + " p " + logProb // + " b " + logBackoff); Java.Put(_map, wordSequence, new Probability(logProb, logBackoff)); Java.Add(_tokens, wordSequence); }
public void add(Node n) { if (n.getBeginTime() < startTime) { startTime = n.getBeginTime(); } if (n.getEndTime() > endTime) { endTime = n.getEndTime(); } Java.Add(elements, n); }
/** * Form a subcluster by extracting all nodes corresponding to a given word. * * @param cluster the parent cluster * @param word the word to cluster by * @return the subcluster. */ protected LinkedList <Node> makeWordSubCluster(LinkedList <Node> cluster, String word) { var sub = new LinkedList <Node>(); foreach (Node n in cluster) { if (n.getWord().getSpelling().Equals(word)) { Java.Add(sub, n); } } return(sub); }
/** * 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); } }
public Cluster(Node n) { startTime = n.getBeginTime(); endTime = n.getEndTime(); Java.Add(elements, n); }
private static void AddInterfaces(Type[] interfaces, Java.Util.ISet<Type> ret, Java.Util.IQueue<Type> toVisit) { foreach (var i in interfaces) { if (i == typeof(IGenericTypeDefinition)) continue; // hide this marker interface. if (!ret.Contains(i)) { ret.Add(i); toVisit.Add(i); } } }