Skip to content

Commit 4b09e0e

Browse files
author
Matt Sokoloff
committed
complete ontology management
1 parent ccf36bb commit 4b09e0e

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

examples/basics/ontologies.ipynb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"id": "18d7cb3b",
5252
"metadata": {},
5353
"source": [
54-
"### Create Ontology From Normalized JSON\n",
54+
"### Create Ontology From Normalized Data\n",
5555
"* Users can create ontologies from a json definition of the ontology\n",
5656
"* See below `OntologyBuilder` section for more details on constructing the normalized ontology"
5757
]
@@ -65,14 +65,14 @@
6565
"source": [
6666
"# This will automatically create new root schema node\n",
6767
"ontology_name = \"sdk-ontology\"\n",
68-
"root_schema_node_cat_normalized_json = {\n",
68+
"root_schema_node_cat_normalized = {\n",
6969
" 'tool': 'polygon', \n",
7070
" 'name': 'cat', \n",
7171
" 'color': 'black'\n",
7272
"}\n",
7373
"\n",
74-
"ontology_normalized_json = {\"tools\" : [root_schema_node_cat_normalized_json], \"classifications\" : []}\n",
75-
"ontology = client.create_ontology(name = ontology_name, normalized_json = ontology_normalized_json)\n",
74+
"ontology_normalized_json = {\"tools\" : [root_schema_node_cat_normalized], \"classifications\" : []}\n",
75+
"ontology = client.create_ontology(name = ontology_name, normalized = ontology_normalized_json)\n",
7676
"print(ontology)"
7777
]
7878
},
@@ -94,8 +94,9 @@
9494
"outputs": [],
9595
"source": [
9696
"# First create the root schema node\n",
97-
"root_schema_node_cat = client.create_root_schema_node(root_schema_node_cat_normalized_json)\n",
97+
"root_schema_node_cat = client.create_root_schema_node(root_schema_node_cat_normalized)\n",
9898
"# When we create the ontology it will not re-create the schema node\n",
99+
"print(root_schema_node_cat.uid)\n",
99100
"ontology = client.create_ontology_from_root_schema_nodes(ontology_name, [root_schema_node_cat.uid])"
100101
]
101102
},
@@ -118,13 +119,13 @@
118119
"outputs": [],
119120
"source": [
120121
"# Create new dog schema id \n",
121-
"root_schema_node_dog_normalized_json = {\n",
122+
"root_schema_node_dog_normalized = {\n",
122123
" 'tool': 'polygon', \n",
123124
" 'name': 'dog', \n",
124125
" 'color': 'black', \n",
125126
" 'classifications': [], \n",
126127
"}\n",
127-
"root_schema_node_dog = client.create_root_schema_node(root_schema_node_cat_normalized_json)\n",
128+
"root_schema_node_dog = client.create_root_schema_node(root_schema_node_dog_normalized)\n",
128129
"# The cat is shared between this new ontology and the one we created previously \n",
129130
"# (ie. the cat root schema node will not be re-created)\n",
130131
"ontology = client.create_ontology(ontology_name, [root_schema_node_cat.uid, root_schema_node_dog.uid])"

labelbox/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def create_ontology_from_root_schema_nodes(self, name,
788788
"""
789789
tools, classifications = [], []
790790
for schema_node_id in root_schema_node_ids:
791-
schema_node = self.get_root_schema_node(root_schema_node_ids)
791+
schema_node = self.get_root_schema_node(schema_node_id)
792792
tool = schema_node.normalized['tool']
793793
try:
794794
Tool.Type(tool)
@@ -801,7 +801,9 @@ def create_ontology_from_root_schema_nodes(self, name,
801801
raise ValueError(
802802
f"Tool `{tool}` not in list of supported tools or classifications."
803803
)
804+
804805
normalized = {'tools': tools, 'classifications': classifications}
806+
print(normalized)
805807
return self.create_ontology(name, normalized)
806808

807809
def create_ontology(self, name, normalized):
@@ -857,8 +859,8 @@ def create_root_schema_node(self, normalized):
857859
# The OntologyBuilder automatically assigns colors when calling asdict() but Tools and Classifications do not.
858860
# So we check here to prevent getting 500 erros
859861

860-
if 'color' not in normalized_json:
862+
if 'color' not in normalized:
861863
raise KeyError("Must provide color.")
862-
params = {'data': {'normalized': json.dumps(normalized_json)}}
864+
params = {'data': {'normalized': json.dumps(normalized)}}
863865
res = self.execute(query_str, params)
864866
return Entity.RootSchemaNode(self, res['upsertRootSchemaNode'])

labelbox/schema/project.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,25 @@ def setup_editor(self, ontology):
429429
Args:
430430
ontology (Ontology): The ontology to attach to the project
431431
"""
432-
labeling_front_end = next(
432+
labeling_frontend = next(
433433
self.client.get_labeling_frontends(
434434
where=Entity.LabelingFrontend.name == "Editor"))
435-
self.labeling_frontend.connect(labeling_front_end)
435+
self.labeling_frontend.connect(labeling_frontend)
436+
437+
LFO = Entity.LabelingFrontendOptions
438+
self.client._create(
439+
LFO, {
440+
LFO.project:
441+
self,
442+
LFO.labeling_frontend:
443+
labeling_frontend,
444+
LFO.customization_options:
445+
json.dumps({
446+
"tools": [],
447+
"classifications": []
448+
})
449+
})
450+
436451
query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){
437452
project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}"""
438453
self.client.execute(query_str, {

0 commit comments

Comments
 (0)