Inheritance: ForestNode
Example #1
0
        private List <ForestNode[]> BuildChildren()
        {
            var count = _family.Production.Rhs.Count;

            if (count == 0)
            {
                if (_family.Members.Count != 1)
                {
                    throw new Exception();
                }
                var leaf = new ForestLeaf((EpsilonNode)_family.Members[0]);
                return(new List <ForestNode[]> {
                    new ForestNode[1] {
                        leaf
                    }
                });
            }
            var start     = new ForestNode[count];
            var startList = new List <ForestNode[]> {
                start
            };

            BuildChildrenHelper(_family, startList, _family.Production.Rhs, count - 1);
            return(startList);
        }
Example #2
0
		private List<ForestNode[]> BuildChildren() {
			var count = _family.Production.Rhs.Count;
			if (count == 0) {
				if (_family.Members.Count != 1) {
					throw new Exception();
				}
				var leaf = new ForestLeaf((EpsilonNode)_family.Members[0]);
				return new List<ForestNode[]> { new ForestNode[1] { leaf } };
			}
			var start = new ForestNode[count];
			var startList = new List<ForestNode[]> { start };
			BuildChildrenHelper(_family, startList, _family.Production.Rhs, count - 1);
			return startList;
		}
Example #3
0
        //internal void GetGraphHelper(Graph g) {
        //	//g.Add(this);
        //	bool changes = false;
        //	var myNode = new NodeNode(this, 0);
        //	foreach (var children in _children) {
        //		var childNode = new ChildNode(_family.Production.Rhs, StartPosition, EndPosition);
        //		changes |= g.AddEdge(myNode, childNode);
        //		foreach (var child in children) {
        //			var mychildNode = new NodeNode(child, 0);
        //			changes |= g.AddEdge(childNode, mychildNode);
        //		}
        //	}
        //	if (changes) {
        //		foreach (var children in _children) {
        //			foreach (var child in children) {
        //				child.GetGraphHelper(g);
        //			}
        //		}
        //	}
        //}

        private static void AddNode(SppfNode node, List <ForestNode[]> startList, Sentence rhs, int position)
        {
            ForestNode nodeToAdd;

            if (node is TerminalNode)
            {
                nodeToAdd = new ForestLeaf((TerminalNode)node);
            }
            else
            {
                nodeToAdd = new ForestInternal((SymbolNode)node, (Nonterminal)rhs[position]);
            }
            foreach (var children in startList)
            {
                children[position] = nodeToAdd;
            }
        }
Example #4
0
		//internal void GetGraphHelper(Graph g) {
		//	//g.Add(this);
		//	bool changes = false;
		//	var myNode = new NodeNode(this, 0);
		//	foreach (var children in _children) {
		//		var childNode = new ChildNode(_family.Production.Rhs, StartPosition, EndPosition);
		//		changes |= g.AddEdge(myNode, childNode);
		//		foreach (var child in children) {
		//			var mychildNode = new NodeNode(child, 0);
		//			changes |= g.AddEdge(childNode, mychildNode);
		//		}
		//	}
		//	if (changes) {
		//		foreach (var children in _children) {
		//			foreach (var child in children) {
		//				child.GetGraphHelper(g);
		//			}
		//		}
		//	}
		//}

		private static void AddNode(SppfNode node, List<ForestNode[]> startList, Sentence rhs, int position) {
			ForestNode nodeToAdd;
			if (node is TerminalNode) {
				nodeToAdd = new ForestLeaf((TerminalNode)node);
			} else {
				nodeToAdd = new ForestInternal((SymbolNode)node, (Nonterminal)rhs[position]);
			}
			foreach (var children in startList) {
				children[position] = nodeToAdd;
			}
		}