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