@@ -40,13 +40,11 @@ def label(self):
40
40
41
41
@classmethod
42
42
def from_dict (cls , dictionary : Dict [str , Any ]):
43
- return Option (value = dictionary ["value" ],
44
- schema_id = dictionary .get ("schemaNodeId" , None ),
45
- feature_schema_id = dictionary .get ("featureSchemaId" , None ),
46
- options = [
47
- Classification .from_dict (o )
48
- for o in dictionary .get ("options" , [])
49
- ])
43
+ return cls (
44
+ value = dictionary ["value" ],
45
+ schema_id = dictionary .get ("schemaNodeId" , None ),
46
+ feature_schema_id = dictionary .get ("featureSchemaId" , None ),
47
+ options = [cls .from_dict (o ) for o in dictionary .get ("options" , [])])
50
48
51
49
def asdict (self ) -> Dict [str , Any ]:
52
50
return {
@@ -119,16 +117,15 @@ def name(self):
119
117
120
118
@classmethod
121
119
def from_dict (cls , dictionary : Dict [str , Any ]):
122
- return Classification (
123
- class_type = Classification .Type (dictionary ["type" ]),
124
- instructions = dictionary ["instructions" ],
125
- required = dictionary .get ("required" , False ),
126
- options = [Option .from_dict (o ) for o in dictionary ["options" ]],
127
- schema_id = dictionary .get ("schemaNodeId" , None ),
128
- feature_schema_id = dictionary .get ("featureSchemaId" , None ))
120
+ return cls (class_type = cls .Type (dictionary ["type" ]),
121
+ instructions = dictionary ["instructions" ],
122
+ required = dictionary .get ("required" , False ),
123
+ options = [Option .from_dict (o ) for o in dictionary ["options" ]],
124
+ schema_id = dictionary .get ("schemaNodeId" , None ),
125
+ feature_schema_id = dictionary .get ("featureSchemaId" , None ))
129
126
130
127
def asdict (self ) -> Dict [str , Any ]:
131
- if self .class_type in Classification ._REQUIRES_OPTIONS \
128
+ if self .class_type in self ._REQUIRES_OPTIONS \
132
129
and len (self .options ) < 1 :
133
130
raise InconsistentOntologyException (
134
131
f"Classification '{ self .instructions } ' requires options." )
@@ -199,16 +196,16 @@ class Type(Enum):
199
196
200
197
@classmethod
201
198
def from_dict (cls , dictionary : Dict [str , Any ]):
202
- return Tool (name = dictionary ['name' ],
203
- schema_id = dictionary .get ("schemaNodeId" , None ),
204
- feature_schema_id = dictionary .get ("featureSchemaId" , None ),
205
- required = dictionary .get ("required" , False ),
206
- tool = Tool .Type (dictionary ["tool" ]),
207
- classifications = [
208
- Classification .from_dict (c )
209
- for c in dictionary ["classifications" ]
210
- ],
211
- color = dictionary ["color" ])
199
+ return cls (name = dictionary ['name' ],
200
+ schema_id = dictionary .get ("schemaNodeId" , None ),
201
+ feature_schema_id = dictionary .get ("featureSchemaId" , None ),
202
+ required = dictionary .get ("required" , False ),
203
+ tool = cls .Type (dictionary ["tool" ]),
204
+ classifications = [
205
+ Classification .from_dict (c )
206
+ for c in dictionary ["classifications" ]
207
+ ],
208
+ color = dictionary ["color" ])
212
209
213
210
def asdict (self ) -> Dict [str , Any ]:
214
211
return {
@@ -309,12 +306,11 @@ class OntologyBuilder:
309
306
310
307
@classmethod
311
308
def from_dict (cls , dictionary : Dict [str , Any ]):
312
- return OntologyBuilder (
313
- tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
314
- classifications = [
315
- Classification .from_dict (c )
316
- for c in dictionary ["classifications" ]
317
- ])
309
+ return cls (tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
310
+ classifications = [
311
+ Classification .from_dict (c )
312
+ for c in dictionary ["classifications" ]
313
+ ])
318
314
319
315
def asdict (self ):
320
316
self ._update_colors ()
@@ -336,7 +332,7 @@ def _update_colors(self):
336
332
@classmethod
337
333
def from_project (cls , project : "Project" ):
338
334
ontology = project .ontology ().normalized
339
- return OntologyBuilder .from_dict (ontology )
335
+ return cls .from_dict (ontology )
340
336
341
337
def add_tool (self , tool : Tool ):
342
338
if tool .name in (t .name for t in self .tools ):
0 commit comments