> 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/hi/sdks/build-ontologies-in-python.md).

# Python में ओन्टोलॉजी बनाना

Python SDK में OntologyStructure से ओन्टोलॉजी बनाएँ: क्लास, शेप (bounding box, polygon आदि), प्रॉपर्टी और पूरे आइटम के क्लासिफ़िकेशन तय करें।

ओन्टोलॉजी बताती है कि एनोटेटर क्या लेबल कर सकते हैं: शेप वाली क्लासें, उन क्लासों की प्रॉपर्टी, और पूरे आइटम के लिए क्लासिफ़िकेशन।

```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)
```

## शेप <a href="#shapes" id="shapes"></a>

| `Shape`               | क्या बनाता है             | आम मीडिया                            |
| --------------------- | ------------------------- | ------------------------------------ |
| `BOUNDING_BOX`        | बॉक्स                     | इमेज, वीडियो, दस्तावेज़, मेडिकल      |
| `POLYGON`             | आउटलाइन                   | इमेज, वीडियो, जियोस्पेशियल, पैथोलॉजी |
| `BITMASK`             | पिक्सेल मास्क             | इमेज, वीडियो, मेडिकल                 |
| `POINT`               | पॉइंट                     | इमेज, वीडियो                         |
| `POLYLINE`            | खुली रेखा                 | इमेज, वीडियो, जियोस्पेशियल           |
| `SKELETON`            | जुड़े हुए कीपॉइंट         | इमेज, वीडियो                         |
| `CUBOID`              | 2D मीडिया पर बना 3D बॉक्स | इमेज, वीडियो, दस्तावेज़, मेडिकल      |
| `TEXT`                | टेक्स्ट अंश               | टेक्स्ट, HTML, टेबुलर                |
| `TIME_RANGE`          | समय खंड                   | ऑडियो, वीडियो                        |
| `INTERVAL`, `INSTANT` | x-अक्ष पर रेंज या क्षण    | टाइम सीरीज़                          |

## प्रॉपर्टी <a href="#properties" id="properties"></a>

| क्लास                | एनोटेटर क्या देता है |
| -------------------- | -------------------- |
| `RadioAttribute`     | एक विकल्प            |
| `ChecklistAttribute` | कितने भी विकल्प      |
| `NumericAttribute`   | एक संख्या            |
| `TextAttribute`      | मुक्त टेक्स्ट        |

| फ़्लैग                             | असर                                                                                                |
| ---------------------------------- | -------------------------------------------------------------------------------------------------- |
| `required=True`                    | मान के बिना ऑब्जेक्ट सबमिट नहीं हो सकता। जिन लेबल में यह मान नहीं है, उन्हें रिलीज़ छोड़ देती हैं। |
| `dynamic=True`                     | वीडियो में मान एक कीफ़्रेम से दूसरे कीफ़्रेम तक बदल सकता है                                        |
| `option.add_nested_attribute(...)` | एक प्रॉपर्टी जो सिर्फ़ उस विकल्प के चुने जाने पर दिखती है                                          |

## स्ट्रक्चर पढ़ना और लिखना <a href="#read-and-write-the-structure" id="read-and-write-the-structure"></a>

`structure.to_dict()` वह JSON लौटाता है जिसे API सेव करता है। `OntologyStructure.from_dict(data)` उसे वापस पढ़ता है, इसलिए आप ओन्टोलॉजी को वर्शन कंट्रोल में रख सकते हैं।

## संबंधित पेज <a href="#related" id="related"></a>

[ओन्टोलॉजी रिसोर्स](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/ontology-resources.md) · [प्रोजेक्ट](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/projects.md) · [CLI: ओन्टोलॉजी और क्लाउड स्टोरेज](https://docs.unitlab.ai/api-sdk-cli/hi/clis/cli-ontologies-and-cloud-storage.md)
