@@ -76,14 +76,15 @@ class UIMode(Enum):
76
76
None # How this classification should be answered (e.g. hotkeys / autocomplete, etc)
77
77
)
78
78
attributes : Optional [FeatureSchemaAttributes ] = None
79
+ is_likert_scale : bool = False
79
80
80
81
def __post_init__ (self ):
81
82
if self .name is None :
82
83
msg = (
83
- " When creating the Classification feature, please use “ name” "
84
+ ' When creating the Classification feature, please use " name" '
84
85
"for the classification schema name, which will be used when "
85
86
"creating annotation payload for Model-Assisted Labeling "
86
- " Import and Label Import. “ instructions” is no longer "
87
+ ' Import and Label Import. " instructions" is no longer '
87
88
"supported to specify classification schema name."
88
89
)
89
90
if self .instructions is not None :
@@ -119,6 +120,7 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> "Classification":
119
120
]
120
121
if dictionary .get ("attributes" )
121
122
else None ,
123
+ is_likert_scale = dictionary .get ("isLikertScale" , False ),
122
124
)
123
125
124
126
def asdict (self , is_subclass : bool = False ) -> Dict [str , Any ]:
@@ -138,6 +140,9 @@ def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
138
140
if self .attributes is not None
139
141
else None ,
140
142
}
143
+ if self .class_type == self .Type .RADIO and self .is_likert_scale :
144
+ # is_likert_scale is only applicable to RADIO classifications
145
+ classification ["isLikertScale" ] = self .is_likert_scale
141
146
if (
142
147
self .class_type == self .Type .RADIO
143
148
or self .class_type == self .Type .CHECKLIST
@@ -159,6 +164,9 @@ def add_option(self, option: "Option") -> None:
159
164
f"Duplicate option '{ option .value } ' "
160
165
f"for classification '{ self .name } '."
161
166
)
167
+ # Auto-assign position if not set
168
+ if option .position is None :
169
+ option .position = len (self .options )
162
170
self .options .append (option )
163
171
164
172
@@ -178,6 +186,7 @@ class Option:
178
186
schema_id: (str)
179
187
feature_schema_id: (str)
180
188
options: (list)
189
+ position: (int) - Position of the option, auto-assigned starting from 0
181
190
"""
182
191
183
192
value : Union [str , int ]
@@ -187,6 +196,7 @@ class Option:
187
196
options : Union [
188
197
List ["Classification" ], List ["PromptResponseClassification" ]
189
198
] = field (default_factory = list )
199
+ position : Optional [int ] = None
190
200
191
201
def __post_init__ (self ):
192
202
if self .label is None :
@@ -203,16 +213,20 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> "Option":
203
213
Classification .from_dict (o )
204
214
for o in dictionary .get ("options" , [])
205
215
],
216
+ position = dictionary .get ("position" , None ),
206
217
)
207
218
208
219
def asdict (self ) -> Dict [str , Any ]:
209
- return {
220
+ result = {
210
221
"schemaNodeId" : self .schema_id ,
211
222
"featureSchemaId" : self .feature_schema_id ,
212
223
"label" : self .label ,
213
224
"value" : self .value ,
214
225
"options" : [o .asdict (is_subclass = True ) for o in self .options ],
215
226
}
227
+ if self .position is not None :
228
+ result ["position" ] = self .position
229
+ return result
216
230
217
231
def add_option (
218
232
self , option : Union ["Classification" , "PromptResponseClassification" ]
@@ -268,10 +282,10 @@ class PromptResponseClassification:
268
282
def __post_init__ (self ):
269
283
if self .name is None :
270
284
msg = (
271
- " When creating the Classification feature, please use “ name” "
285
+ ' When creating the Classification feature, please use " name" '
272
286
"for the classification schema name, which will be used when "
273
287
"creating annotation payload for Model-Assisted Labeling "
274
- " Import and Label Import. “ instructions” is no longer "
288
+ ' Import and Label Import. " instructions" is no longer '
275
289
"supported to specify classification schema name."
276
290
)
277
291
if self .instructions is not None :
0 commit comments