Definitions of tree structures.
- class penman.tree.Tree(node, metadata=None)[source]¶
A tree structure.
A tree is essentially a node that contains other nodes, but this Tree class is useful to contain any metadata and to provide tree-based methods.
Recreate node variables formatted using fmt.
The fmt string can be formatted with the following values:
prefix: first alphabetic character in the node’s concept
i: 0-based index of the current occurrence of the prefix
j: 1-based index starting from the second occurrence
Iterate over branches in the tree.
This function yields pairs of (path, branch) where each path is a tuple of 0-based indices of branches to get to branch. For example, the path (2, 0) is the concept branch (‘/’, ‘bark-01’) in the tree for the following PENMAN string, traversing first to the third (index 2) branch of the top node, then to the first (index 0) branch of that node:
(t / try-01 :ARG0 (d / dog) :ARG1 (b / bark-01 :ARG0 d))
The (path, branch) pairs are yielded in depth-first order of the tree traversal.