OntologyStructure Objects

class OntologyStructure()

get_child_by_hash

def get_child_by_hash(
        feature_node_hash: str,
        type_: Optional[Type[OntologyElementT]] = None) -> OntologyElementT

Returns the first child node of this ontology tree node with the matching feature node hash. If there is more than one child with the same feature node hash in the ontology tree node, then the ontology would be in an invalid state. Throws if nothing is found or if the type is not matched.

Arguments:

  • feature_node_hash - The feature_node_hash of the child node to search for in the ontology.
  • type_ - The expected type of the item. If the found child does not match the type, an error will be thrown.

Raises:

  • OntologyError - If the item with the specified feature_node_hash is not found or if the type does not match.

get_child_by_title

def get_child_by_title(
        title: str,
        type_: Optional[Type[OntologyElementT]] = None) -> OntologyElementT

Returns a child node of this ontology tree node with the matching title and matching type if specified. If more than one child in this Object have the same title, then an error will be thrown. If no item is found, an error will be thrown as well.

Arguments:

  • title - The exact title of the child node to search for in the ontology.
  • type_ - The expected type of the child node. Only a node that matches this type will be returned.

Raises:

  • OntologyError - If no child node with the specified title and type is found, or if multiple matches are found.

get_children_by_title

def get_children_by_title(
        title: str,
        type_: Optional[Type[OntologyElementT]] = None
) -> List[OntologyElementT]

Returns all the child nodes of this ontology tree node with the matching title and matching type if specified. Title in ontologies do not need to be unique, however, we recommend unique titles when creating ontologies.

Arguments:

  • title - The exact title of the child node to search for in the ontology.
  • type_ - The expected type of the item. Only nodes that match this type will be returned.

Returns:

  • List[OntologyElementT] - A list of child nodes with the matching title and type.

from_dict

@classmethod
def from_dict(cls, d: Dict[str, Any]) -> OntologyStructure

Create an OntologyStructure from a dictionary.

Arguments:

  • d - A JSON blob of an “ontology structure” (e.g. from Encord web app)

Returns:

  • OntologyStructure - The created OntologyStructure object.

Raises:

  • KeyError - If the dict is missing a required field.

to_dict

def to_dict() -> Dict[str, List[Dict[str, Any]]]

Convert the OntologyStructure to a dictionary.

Returns:

Dict[str, List[Dict[str, Any]]]: The dictionary representation of the ontology.

add_object

def add_object(name: str,
               shape: Shape,
               uid: Optional[int] = None,
               color: Optional[str] = None,
               feature_node_hash: Optional[str] = None) -> Object

Adds an object class definition to the structure.

Arguments:

  • name - The user-visible name of the object.
  • shape - The kind of object (bounding box, polygon, etc). See :py:class:encord.objects.common.Shape enum for possible values.
  • uid - Integer identifier of the object. Normally auto-generated; omit this unless the aim is to create an exact clone of existing structure.
  • color - The color of the object in the label editor. Normally auto-assigned, should be in ’1A2B3F’ syntax.
  • feature_node_hash - Global identifier of the object. Normally auto-generated; omit this unless the aim is to create an exact clone of existing structure.

Returns:

  • Object - The created object class that can be further customized with attributes.

Raises:

  • ValueError - If a duplicate uid or feature_node_hash is provided.

add_classification

def add_classification(
        uid: Optional[int] = None,
        feature_node_hash: Optional[str] = None) -> Classification

Adds a classification definition to the ontology.

Arguments:

  • uid - Integer identifier of the object. Normally auto-generated; omit this unless the aim is to create an exact clone of existing structure.
  • feature_node_hash - Global identifier of the object. Normally auto-generated; omit this unless the aim is to create an exact clone of existing structure.

Returns:

  • Classification - The created classification node. Note that classification attribute should be further specified by calling its add_attribute() method.

Raises:

  • ValueError - If a duplicate uid or feature_node_hash is provided.

add_skeleton_template

def add_skeleton_template(skeleton_template: SkeletonTemplate,
                          feature_node_hash: Optional[str] = None) -> None

Adds a skeleton template to the ontology structure.

Arguments:

  • skeleton_template - The SkeletonTemplate object to be added.
  • feature_node_hash - Global identifier of the skeleton template. Normally auto-generated; omit this unless the aim is to create an exact clone of existing structure.

Raises:

  • ValueError - If a skeleton template with the same name already exists in the ontology.