17
17
class Option :
18
18
"""
19
19
An option is a possible answer within a Classification object in
20
- a Project's ontology.
20
+ a Project's ontology.
21
21
22
22
To instantiate, only the "value" parameter needs to be passed in.
23
23
@@ -41,11 +41,11 @@ def label(self):
41
41
42
42
@classmethod
43
43
def from_dict (cls , dictionary : Dict [str , Any ]):
44
- return Option (value = dictionary ["value" ],
44
+ return cls (value = dictionary ["value" ],
45
45
schema_id = dictionary .get ("schemaNodeId" , None ),
46
46
feature_schema_id = dictionary .get ("featureSchemaId" , None ),
47
47
options = [
48
- Classification .from_dict (o )
48
+ cls .from_dict (o )
49
49
for o in dictionary .get ("options" , [])
50
50
])
51
51
@@ -69,13 +69,13 @@ def add_option(self, option: 'Classification'):
69
69
@dataclass
70
70
class Classification :
71
71
"""
72
- A classfication to be added to a Project's ontology. The
72
+ A classfication to be added to a Project's ontology. The
73
73
classification is dependent on the Classification Type.
74
74
75
75
To instantiate, the "class_type" and "instructions" parameters must
76
76
be passed in.
77
77
78
- The "options" parameter holds a list of Option objects. This is not
78
+ The "options" parameter holds a list of Option objects. This is not
79
79
necessary for some Classification types, such as TEXT. To see which
80
80
types require options, look at the "_REQUIRES_OPTIONS" class variable.
81
81
@@ -120,16 +120,16 @@ def name(self):
120
120
121
121
@classmethod
122
122
def from_dict (cls , dictionary : Dict [str , Any ]):
123
- return Classification (
124
- class_type = Classification .Type (dictionary ["type" ]),
123
+ return cls (
124
+ class_type = cls .Type (dictionary ["type" ]),
125
125
instructions = dictionary ["instructions" ],
126
126
required = dictionary .get ("required" , False ),
127
127
options = [Option .from_dict (o ) for o in dictionary ["options" ]],
128
128
schema_id = dictionary .get ("schemaNodeId" , None ),
129
129
feature_schema_id = dictionary .get ("featureSchemaId" , None ))
130
130
131
131
def asdict (self ) -> Dict [str , Any ]:
132
- if self .class_type in Classification ._REQUIRES_OPTIONS \
132
+ if self .class_type in self ._REQUIRES_OPTIONS \
133
133
and len (self .options ) < 1 :
134
134
raise InconsistentOntologyException (
135
135
f"Classification '{ self .instructions } ' requires options." )
@@ -160,13 +160,13 @@ class Tool:
160
160
To instantiate, the "tool" and "name" parameters must
161
161
be passed in.
162
162
163
- The "classifications" parameter holds a list of Classification objects.
163
+ The "classifications" parameter holds a list of Classification objects.
164
164
This can be used to add nested classifications to a tool.
165
165
166
166
Example(s):
167
167
tool = Tool(
168
168
tool = Tool.Type.LINE,
169
- name = "Tool example")
169
+ name = "Tool example")
170
170
classification = Classification(
171
171
class_type = Classification.Type.TEXT,
172
172
instructions = "Classification Example")
@@ -200,11 +200,11 @@ class Type(Enum):
200
200
201
201
@classmethod
202
202
def from_dict (cls , dictionary : Dict [str , Any ]):
203
- return Tool (name = dictionary ['name' ],
203
+ return cls (name = dictionary ['name' ],
204
204
schema_id = dictionary .get ("schemaNodeId" , None ),
205
205
feature_schema_id = dictionary .get ("featureSchemaId" , None ),
206
206
required = dictionary .get ("required" , False ),
207
- tool = Tool .Type (dictionary ["tool" ]),
207
+ tool = cls .Type (dictionary ["tool" ]),
208
208
classifications = [
209
209
Classification .from_dict (c )
210
210
for c in dictionary ["classifications" ]
@@ -287,9 +287,9 @@ class OntologyBuilder:
287
287
for making Project ontologies from scratch. OntologyBuilder can also
288
288
pull from an already existing Project's ontology.
289
289
290
- There are no required instantiation arguments.
290
+ There are no required instantiation arguments.
291
291
292
- To create an ontology, use the asdict() method after fully building your
292
+ To create an ontology, use the asdict() method after fully building your
293
293
ontology within this class, and inserting it into project.setup() as the
294
294
"labeling_frontend_options" parameter.
295
295
@@ -303,14 +303,14 @@ class OntologyBuilder:
303
303
tools: (list)
304
304
classifications: (list)
305
305
306
-
306
+
307
307
"""
308
308
tools : List [Tool ] = field (default_factory = list )
309
309
classifications : List [Classification ] = field (default_factory = list )
310
310
311
311
@classmethod
312
312
def from_dict (cls , dictionary : Dict [str , Any ]):
313
- return OntologyBuilder (
313
+ return cls (
314
314
tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
315
315
classifications = [
316
316
Classification .from_dict (c )
@@ -337,7 +337,7 @@ def _update_colors(self):
337
337
@classmethod
338
338
def from_project (cls , project : Project ):
339
339
ontology = project .ontology ().normalized
340
- return OntologyBuilder .from_dict (ontology )
340
+ return cls .from_dict (ontology )
341
341
342
342
def add_tool (self , tool : Tool ):
343
343
if tool .name in (t .name for t in self .tools ):
0 commit comments