public virtual void TestReorderIncorrectShiftResultingTree() { for (int testcase = 0; testcase < correctTrees.Length; ++testcase) { State state = ShiftReduceParser.InitialStateFromGoldTagTree(correctTrees[testcase]); IList <ITransition> gold = CreateTransitionSequence.CreateTransitionSequence(binarizedTrees[testcase]); // System.err.println(correctTrees[testcase]); // System.err.println(gold); int tnum = 0; for (; tnum < gold.Count; ++tnum) { if (gold[tnum] is BinaryTransition) { break; } state = gold[tnum].Apply(state); } state = shift.Apply(state); IList <ITransition> reordered = Generics.NewLinkedList(gold.SubList(tnum, gold.Count)); NUnit.Framework.Assert.IsTrue(ReorderingOracle.ReorderIncorrectShiftTransition(reordered)); // System.err.println(reordered); foreach (ITransition transition in reordered) { state = transition.Apply(state); } Tree debinarized = debinarizer.TransformTree(state.stack.Peek()); // System.err.println(debinarized); NUnit.Framework.Assert.AreEqual(incorrectShiftTrees[testcase].ToString(), debinarized.ToString()); } }
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())); }
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); }