Ejemplo n.º 1
0
        private static void MergeIdenticalTransitions(ArcList arcs, List <Arc> identicalWords)
        {
            List <List <Arc> > list = null;
            Arc arc = arcs.First;

            foreach (Arc arc2 in arcs)
            {
                if (Arc.CompareContent(arc, arc2) != 0)
                {
                    if (identicalWords.Count >= 2)
                    {
                        identicalWords.Sort(Arc.CompareIdenticalTransitions);
                        if (list == null)
                        {
                            list = new List <List <Arc> >();
                        }
                        list.Add(new List <Arc>(identicalWords));
                    }
                    identicalWords.Clear();
                }
                arc = arc2;
                identicalWords.Add(arc2);
            }
            if (identicalWords.Count >= 2)
            {
                MergeIdenticalTransitions(identicalWords);
            }
            identicalWords.Clear();
            if (list != null)
            {
                foreach (List <Arc> item in list)
                {
                    MergeIdenticalTransitions(item);
                }
            }
        }
Ejemplo n.º 2
0
        private void MergeDuplicateOutputTransitions(ArcList arcs, Stack <State> mergeStates)
        {
            List <Arc> list = null;
            Arc        arc  = null;
            bool       flag = false;

            foreach (Arc arc5 in arcs)
            {
                bool flag2 = arc5.End == null || !arc5.End.InArcs.CountIsOne;
                if (arc != null && Arc.CompareContent(arc5, arc) == 0)
                {
                    if (!flag2)
                    {
                        if (list == null)
                        {
                            list = new List <Arc>();
                        }
                        if (!flag)
                        {
                            list.Add(arc);
                            flag = true;
                        }
                        list.Add(arc5);
                    }
                }
                else
                {
                    arc  = (flag2 ? null : arc5);
                    flag = false;
                }
            }
            if (list != null)
            {
                list.Sort(Arc.CompareForDuplicateOutputTransitions);
                arc = null;
                Arc   arc3  = null;
                State state = null;
                bool  flag3 = false;
                foreach (Arc item in list)
                {
                    if (arc == null || Arc.CompareContent(item, arc) != 0)
                    {
                        arc = item;
                        if (flag3)
                        {
                            AddToMergeStateList(mergeStates, state);
                        }
                        arc3  = null;
                        state = null;
                        flag3 = false;
                    }
                    Arc   arc4 = item;
                    State end  = arc4.End;
                    if (end != end.Rule._firstState && MoveSemanticTagRight(arc4))
                    {
                        if (arc3 != null)
                        {
                            if (!flag3)
                            {
                                foreach (Arc outArc in state.OutArcs)
                                {
                                    outArc.Weight *= arc3.Weight;
                                }
                                flag3 = true;
                            }
                            foreach (Arc outArc2 in end.OutArcs)
                            {
                                outArc2.Weight *= arc4.Weight;
                            }
                            arc4.Weight += arc3.Weight;
                            Arc.CopyTags(arc3, arc4, Direction.Right);
                            DeleteTransition(arc3);
                            MoveOutputTransitionsAndDeleteState(state, end);
                        }
                        arc3  = arc4;
                        state = end;
                    }
                }
                if (flag3)
                {
                    AddToMergeStateList(mergeStates, state);
                }
            }
        }