private static void AddNode(Parse parse, PtbNode node, ref int index) { var head = ++index; // TODO: How to deal with this gaps here? //if (node.Type != "-NONE-") parse.Insert(new Parse(parse.Text, node.Span, AbstractBottomUpParser.TOK_NODE, 1, head)); // Add the children first, otherwise the order of the nodes will be a mess :P if (node.HasChildren) { foreach (var child in node.Children) { if (child.HasChildren) { AddNode(parse, child, ref index); } else { parse.Insert(new Parse(parse.Text, child.Span, child.Type, 1, head)); } } } parse.Insert(new Parse(parse.Text, node.Span, node.Type, 1, head)); }
private static bool CheckFormat(PtbNode node) { if (node == null) return false; var str = node.ToString(); var open = 0; var close = 0; foreach (var chr in str) { switch (chr) { case '(': open++; continue; case ')': close++; continue; } } return (open - close) == 0; }
private static void AddNode(List <string> list, PtbNode node) { if (node.Token != null) { list.Add(node.Type); } if (!node.HasChildren) { return; } foreach (var child in node.Children) { AddNode(list, child); } }
private static void CheckSpan(string text, PtbNode node) { var check = string.Join(" ", node.Tokens); Assert.AreEqual(text.Substring(node.Span.Start, node.Span.End - node.Span.Start), check); if (!node.HasChildren) return; foreach (var child in node.Children) { CheckSpan(text, child); } }