> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/de/sdks/build-ontologies-in-python.md).

# Ontologien in Python erstellen

Ontologien in Python mit OntologyStructure erstellen: Klassen, Formen, Eigenschaften und Klassifikationen für ganze Elemente im Unitlab-SDK definieren.

Eine Ontologie legt fest, was Annotatoren labeln können: Klassen mit einer Form, Eigenschaften dieser Klassen und Klassifikationen für ein ganzes Element.

```python
from unitlab import (
    ChecklistAttribute, NumericAttribute, OntologyStructure,
    RadioAttribute, Shape, TextAttribute,
)

structure = OntologyStructure()

# Objects: a class with a shape
gripper = structure.add_object("Gripper", Shape.BOUNDING_BOX, color="#2563EB")
state = gripper.add_attribute(RadioAttribute, "State", required=True, dynamic=True)
state.add_option("Open")
closed = state.add_option("Closed")
closed.add_nested_attribute(RadioAttribute, "Holding object").add_option("Yes")

part = structure.add_object("Part", Shape.POLYGON)
defects = part.add_attribute(ChecklistAttribute, "Defects")
for name in ("Scratch", "Dent", "Missing screw"):
    defects.add_option(name)
part.add_attribute(NumericAttribute, "Occlusion %")
part.add_attribute(TextAttribute, "Notes")

# Classification: answers about the whole item
scene = structure.add_classification()
lighting = scene.add_attribute(RadioAttribute, "Lighting", required=True)
lighting.add_option("Normal")
lighting.add_option("Low")

ontology = client.ontologies.create("Robot cell QA", structure=structure)
```

## Formen <a href="#shapes" id="shapes"></a>

| `Shape`               | Zeichnet                               | Typische Medien                   |
| --------------------- | -------------------------------------- | --------------------------------- |
| `BOUNDING_BOX`        | Box                                    | Bild, Video, Dokument, Medizin    |
| `POLYGON`             | Umriss                                 | Bild, Video, Geodaten, Pathologie |
| `BITMASK`             | Pixelmaske                             | Bild, Video, Medizin              |
| `POINT`               | Punkt                                  | Bild, Video                       |
| `POLYLINE`            | Offene Linie                           | Bild, Video, Geodaten             |
| `SKELETON`            | Verbundene Keypoints                   | Bild, Video                       |
| `CUBOID`              | 3D-Box auf 2D-Medien                   | Bild, Video, Dokument, Medizin    |
| `TEXT`                | Textabschnitt                          | Text, HTML, Tabellendaten         |
| `TIME_RANGE`          | Zeitabschnitt                          | Audio, Video                      |
| `INTERVAL`, `INSTANT` | Bereich oder Zeitpunkt auf der x-Achse | Zeitreihen                        |

## Eigenschaften <a href="#properties" id="properties"></a>

| Klasse               | Annotator gibt an       |
| -------------------- | ----------------------- |
| `RadioAttribute`     | Eine Option             |
| `ChecklistAttribute` | Beliebig viele Optionen |
| `NumericAttribute`   | Eine Zahl               |
| `TextAttribute`      | Freitext                |

| Flag                               | Wirkung                                                                                   |
| ---------------------------------- | ----------------------------------------------------------------------------------------- |
| `required=True`                    | Das Objekt kann ohne Wert nicht eingereicht werden. Releases lassen Labels ohne Wert aus. |
| `dynamic=True`                     | Der Wert kann sich im Video von Keyframe zu Keyframe ändern                               |
| `option.add_nested_attribute(...)` | Eine Eigenschaft, die nur bei Auswahl dieser Option angezeigt wird                        |

## Die Struktur lesen und schreiben <a href="#read-and-write-the-structure" id="read-and-write-the-structure"></a>

`structure.to_dict()` liefert das JSON, das die API speichert. `OntologyStructure.from_dict(data)` liest es wieder ein, sodass Sie Ontologien in der Versionsverwaltung pflegen können.

## Verwandte Themen <a href="#related" id="related"></a>

[Ontologie-Ressourcen](https://docs.unitlab.ai/api-sdk-cli/de/sdks/ontology-resources.md) · [Projekte](https://docs.unitlab.ai/api-sdk-cli/de/sdks/projects.md) · [CLI: Ontologien und Cloud-Speicher](https://docs.unitlab.ai/api-sdk-cli/de/clis/cli-ontologies-and-cloud-storage.md)
