Definitions of tree structures.
- class penman.tree.Tree(node, metadata=None)#
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.
Return the nodes in the tree as a flat list.
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.
Trueif x is a valid atomic value.
>>> from penman.tree import is_atomic >>> is_atomic('a') True >>> is_atomic(None) True >>> is_atomic(3.14) True >>> is_atomic(('a', [('/', 'alpha')])) False