@@ -124,6 +124,10 @@ class Type(Enum):
124
124
RADIO = "radio"
125
125
DROPDOWN = "dropdown"
126
126
127
+ class Scope (Enum ):
128
+ GLOBAL = "global"
129
+ INDEX = "index"
130
+
127
131
_REQUIRES_OPTIONS = {Type .CHECKLIST , Type .RADIO , Type .DROPDOWN }
128
132
129
133
class_type : Type
@@ -132,6 +136,7 @@ class Type(Enum):
132
136
options : List [Option ] = field (default_factory = list )
133
137
schema_id : Optional [str ] = None
134
138
feature_schema_id : Optional [str ] = None
139
+ scope : Scope = None
135
140
136
141
def __post_init__ (self ):
137
142
if self .class_type == Classification .Type .DROPDOWN :
@@ -151,21 +156,31 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
151
156
required = dictionary .get ("required" , False ),
152
157
options = [Option .from_dict (o ) for o in dictionary ["options" ]],
153
158
schema_id = dictionary .get ("schemaNodeId" , None ),
154
- feature_schema_id = dictionary .get ("featureSchemaId" , None ))
159
+ feature_schema_id = dictionary .get ("featureSchemaId" , None ),
160
+ scope = cls .Scope (dictionary .get ("scope" , cls .Scope .GLOBAL )))
155
161
156
162
def asdict (self ) -> Dict [str , Any ]:
157
163
if self .class_type in self ._REQUIRES_OPTIONS \
158
164
and len (self .options ) < 1 :
159
165
raise InconsistentOntologyException (
160
166
f"Classification '{ self .instructions } ' requires options." )
161
167
return {
162
- "type" : self .class_type .value ,
163
- "instructions" : self .instructions ,
164
- "name" : self .name ,
165
- "required" : self .required ,
168
+ "type" :
169
+ self .class_type .value ,
170
+ "instructions" :
171
+ self .instructions ,
172
+ "name" :
173
+ self .name ,
174
+ "required" :
175
+ self .required ,
166
176
"options" : [o .asdict () for o in self .options ],
167
- "schemaNodeId" : self .schema_id ,
168
- "featureSchemaId" : self .feature_schema_id
177
+ "schemaNodeId" :
178
+ self .schema_id ,
179
+ "featureSchemaId" :
180
+ self .feature_schema_id ,
181
+ "scope" :
182
+ self .scope .value
183
+ if self .scope is not None else self .Scope .GLOBAL .value
169
184
}
170
185
171
186
def add_option (self , option : Option ) -> None :
0 commit comments