@@ -89,13 +89,20 @@ def get_choice(choices: list[dict[str, Any]], *, choice_id: Optional[str] = None
89
89
return result [0 ]
90
90
91
91
92
- def get_attribute (additionals : list [dict [str , Any ]], * , attribute_id : Optional [str ] = None , attribute_name : Optional [str ] = None ) -> dict [str , Any ]:
92
+ def get_attribute (
93
+ additionals : list [dict [str , Any ]],
94
+ * ,
95
+ attribute_id : Optional [str ] = None ,
96
+ attribute_name : Optional [str ] = None ,
97
+ label : Optional [dict [str , Any ]] = None ,
98
+ ) -> dict [str , Any ]:
93
99
"""
94
100
属性情報を取得します。
95
101
96
102
Args:
97
103
attribute_id: 属性ID
98
104
attribute_name: 属性名(英語)
105
+ label: Noneでなければ、指定したラベルに紐づく属性情報を取得します。
99
106
100
107
Raises:
101
108
ValueError: 'attribute_id'か'attribute_name'の指定方法が間違っている。または引数に合致する属性情報が見つからない。または複数見つかった。
@@ -110,10 +117,19 @@ def get_attribute(additionals: list[dict[str, Any]], *, attribute_id: Optional[s
110
117
else :
111
118
raise ValueError ("'attribute_id'か'attribute_name'のどちらかはNone以外にしてください。" )
112
119
120
+ label_name = None
121
+ if label is not None :
122
+ result = [e for e in result if e ["additional_data_definition_id" ] in label ["additional_data_definitions" ]]
123
+ label_name = get_english_message (label ["label_name" ])
124
+
113
125
if len (result ) == 0 :
114
- raise ValueError (f"属性情報が見つかりませんでした。 :: attribute_id='{ attribute_id } ', attribute_name='{ attribute_name } '" )
126
+ raise ValueError (
127
+ f"属性情報が見つかりませんでした。 :: attribute_id='{ attribute_id } ', attribute_name='{ attribute_name } ', label_name='{ label_name } '"
128
+ )
115
129
if len (result ) > 1 :
116
- raise ValueError (f"属性情報が複数({ len (result )} 件)見つかりました。 :: attribute_id='{ attribute_id } ', attribute_name='{ attribute_name } '" )
130
+ raise ValueError (
131
+ f"属性情報が複数({ len (result )} 件)見つかりました。 :: attribute_id='{ attribute_id } ', attribute_name='{ attribute_name } ', label_name='{ label_name } '" # noqa: E501
132
+ )
117
133
return result [0 ]
118
134
119
135
@@ -159,15 +175,22 @@ def __init__(self, annotation_specs: dict[str, Any]) -> None:
159
175
self .labels = annotation_specs ["labels" ]
160
176
self .additionals = annotation_specs ["additionals" ]
161
177
162
- def get_attribute (self , * , attribute_id : Optional [str ] = None , attribute_name : Optional [str ] = None ) -> dict [str , Any ]:
178
+ def get_attribute (
179
+ self , * , attribute_id : Optional [str ] = None , attribute_name : Optional [str ] = None , label : Optional [dict [str , Any ]] = None
180
+ ) -> dict [str , Any ]:
163
181
"""
164
182
属性情報を取得します。
165
183
166
184
Args:
167
185
attribute_id: 属性ID
168
186
attribute_name: 属性名(英語)
187
+ label: Noneでなければ、指定したラベルに紐づく属性情報を取得します。
188
+
189
+ Raises:
190
+ ValueError: 'attribute_id'か'attribute_name'の指定方法が間違っている。または引数に合致する属性情報が見つからない。または複数見つかった。
191
+
169
192
"""
170
- return get_attribute (self .additionals , attribute_id = attribute_id , attribute_name = attribute_name )
193
+ return get_attribute (self .additionals , attribute_id = attribute_id , attribute_name = attribute_name , label = label )
171
194
172
195
def get_label (self , * , label_id : Optional [str ] = None , label_name : Optional [str ] = None ) -> dict [str , Any ]:
173
196
"""
@@ -176,5 +199,9 @@ def get_label(self, *, label_id: Optional[str] = None, label_name: Optional[str]
176
199
Args:
177
200
label_id: ラベルID
178
201
label_name: ラベル名(英語)
202
+
203
+ Raises:
204
+ ValueError: 'label_id'か'label_name'の指定方法が間違っている。または引数に合致するラベル情報が見つからない。または複数見つかった。
205
+
179
206
"""
180
207
return get_label (self .labels , label_id = label_id , label_name = label_name )
0 commit comments