1
- import abc
2
1
from dataclasses import dataclass , field
3
- from enum import Enum , auto
2
+ from enum import Enum
4
3
import colorsys
5
4
6
- from typing import Any , Callable , Dict , List , Optional , Union
5
+ from typing import Any , Dict , List , Optional , Union
7
6
8
7
from 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
13
10
from labelbox .exceptions import InconsistentOntologyException
14
11
15
12
@@ -41,13 +38,11 @@ def label(self):
41
38
42
39
@classmethod
43
40
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" , [])])
51
46
52
47
def asdict (self ) -> Dict [str , Any ]:
53
48
return {
@@ -120,16 +115,15 @@ def name(self):
120
115
121
116
@classmethod
122
117
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 ))
130
124
131
125
def asdict (self ) -> Dict [str , Any ]:
132
- if self .class_type in Classification ._REQUIRES_OPTIONS \
126
+ if self .class_type in self ._REQUIRES_OPTIONS \
133
127
and len (self .options ) < 1 :
134
128
raise InconsistentOntologyException (
135
129
f"Classification '{ self .instructions } ' requires options." )
@@ -200,16 +194,16 @@ class Type(Enum):
200
194
201
195
@classmethod
202
196
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" ])
213
207
214
208
def asdict (self ) -> Dict [str , Any ]:
215
209
return {
@@ -310,12 +304,11 @@ class OntologyBuilder:
310
304
311
305
@classmethod
312
306
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
+ ])
319
312
320
313
def asdict (self ):
321
314
self ._update_colors ()
@@ -337,7 +330,7 @@ def _update_colors(self):
337
330
@classmethod
338
331
def from_project (cls , project : Project ):
339
332
ontology = project .ontology ().normalized
340
- return OntologyBuilder .from_dict (ontology )
333
+ return cls .from_dict (ontology )
341
334
342
335
def add_tool (self , tool : Tool ):
343
336
if tool .name in (t .name for t in self .tools ):
0 commit comments