Ejemplo n.º 1
0
        private static void MergeIdenticalTransitions(List <Arc> identicalWords)
        {
            Collection <Arc> collection = null;
            Arc arc = null;

            foreach (Arc identicalWord in identicalWords)
            {
                if (arc != null && Arc.CompareIdenticalTransitions(arc, identicalWord) == 0)
                {
                    identicalWord.Weight += arc.Weight;
                    arc.ClearTags();
                    if (collection == null)
                    {
                        collection = new Collection <Arc>();
                    }
                    collection.Add(arc);
                }
                arc = identicalWord;
            }
            if (collection != null)
            {
                foreach (Arc item in collection)
                {
                    DeleteTransition(item);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Description:
        ///    Merge identical transitions with identical content, StartState, and EndState.
        ///
        /// Algorithm:
        /// - LastArc = Arcs[0]
        /// - For each Arc in Arcs[1-],
        ///   - If Arc is identical to LastArc,
        ///   - LastArc.Weight += Arc.Weight
        ///   - Delete Arc
        ///   - Else LastArc = Arc
        ///
        /// Moving SemanticTag:
        /// - Identical transitions have identical semantic tags.  Currently impossible to have identical
        /// non-null tags.
        /// - MoveSemanticTagReferences(DuplicateArc, CommonArc)
        /// </summary>
        private static void MergeIdenticalTransitions(List <Arc> identicalWords)
        {
            Collection <Arc> arcsToDelete = null;
            Arc refArc = null;

            foreach (Arc arc in identicalWords)
            {
                if (refArc != null && Arc.CompareIdenticalTransitions(refArc, arc) == 0)
                {
                    // Identical transition
                    arc.Weight += refArc.Weight;
                    refArc.ClearTags();
                    if (arcsToDelete == null)
                    {
                        // delay the creation of the collection as this operation in infrequent.
                        arcsToDelete = new Collection <Arc>();
                    }
                    arcsToDelete.Add(refArc);
                }
                refArc = arc;
            }
            if (arcsToDelete != null)
            {
                foreach (Arc arc in arcsToDelete)
                {
                    // arc will become an orphan
                    DeleteTransition(arc);
                }
            }
        }