fiftyone.core.annotation.nodes#
Taxonomy node primitive.
Classes:
|
A node in a |
Functions:
|
Returns the first descendant (or |
|
Returns a copy of |
- class fiftyone.core.annotation.nodes.Node(name: str, description: str | None = None, can_select: bool = True, deprecated: bool = False, values: list[Node] | None = None)#
Bases:
objectA node in a
fiftyone.core.ontology.Taxonomytree.There is a single node type: every node has the same shape regardless of whether it represents a leaf class, a sub-class, or a group header. The role of a node is determined by its position in the tree and by the
can_selectflag.- Parameters:
name – required label for this node — a class name, sub-class name, or group header. Must be unique within the taxonomy (uniqueness is enforced by
validate_taxonomy, not at construction time).description – optional context for the user (tooltip / guidance text in the UI)
can_select – if
False, the node is a group header — it expands to show child nodes but is not itself selectable as a class. Defaults toTrue.deprecated – if
True, the node is hidden from the UI for new selections but remains valid on existing labels. Defaults toFalse.values – optional list of child
Nodeinstances. A leaf node has novalues; a node with children hasvalues.
Example:
Node( name="vehicles", can_select=False, values=[ Node(name="car"), Node(name="truck"), ], )
Attributes:
Methods:
- name: str#
- description: str | None = None#
- to_dict() dict#
Serializes this node to a dict.
- Returns:
a dict
- fiftyone.core.annotation.nodes.find_in_dict(root: dict, name: str) dict | None#
Returns the first descendant (or
rootitself) whosenamematches, orNone.Node names are unique within a taxonomy (enforced by
fiftyone.core.ontology_validation.validate_taxonomy()), so the first match is the only match.- Parameters:
root – a node-shaped dict
name – the node name to search for
- Returns:
the matching dict (a reference into
root) orNone
- fiftyone.core.annotation.nodes.truncate_dict(node: dict, depth: int) dict#
Returns a copy of
nodetruncated todepthlevels below.At the truncation boundary, nodes that had children in the source are returned with
values=[]so the wire format distinguishes them from real leaves (which have novalueskey).- Parameters:
node – a node-shaped dict
depth – non-negative recursion depth.
0returns justnodewith no descendants.
- Returns:
a new dict; the input is not mutated