tree¶
Tree
is a very basic immutable tree class. A Tree
can have multiple children and has one parent. The parent and child of a tree are established when a Tree
is created. Accessing the data on a Tree
can be done through the data
member. A Tree
’s direct children can be iterated with a for loop. A Tree
is created through the TreeBuilder
module which is an internal module in pyconll and keeps Tree
immutable on the public interface. A Tree
is provided as the result of to_tree
on a Sentence
object.
API¶
A general immutable tree module. This module is used when parsing a serial sentence into a Tree structure.
-
class
pyconll.tree.tree.
Tree
(data: T)[source]¶ A tree node. This is the base representation for a tree, which can have many children which are accessible via child index. The tree’s structure is immutable, so the data, parent, children cannot be changed once created.
As is this class is useless, and must be created with the TreeBuilder module which is a sort of friend class of Tree to maintain its immutable public contract.
-
__getitem__
(key: int) → Tree[T][source]¶ -
__getitem__
(key: slice) → List[Tree[T]] Get specific children from the Tree. This can be an integer or slice.
- Parameters
key – The indexer for the item.
-
__init__
(data: T) → None[source]¶ Create a tree holding the value. Create a larger Tree, with TreeBuilder.
- Parameters
data – The data to put with the Tree node.
-
__iter__
() → Iterator[pyconll.tree.tree.Tree[T]][source]¶ Provides an iterator over the children.
-
__len__
() → int[source]¶ Provides the number of direct children on the tree.
- Returns
The number of direct children on the tree.
-
property
data
¶ The data on the tree node. The property ensures it is readonly.
- Returns
The data stored on the Tree.
-
property
parent
¶ Provides the parent of the Tree. The property ensures it is readonly.
- Returns
A pointer to the parent Tree reference. None if there is no parent.
-