예제 #1
0
 public virtual bool Parse <_T0>(IList <_T0> sentence)
     where _T0 : IHasWord
 {
     this.originalSentence = sentence;
     initialState          = ShiftReduceParser.InitialStateFromTaggedSentence(sentence);
     return(ParseInternal());
 }
예제 #2
0
        public virtual void TestInitialStateFromTagged()
        {
            string[] words = new string[] { "This", "is", "a", "short", "test", "." };
            string[] tags  = new string[] { "DT", "VBZ", "DT", "JJ", "NN", "." };
            NUnit.Framework.Assert.AreEqual(words.Length, tags.Length);
            IList <TaggedWord> sentence = SentenceUtils.ToTaggedList(Arrays.AsList(words), Arrays.AsList(tags));
            State state = ShiftReduceParser.InitialStateFromTaggedSentence(sentence);

            for (int i = 0; i < words.Length; ++i)
            {
                NUnit.Framework.Assert.AreEqual(tags[i], state.sentence[i].Value());
                NUnit.Framework.Assert.AreEqual(1, state.sentence[i].Children().Length);
                NUnit.Framework.Assert.AreEqual(words[i], state.sentence[i].Children()[0].Value());
            }
        }
예제 #3
0
        public virtual void TestTransition()
        {
            string[] words = new string[] { "This", "is", "a", "short", "test", "." };
            string[] tags  = new string[] { "DT", "VBZ", "DT", "JJ", "NN", "." };
            NUnit.Framework.Assert.AreEqual(words.Length, tags.Length);
            IList <TaggedWord> sentence = SentenceUtils.ToTaggedList(Arrays.AsList(words), Arrays.AsList(tags));
            State           state       = ShiftReduceParser.InitialStateFromTaggedSentence(sentence);
            ShiftTransition shift       = new ShiftTransition();

            for (int i = 0; i < 3; ++i)
            {
                state = shift.Apply(state);
            }
            NUnit.Framework.Assert.AreEqual(3, state.tokenPosition);
        }
        public virtual void TestBinarySide()
        {
            string[] words = new string[] { "This", "is", "a", "short", "test", "." };
            string[] tags  = new string[] { "DT", "VBZ", "DT", "JJ", "NN", "." };
            NUnit.Framework.Assert.AreEqual(words.Length, tags.Length);
            IList <TaggedWord> sentence = SentenceUtils.ToTaggedList(Arrays.AsList(words), Arrays.AsList(tags));
            State           state       = ShiftReduceParser.InitialStateFromTaggedSentence(sentence);
            ShiftTransition shift       = new ShiftTransition();

            state = shift.Apply(shift.Apply(state));
            BinaryTransition transition = new BinaryTransition("NP", BinaryTransition.Side.Right);
            State            next       = transition.Apply(state);

            NUnit.Framework.Assert.AreEqual(BinaryTransition.Side.Right, ShiftReduceUtils.GetBinarySide(next.stack.Peek()));
            transition = new BinaryTransition("NP", BinaryTransition.Side.Left);
            next       = transition.Apply(state);
            NUnit.Framework.Assert.AreEqual(BinaryTransition.Side.Left, ShiftReduceUtils.GetBinarySide(next.stack.Peek()));
        }