Taxonomy¶
The Plums taxonomy module implements a taxonomy creation, modification and look-up API.
It mainly consists in 3 classes:
The
Labelclass which is the base class for allTaxonomycreation: it implements the actual tree logic and the creation API.The
Treeclass which is a reader/helper class to facilitate lookups, iterative walks and comparisons.The
Taxonomyclass which is a special kind ofTreewith a fixed, virtual root to allow multiple rooted taxonomies.
The Taxonomy API¶
Trees helper classes¶
Taxonomies iterators¶
-
class
plums.commons.data.taxonomy.iterator.TreeIteratorBase(tree, max_depth=None)[source]¶ Bases:
objectAbstract Base Class for all
Treeiterator classes.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to iterate.
-
class
plums.commons.data.taxonomy.iterator.DefaultTreeIterator(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates in a top-down manner and gives interfaces to other iteration flavors.It starts at the tree root and go down until it reaches a leaf label. It then steps upward and searches for the next leafs.
For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hThe iterator will yield:
f,b,a,d,c,e,g,ithenh.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot)which to iterate. (on) –
-
top_down()[source]¶ Make an iterator which iterate through a
Treein a top-down order.See also
The
TopDownTreeIteratorclass.Yields (
Label): A treeLabelnode.
-
bottom_up()[source]¶ Make an iterator which iterate through a
Treein a bottom-up order.See also
The
BottomUpTreeIteratorclass.Yields (
Label): A treeLabelnode.
-
depth_wise_top_down()[source]¶ Make an iterator which iterate through a
Treein a depth-wise top-down order.See also
The
TopDownDepthWiseTreeIteratorclass.Yields (Iterable[
Label]): An iterator over an ensemble ofLabelnodes.
-
depth_wise_bottom_up()[source]¶ Make an iterator which iterate through a
Treein a depth-wise bottom-up order.See also
The
BottomUpDepthWiseTreeIteratorclass.Yields (Iterable[
Label]): An iterator over an ensemble ofLabelnodes.
-
floor(depth)[source]¶ Make an iterator which iterate through a
Treegiven depth floor.- Parameters
depth (int) – The
Labeldepth (relative totreeroot) on which to iterate.
See also
The
FloorTreeIteratorclass.Yields (
Label): A treeLabelnode.
-
class
plums.commons.data.taxonomy.iterator.TopDownTreeIterator(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates in a top-down manner.It starts at the tree root and go down until it reaches a leaf label. It then steps upward and searches for the next leafs.
For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hThe iterator will yield:
f,b,a,d,c,e,g,ithenh.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to iterate.
-
class
plums.commons.data.taxonomy.iterator.BottomUpTreeIterator(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates in a bottom-up manner.It starts at a leaf and go up until it reaches the tree root. It then steps downward and searches for the next leafs to start from.
For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hThe iterator will yield:
h,i,g,e,c,d,a,bthenf.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot)which to iterate. (on) –
-
class
plums.commons.data.taxonomy.iterator.FloorTreeIterator(tree, depth)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates over all labels in a given depth.For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hIf depth is 2, the iterator will yield:
a,dtheni.- Parameters
tree (
Tree) – The tree on which to iterate.depth (int) – The
Labeldepth (relative totreeroot) on which to iterate.
-
class
plums.commons.data.taxonomy.iterator.TopDownDepthWiseTreeIterator(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates through aTreein a depth-wise top-down manner.For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hThe iterator will yield:
(f, ),(b, g),(a, d, i)then(c, e, h).- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to iterate.
-
class
plums.commons.data.taxonomy.iterator.BottomUpDepthWiseTreeIterator(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.iterator.TreeIteratorBaseA
Treeiterator class which iterates through aTreein a depth-wise bottom-up manner.For example, given the following:
f ├── b │ ├── a │ ╰── d │ ├── c │ ╰── e ╰── g ╰── i ╰── hThe iterator will yield:
(c, e, h),(a, d, i),(b, g)then(f, ).- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to iterate.
Taxonomies accessors¶
-
class
plums.commons.data.taxonomy.accessor.TreeAccessorBase(tree, max_depth=None)[source]¶ Bases:
objectAbstract Base Class for all
Treeaccessor classes.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to allow access.
-
class
plums.commons.data.taxonomy.accessor.DefaultTreeAccessor(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.accessor.TreeAccessorBaseTreeaccessor class which retrieveLabelfrom their name and exposes other access flavors as properties.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to allow access.
-
property
name¶ Access
Labelfrom their name.- Type
-
property
id¶ Access
Labelfrom their id.- Type
-
class
plums.commons.data.taxonomy.accessor.NameTreeAccessor(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.accessor.TreeAccessorBaseTreeaccessor class which retrieveLabelfrom their name.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to allow access.
-
class
plums.commons.data.taxonomy.accessor.IdTreeAccessor(tree, max_depth=None)[source]¶ Bases:
plums.commons.data.taxonomy.accessor.TreeAccessorBaseTreeaccessor class which retrieveLabelfrom their id.- Parameters
tree (
Tree) – The tree on which to iterate.max_depth (int) – Optional. Default to None. If provided, the maximum
Labeldepth (relative totreeroot) on which to allow access.