1- import abc
21from dataclasses import dataclass , field
3- from enum import Enum , auto
2+ from enum import Enum
43import colorsys
54
6- from typing import Any , Callable , Dict , List , Optional , Union
5+ from typing import Any , Dict , List , Optional , Union
76
87from labelbox .schema .project import Project
9- from labelbox .orm import query
10- from labelbox .orm .db_object import DbObject , Updateable , BulkDeletable
11- from labelbox .orm .model import Entity , Field , Relationship
12- from labelbox .utils import snake_case , camel_case
8+ from labelbox .orm .db_object import DbObject
9+ from labelbox .orm .model import Field , Relationship
1310from labelbox .exceptions import InconsistentOntologyException
1411
1512
@@ -41,13 +38,11 @@ def label(self):
4138
4239 @classmethod
4340 def from_dict (cls , dictionary : Dict [str , Any ]):
44- return Option (value = dictionary ["value" ],
45- schema_id = dictionary .get ("schemaNodeId" , None ),
46- feature_schema_id = dictionary .get ("featureSchemaId" , None ),
47- options = [
48- Classification .from_dict (o )
49- for o in dictionary .get ("options" , [])
50- ])
41+ return cls (
42+ value = dictionary ["value" ],
43+ schema_id = dictionary .get ("schemaNodeId" , None ),
44+ feature_schema_id = dictionary .get ("featureSchemaId" , None ),
45+ options = [cls .from_dict (o ) for o in dictionary .get ("options" , [])])
5146
5247 def asdict (self ) -> Dict [str , Any ]:
5348 return {
@@ -120,16 +115,15 @@ def name(self):
120115
121116 @classmethod
122117 def from_dict (cls , dictionary : Dict [str , Any ]):
123- return Classification (
124- class_type = Classification .Type (dictionary ["type" ]),
125- instructions = dictionary ["instructions" ],
126- required = dictionary .get ("required" , False ),
127- options = [Option .from_dict (o ) for o in dictionary ["options" ]],
128- schema_id = dictionary .get ("schemaNodeId" , None ),
129- feature_schema_id = dictionary .get ("featureSchemaId" , None ))
118+ return cls (class_type = cls .Type (dictionary ["type" ]),
119+ instructions = dictionary ["instructions" ],
120+ required = dictionary .get ("required" , False ),
121+ options = [Option .from_dict (o ) for o in dictionary ["options" ]],
122+ schema_id = dictionary .get ("schemaNodeId" , None ),
123+ feature_schema_id = dictionary .get ("featureSchemaId" , None ))
130124
131125 def asdict (self ) -> Dict [str , Any ]:
132- if self .class_type in Classification ._REQUIRES_OPTIONS \
126+ if self .class_type in self ._REQUIRES_OPTIONS \
133127 and len (self .options ) < 1 :
134128 raise InconsistentOntologyException (
135129 f"Classification '{ self .instructions } ' requires options." )
@@ -200,16 +194,16 @@ class Type(Enum):
200194
201195 @classmethod
202196 def from_dict (cls , dictionary : Dict [str , Any ]):
203- return Tool (name = dictionary ['name' ],
204- schema_id = dictionary .get ("schemaNodeId" , None ),
205- feature_schema_id = dictionary .get ("featureSchemaId" , None ),
206- required = dictionary .get ("required" , False ),
207- tool = Tool .Type (dictionary ["tool" ]),
208- classifications = [
209- Classification .from_dict (c )
210- for c in dictionary ["classifications" ]
211- ],
212- color = dictionary ["color" ])
197+ return cls (name = dictionary ['name' ],
198+ schema_id = dictionary .get ("schemaNodeId" , None ),
199+ feature_schema_id = dictionary .get ("featureSchemaId" , None ),
200+ required = dictionary .get ("required" , False ),
201+ tool = cls .Type (dictionary ["tool" ]),
202+ classifications = [
203+ Classification .from_dict (c )
204+ for c in dictionary ["classifications" ]
205+ ],
206+ color = dictionary ["color" ])
213207
214208 def asdict (self ) -> Dict [str , Any ]:
215209 return {
@@ -310,12 +304,11 @@ class OntologyBuilder:
310304
311305 @classmethod
312306 def from_dict (cls , dictionary : Dict [str , Any ]):
313- return OntologyBuilder (
314- tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
315- classifications = [
316- Classification .from_dict (c )
317- for c in dictionary ["classifications" ]
318- ])
307+ return cls (tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
308+ classifications = [
309+ Classification .from_dict (c )
310+ for c in dictionary ["classifications" ]
311+ ])
319312
320313 def asdict (self ):
321314 self ._update_colors ()
@@ -337,7 +330,7 @@ def _update_colors(self):
337330 @classmethod
338331 def from_project (cls , project : Project ):
339332 ontology = project .ontology ().normalized
340- return OntologyBuilder .from_dict (ontology )
333+ return cls .from_dict (ontology )
341334
342335 def add_tool (self , tool : Tool ):
343336 if tool .name in (t .name for t in self .tools ):
0 commit comments