Example #1
0
 public void Remove()
 {
     lock (list.SyncRoot)
     {
         iterator.Remove();
     }
 }
        internal static bool ReorderIncorrectBinaryTransition(IList <ITransition> transitions)
        {
            int shiftCount = 0;
            IListIterator <ITransition> cursor = transitions.ListIterator();

            do
            {
                if (!cursor.MoveNext())
                {
                    return(false);
                }
                ITransition next = cursor.Current;
                if (next is ShiftTransition)
                {
                    ++shiftCount;
                }
                else
                {
                    if (next is BinaryTransition)
                    {
                        --shiftCount;
                        if (shiftCount <= 0)
                        {
                            cursor.Remove();
                        }
                    }
                }
            }while (shiftCount > 0);
            if (!cursor.MoveNext())
            {
                return(false);
            }
            ITransition next_1 = cursor.Current;

            while ((next_1 is UnaryTransition) || (next_1 is CompoundUnaryTransition))
            {
                cursor.Remove();
                if (!cursor.MoveNext())
                {
                    return(false);
                }
                next_1 = cursor.Current;
            }
            // At this point, the rest of the transition sequence should suffice
            return(true);
        }
        /// <summary>
        /// In this case, we are starting to build a new subtree when instead
        /// we should have been combining existing trees.
        /// </summary>
        /// <remarks>
        /// In this case, we are starting to build a new subtree when instead
        /// we should have been combining existing trees.  What we can do is
        /// find the transitions that build up the next subtree in the gold
        /// transition list, figure out how it gets applied to a
        /// BinaryTransition, and make that the next BinaryTransition we
        /// perform after finishing the subtree.  If there are multiple
        /// BinaryTransitions in a row, we ignore any associated
        /// UnaryTransitions (unfixable) and try to transition to the final
        /// state.  The assumption is that we can't do anything about the
        /// incorrect subtrees any more, so we skip them all.
        /// <br />
        /// Sadly, this does not seem to help - the parser gets worse when it
        /// learns these states
        /// </remarks>
        internal static bool ReorderIncorrectShiftTransition(IList <ITransition> transitions)
        {
            IList <BinaryTransition> leftoverBinary = Generics.NewArrayList();

            while (transitions.Count > 0)
            {
                ITransition head = transitions.Remove(0);
                if (head is ShiftTransition)
                {
                    break;
                }
                if (head is BinaryTransition)
                {
                    leftoverBinary.Add((BinaryTransition)head);
                }
            }
            if (transitions.Count == 0 || leftoverBinary.Count == 0)
            {
                // honestly this is an error we should probably just throw
                return(false);
            }
            int shiftCount = 0;
            IListIterator <ITransition> cursor     = transitions.ListIterator();
            BinaryTransition            lastBinary = null;

            while (cursor.MoveNext() && shiftCount >= 0)
            {
                ITransition next = cursor.Current;
                if (next is ShiftTransition)
                {
                    ++shiftCount;
                }
                else
                {
                    if (next is BinaryTransition)
                    {
                        --shiftCount;
                        if (shiftCount < 0)
                        {
                            lastBinary = (BinaryTransition)next;
                            cursor.Remove();
                        }
                    }
                }
            }
            if (!cursor.MoveNext() || lastBinary == null)
            {
                // once again, an error.  even if the sequence of tree altering
                // gold transitions ends with a BinaryTransition, there should
                // be a FinalizeTransition after that
                return(false);
            }
            string label = lastBinary.label;

            if (lastBinary.IsBinarized())
            {
                label = Sharpen.Runtime.Substring(label, 1);
            }
            if (lastBinary.side == BinaryTransition.Side.Right)
            {
                // When we finally transition all the binary transitions, we
                // will want to have the new node be the right head.  Therefore,
                // we add a bunch of temporary binary transitions with a right
                // head, ending up with a binary transition with a right head
                for (int i = 0; i < leftoverBinary.Count; ++i)
                {
                    cursor.Add(new BinaryTransition("@" + label, BinaryTransition.Side.Right));
                }
                // use lastBinary.label in case the last transition is temporary
                cursor.Add(new BinaryTransition(lastBinary.label, BinaryTransition.Side.Right));
            }
            else
            {
                cursor.Add(new BinaryTransition("@" + label, BinaryTransition.Side.Left));
                for (int i = 0; i < leftoverBinary.Count - 1; ++i)
                {
                    cursor.Add(new BinaryTransition("@" + label, leftoverBinary[i].side));
                }
                cursor.Add(new BinaryTransition(lastBinary.label, leftoverBinary[leftoverBinary.Count - 1].side));
            }
            return(true);
        }
Example #4
0
 public void Remove()
 {
     iterator.Remove();
 }