|
23 | 23 | import pytest
|
24 | 24 |
|
25 | 25 |
|
26 |
| -def test_schema_assignment_geometry(): |
27 |
| - name = "line_feature" |
28 |
| - label = Label( |
29 |
| - data=MaskData( |
30 |
| - arr=np.ones((32, 32, 3), dtype=np.uint8), global_key="test" |
31 |
| - ), |
32 |
| - annotations=[ |
33 |
| - ObjectAnnotation( |
34 |
| - value=Line(points=[Point(x=1, y=2), Point(x=2, y=2)]), |
35 |
| - name=name, |
36 |
| - ) |
37 |
| - ], |
38 |
| - ) |
39 |
| - feature_schema_id = "expected_id" |
40 |
| - ontology = OntologyBuilder( |
41 |
| - tools=[ |
42 |
| - Tool(Tool.Type.LINE, name=name, feature_schema_id=feature_schema_id) |
43 |
| - ] |
44 |
| - ) |
45 |
| - label.assign_feature_schema_ids(ontology) |
46 |
| - |
47 |
| - assert label.annotations[0].feature_schema_id == feature_schema_id |
48 |
| - |
49 |
| - |
50 |
| -def test_schema_assignment_classification(): |
51 |
| - radio_name = "radio_name" |
52 |
| - text_name = "text_name" |
53 |
| - option_name = "my_option" |
54 |
| - |
55 |
| - label = Label( |
56 |
| - data=MaskData(arr=np.ones((32, 32, 3), dtype=np.uint8), uid="test"), |
57 |
| - annotations=[ |
58 |
| - ClassificationAnnotation( |
59 |
| - value=Radio(answer=ClassificationAnswer(name=option_name)), |
60 |
| - name=radio_name, |
61 |
| - ), |
62 |
| - ClassificationAnnotation( |
63 |
| - value=Text(answer="some text"), name=text_name |
64 |
| - ), |
65 |
| - ], |
66 |
| - ) |
67 |
| - radio_schema_id = "radio_schema_id" |
68 |
| - text_schema_id = "text_schema_id" |
69 |
| - option_schema_id = "option_schema_id" |
70 |
| - ontology = OntologyBuilder( |
71 |
| - tools=[], |
72 |
| - classifications=[ |
73 |
| - OClassification( |
74 |
| - class_type=OClassification.Type.RADIO, |
75 |
| - name=radio_name, |
76 |
| - feature_schema_id=radio_schema_id, |
77 |
| - options=[ |
78 |
| - Option( |
79 |
| - value=option_name, feature_schema_id=option_schema_id |
80 |
| - ) |
81 |
| - ], |
82 |
| - ), |
83 |
| - OClassification( |
84 |
| - class_type=OClassification.Type.TEXT, |
85 |
| - name=text_name, |
86 |
| - feature_schema_id=text_schema_id, |
87 |
| - ), |
88 |
| - ], |
89 |
| - ) |
90 |
| - label.assign_feature_schema_ids(ontology) |
91 |
| - assert label.annotations[0].feature_schema_id == radio_schema_id |
92 |
| - assert label.annotations[1].feature_schema_id == text_schema_id |
93 |
| - assert ( |
94 |
| - label.annotations[0].value.answer.feature_schema_id == option_schema_id |
95 |
| - ) |
96 |
| - |
97 |
| - |
98 |
| -def test_schema_assignment_subclass(): |
99 |
| - name = "line_feature" |
100 |
| - radio_name = "radio_name" |
101 |
| - option_name = "my_option" |
102 |
| - classification = ClassificationAnnotation( |
103 |
| - name=radio_name, |
104 |
| - value=Radio(answer=ClassificationAnswer(name=option_name)), |
105 |
| - ) |
106 |
| - label = Label( |
107 |
| - data=MaskData(arr=np.ones((32, 32, 3), dtype=np.uint8), uid="test"), |
108 |
| - annotations=[ |
109 |
| - ObjectAnnotation( |
110 |
| - value=Line(points=[Point(x=1, y=2), Point(x=2, y=2)]), |
111 |
| - name=name, |
112 |
| - classifications=[classification], |
113 |
| - ) |
114 |
| - ], |
115 |
| - ) |
116 |
| - feature_schema_id = "expected_id" |
117 |
| - classification_schema_id = "classification_id" |
118 |
| - option_schema_id = "option_schema_id" |
119 |
| - ontology = OntologyBuilder( |
120 |
| - tools=[ |
121 |
| - Tool( |
122 |
| - Tool.Type.LINE, |
123 |
| - name=name, |
124 |
| - feature_schema_id=feature_schema_id, |
125 |
| - classifications=[ |
126 |
| - OClassification( |
127 |
| - class_type=OClassification.Type.RADIO, |
128 |
| - name=radio_name, |
129 |
| - feature_schema_id=classification_schema_id, |
130 |
| - options=[ |
131 |
| - Option( |
132 |
| - value=option_name, |
133 |
| - feature_schema_id=option_schema_id, |
134 |
| - ) |
135 |
| - ], |
136 |
| - ) |
137 |
| - ], |
138 |
| - ) |
139 |
| - ] |
140 |
| - ) |
141 |
| - label.assign_feature_schema_ids(ontology) |
142 |
| - assert label.annotations[0].feature_schema_id == feature_schema_id |
143 |
| - assert ( |
144 |
| - label.annotations[0].classifications[0].feature_schema_id |
145 |
| - == classification_schema_id |
146 |
| - ) |
147 |
| - assert ( |
148 |
| - label.annotations[0].classifications[0].value.answer.feature_schema_id |
149 |
| - == option_schema_id |
150 |
| - ) |
151 |
| - |
152 |
| - |
153 |
| -def test_highly_nested(): |
154 |
| - name = "line_feature" |
155 |
| - radio_name = "radio_name" |
156 |
| - nested_name = "nested_name" |
157 |
| - option_name = "my_option" |
158 |
| - nested_option_name = "nested_option_name" |
159 |
| - classification = ClassificationAnnotation( |
160 |
| - name=radio_name, |
161 |
| - value=Radio(answer=ClassificationAnswer(name=option_name)), |
162 |
| - classifications=[ |
163 |
| - ClassificationAnnotation( |
164 |
| - value=Radio( |
165 |
| - answer=ClassificationAnswer(name=nested_option_name) |
166 |
| - ), |
167 |
| - name=nested_name, |
168 |
| - ) |
169 |
| - ], |
170 |
| - ) |
171 |
| - label = Label( |
172 |
| - data=MaskData( |
173 |
| - arr=np.ones((32, 32, 3), dtype=np.uint8), global_key="test" |
174 |
| - ), |
175 |
| - annotations=[ |
176 |
| - ObjectAnnotation( |
177 |
| - value=Line(points=[Point(x=1, y=2), Point(x=2, y=2)]), |
178 |
| - name=name, |
179 |
| - classifications=[classification], |
180 |
| - ) |
181 |
| - ], |
182 |
| - ) |
183 |
| - feature_schema_id = "expected_id" |
184 |
| - classification_schema_id = "classification_id" |
185 |
| - nested_classification_schema_id = "nested_classification_schema_id" |
186 |
| - option_schema_id = "option_schema_id" |
187 |
| - ontology = OntologyBuilder( |
188 |
| - tools=[ |
189 |
| - Tool( |
190 |
| - Tool.Type.LINE, |
191 |
| - name=name, |
192 |
| - feature_schema_id=feature_schema_id, |
193 |
| - classifications=[ |
194 |
| - OClassification( |
195 |
| - class_type=OClassification.Type.RADIO, |
196 |
| - name=radio_name, |
197 |
| - feature_schema_id=classification_schema_id, |
198 |
| - options=[ |
199 |
| - Option( |
200 |
| - value=option_name, |
201 |
| - feature_schema_id=option_schema_id, |
202 |
| - options=[ |
203 |
| - OClassification( |
204 |
| - class_type=OClassification.Type.RADIO, |
205 |
| - name=nested_name, |
206 |
| - feature_schema_id=nested_classification_schema_id, |
207 |
| - options=[ |
208 |
| - Option( |
209 |
| - value=nested_option_name, |
210 |
| - feature_schema_id=nested_classification_schema_id, |
211 |
| - ) |
212 |
| - ], |
213 |
| - ) |
214 |
| - ], |
215 |
| - ) |
216 |
| - ], |
217 |
| - ) |
218 |
| - ], |
219 |
| - ) |
220 |
| - ] |
221 |
| - ) |
222 |
| - label.assign_feature_schema_ids(ontology) |
223 |
| - assert label.annotations[0].feature_schema_id == feature_schema_id |
224 |
| - assert ( |
225 |
| - label.annotations[0].classifications[0].feature_schema_id |
226 |
| - == classification_schema_id |
227 |
| - ) |
228 |
| - assert ( |
229 |
| - label.annotations[0].classifications[0].value.answer.feature_schema_id |
230 |
| - == option_schema_id |
231 |
| - ) |
232 |
| - |
233 |
| - |
234 | 26 | def test_schema_assignment_confidence():
|
235 | 27 | name = "line_feature"
|
236 | 28 | label = Label(
|
|
0 commit comments