> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Objects.ontology structure

## OntologyStructure Objects

```python theme={"dark"}
@dataclass
class OntologyStructure()
```

#### get\_child\_by\_hash

```python theme={"dark"}
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

```python theme={"dark"}
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

```python theme={"dark"}
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

```python theme={"dark"}
@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

```python theme={"dark"}
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

```python theme={"dark"}
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[Shape](/sdk-documentation/sdk-references/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

```python theme={"dark"}
def add_classification(
        uid: Optional[int] = None,
        feature_node_hash: Optional[str] = None,
        level: Optional[OntologyClassificationLevel] = 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.
* `level` - The level at which this classification applies. See :py[OntologyClassificationLevel](/sdk-documentation/sdk-references/objects.classification#ontologyclassificationlevel) enum for possible values.

**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

```python theme={"dark"}
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.
