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[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)[source]

Get specific children from the Tree. This can be an integer or slice.

Parameters:key – The indexer for the item.
__init__()[source]

Create a new empty tree. To create a useful Tree, use TreeBuilder.

__iter__()[source]

Provides an iterator over the children.

__len__()[source]

Provides the number of direct children on the tree.

Returns:The number of direct children on the tree.
data

The data on the tree node. The property ensures it is readonly.

Returns:The data stored on the Tree. No data is represented as None.
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.