Skip to content

Commit e26f972

Browse files
rahullbrahul sharmarahul sharma
authored
adding subclassifications to ontologies (#1063)
Co-authored-by: rahul sharma <rahulsharma@rahuls-MBP.localdomain> Co-authored-by: rahul sharma <rahulsharma@rahuls-MBP.hsd1.fl.comcast.net>
1 parent 87d84aa commit e26f972

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

examples/basics/ontologies.ipynb

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
{
4444
"metadata": {},
4545
"source": [
46-
"!pip install labelbox"
46+
"!pip install labelbox -q"
4747
],
4848
"cell_type": "code",
4949
"outputs": [],
@@ -71,7 +71,7 @@
7171
"metadata": {},
7272
"source": [
7373
"# Add your api key\n",
74-
"API_KEY = None\n",
74+
"API_KEY = \"Enter api key here\"\n",
7575
"client = lb.Client(api_key=API_KEY)"
7676
],
7777
"cell_type": "code",
@@ -212,13 +212,41 @@
212212
{
213213
"metadata": {},
214214
"source": [
215-
"### Update and Delete\n",
216-
"- At this time, these options are not supported from the SDK.\n",
217-
"- Updating an ontology is dangerous and could cause labels to be hidden. \n",
218-
" - Use caution when doing so"
215+
"### Update and Delete"
219216
],
220217
"cell_type": "markdown"
221218
},
219+
{
220+
"metadata": {},
221+
"source": [
222+
"# Check if feature is archived\n",
223+
"feature_schema = next(client.get_feature_schemas(\"cat\"))\n",
224+
"client.is_feature_schema_archived(ontology_id=ontology.uid, feature_schema_id=feature_schema.uid)"
225+
],
226+
"cell_type": "code",
227+
"outputs": [],
228+
"execution_count": null
229+
},
230+
{
231+
"metadata": {},
232+
"source": [
233+
"Delete or Archived a feature:\n",
234+
"\n",
235+
"If the feature schema is a root level node with associated labels, it will be archived.\n",
236+
"If the feature schema is a nested node in the ontology and does not have associated labels, it will be deleted.\n",
237+
"If the feature schema is a nested node in the ontology and has associated labels, it will not be deleted."
238+
],
239+
"cell_type": "markdown"
240+
},
241+
{
242+
"metadata": {},
243+
"source": [
244+
"client.delete_feature_schema_from_ontology(ontology_id=ontology.uid, feature_schema_id=feature_schema.uid)"
245+
],
246+
"cell_type": "code",
247+
"outputs": [],
248+
"execution_count": null
249+
},
222250
{
223251
"metadata": {},
224252
"source": [
@@ -286,12 +314,12 @@
286314
" name=\"cat\",\n",
287315
" classifications=[\n",
288316
" lb.Classification(class_type=lb.Classification.Type.TEXT,\n",
289-
" instructions=\"name\")\n",
317+
" name=\"name\")\n",
290318
" ])\n",
291319
" ],\n",
292320
" classifications=[\n",
293321
" lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
294-
" instructions=\"image_quality\",\n",
322+
" name=\"image_quality\",\n",
295323
" options=[lb.Option(value=\"clear\"),\n",
296324
" lb.Option(value=\"blurry\")])\n",
297325
" ])\n",
@@ -301,6 +329,35 @@
301329
"outputs": [],
302330
"execution_count": null
303331
},
332+
{
333+
"metadata": {},
334+
"source": [
335+
"Example of how to add sub-classfication within an option"
336+
],
337+
"cell_type": "markdown"
338+
},
339+
{
340+
"metadata": {},
341+
"source": [
342+
"# We will use add_classification to add this classification to a previously built ontology_builder or you can create new ontology_builder = OntologyBuilder() \n",
343+
"radio_classification = lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
344+
" name=\"Global classification\",\n",
345+
" options=[lb.Option(\"1st option\", options=[lb.Classification(class_type=lb.Classification.Type.CHECKLIST,\n",
346+
" name=\"Inside 1st option\",\n",
347+
" options=[lb.Option(\"Option A\"), lb.Option(\"Option B\")])]), lb.Option(\"2nd option\", options=[lb.Classification(class_type=lb.Classification.Type.CHECKLIST,\n",
348+
" name=\"Inside 2nd option\",\n",
349+
" options=[lb.Option(\"Option A\"), lb.Option(\"Option B\")])])])\n",
350+
"\n",
351+
"ontology_builder.add_classification(radio_classification) \n",
352+
"\n",
353+
"ontology = client.create_ontology(\"example of nested classification\",\n",
354+
" ontology_builder.asdict())\n",
355+
"print(json.dumps(ontology.normalized, indent=2))"
356+
],
357+
"cell_type": "code",
358+
"outputs": [],
359+
"execution_count": null
360+
},
304361
{
305362
"metadata": {},
306363
"source": [
@@ -335,13 +392,13 @@
335392
"metadata": {},
336393
"source": [
337394
"text_classification = lb.Classification(class_type=lb.Classification.Type.TEXT,\n",
338-
" instructions=\"dog_name\")\n",
395+
" name=\"dog_name\")\n",
339396
"radio_classification = lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
340-
" instructions=\"dog_breed\",\n",
397+
" name=\"dog_breed\",\n",
341398
" options=[lb.Option(\"poodle\")])\n",
342399
"checklist_classification = lb.Classification(\n",
343400
" class_type=lb.Classification.Type.CHECKLIST,\n",
344-
" instructions=\"background\",\n",
401+
" name=\"background\",\n",
345402
" options=[lb.Option(\"at_park\"), lb.Option(\"has_leash\")])"
346403
],
347404
"cell_type": "code",

0 commit comments

Comments
 (0)