public virtual void TestBasicOperations()
        {
            TreeShapedStack <string> tss = new TreeShapedStack <string>();

            NUnit.Framework.Assert.AreEqual(tss.size, 0);
            TreeShapedStack <string> tss1 = tss.Push("1");

            NUnit.Framework.Assert.AreEqual(tss1.size, 1);
            NUnit.Framework.Assert.AreEqual(tss1.Peek(), "1");
            TreeShapedStack <string> tss2 = tss1.Push("2");

            NUnit.Framework.Assert.AreEqual(tss2.size, 2);
            NUnit.Framework.Assert.AreEqual(tss2.Peek(), "2");
            NUnit.Framework.Assert.AreEqual(tss2.previous.Peek(), "1");
            TreeShapedStack <string> tss3 = tss2.Push("3");

            NUnit.Framework.Assert.AreEqual(tss3.size, 3);
            NUnit.Framework.Assert.AreEqual(tss3.Peek(), "3");
            NUnit.Framework.Assert.AreEqual(tss3.previous.Peek(), "2");
            tss3 = tss3.Pop();
            NUnit.Framework.Assert.AreEqual(tss3.Peek(), "2");
            NUnit.Framework.Assert.AreEqual(tss3.previous.Peek(), "1");
            NUnit.Framework.Assert.AreEqual(tss3.Peek(), "2");
            TreeShapedStack <string> tss4 = tss3.Push("4");

            NUnit.Framework.Assert.AreEqual(tss4.Peek(), "4");
            NUnit.Framework.Assert.AreEqual(tss4.Peek(), "4");
            NUnit.Framework.Assert.AreEqual(tss4.previous.Peek(), "2");
            tss4 = tss4.Pop();
            NUnit.Framework.Assert.AreEqual(tss4.Peek(), "2");
            tss4 = tss4.Pop();
            NUnit.Framework.Assert.AreEqual(tss4.Peek(), "1");
            tss4 = tss4.Pop();
            NUnit.Framework.Assert.AreEqual(tss4.size, 0);
        }
        /// <summary>Add a unary node to the existing node on top of the stack</summary>
        public virtual State Apply(State state, double scoreDelta)
        {
            Tree top    = state.stack.Peek();
            Tree newTop = AddUnaryNode(top, label);
            TreeShapedStack <Tree> stack = state.stack.Pop();

            stack = stack.Push(newTop);
            return(new State(stack, state.transitions.Push(this), state.separators, state.sentence, state.tokenPosition, state.score + scoreDelta, false));
        }
Ejemplo n.º 3
0
        /// <summary>Add a unary node to the existing node on top of the stack</summary>
        public virtual State Apply(State state, double scoreDelta)
        {
            Tree top = state.stack.Peek();

            for (int i = labels.Length - 1; i >= 0; --i)
            {
                top = UnaryTransition.AddUnaryNode(top, labels[i]);
            }
            TreeShapedStack <Tree> stack = state.stack.Pop();

            stack = stack.Push(top);
            return(new State(stack, state.transitions.Push(this), state.separators, state.sentence, state.tokenPosition, state.score + scoreDelta, false));
        }
        public virtual void TestEquals()
        {
            TreeShapedStack <string> t1 = new TreeShapedStack <string>();

            t1 = t1.Push("foo");
            t1 = t1.Push("bar");
            t1 = t1.Push("bar");
            t1 = t1.Push("diet");
            t1 = t1.Push("coke");
            TreeShapedStack <string> t2 = new TreeShapedStack <string>();

            t2 = t2.Push("foo");
            t2 = t2.Push("bar");
            t2 = t2.Push("bar");
            t2 = t2.Push("diet");
            t2 = t2.Push("coke");
            TreeShapedStack <string> t3 = t2.Pop().Push("pepsi");

            NUnit.Framework.Assert.AreEqual(t1, t2);
            NUnit.Framework.Assert.IsFalse(t1.Pop().Equals(t2));
            NUnit.Framework.Assert.IsFalse(t2.Pop().Equals(t1));
            NUnit.Framework.Assert.IsFalse(t2.Equals(t3));
        }
        /// <summary>Add a binary node to the existing node on top of the stack</summary>
        public virtual State Apply(State state, double scoreDelta)
        {
            TreeShapedStack <Tree> stack = state.stack;
            Tree right = stack.Peek();

            stack = stack.Pop();
            Tree left = stack.Peek();

            stack = stack.Pop();
            Tree head;

            switch (side)
            {
            case BinaryTransition.Side.Left:
            {
                head = left;
                break;
            }

            case BinaryTransition.Side.Right:
            {
                head = right;
                break;
            }

            default:
            {
                throw new ArgumentException("Unknown side " + side);
            }
            }
            if (!(head.Label() is CoreLabel))
            {
                throw new ArgumentException("Stack should have CoreLabel nodes");
            }
            CoreLabel headLabel  = (CoreLabel)head.Label();
            CoreLabel production = new CoreLabel();

            production.SetValue(label);
            production.Set(typeof(TreeCoreAnnotations.HeadWordLabelAnnotation), headLabel.Get(typeof(TreeCoreAnnotations.HeadWordLabelAnnotation)));
            production.Set(typeof(TreeCoreAnnotations.HeadTagLabelAnnotation), headLabel.Get(typeof(TreeCoreAnnotations.HeadTagLabelAnnotation)));
            Tree newTop = new LabeledScoredTreeNode(production);

            newTop.AddChild(left);
            newTop.AddChild(right);
            stack = stack.Push(newTop);
            return(new State(stack, state.transitions.Push(this), state.separators, state.sentence, state.tokenPosition, state.score + scoreDelta, false));
        }