@@ -192,3 +192,82 @@ def test_bidirectional_relationship():
192192 )
193193 assert rel_serialized ["relationship" ]["type" ] == "bidirectional"
194194 assert rel_2_serialized ["relationship" ]["type" ] == "bidirectional"
195+
196+
197+ def test_readonly_relationships ():
198+ ner_source = ObjectAnnotation (
199+ name = "e1" ,
200+ value = TextEntity (start = 10 , end = 12 ),
201+ )
202+
203+ ner_target = ObjectAnnotation (
204+ name = "e2" ,
205+ value = TextEntity (start = 30 , end = 35 ),
206+ )
207+
208+ # Test unidirectional relationship with readonly=True
209+ readonly_relationship = RelationshipAnnotation (
210+ name = "readonly_rel" ,
211+ value = Relationship (
212+ source = ner_source ,
213+ target = ner_target ,
214+ type = Relationship .Type .UNIDIRECTIONAL ,
215+ readonly = True ,
216+ ),
217+ )
218+
219+ # Test bidirectional relationship with readonly=False
220+ non_readonly_relationship = RelationshipAnnotation (
221+ name = "non_readonly_rel" ,
222+ value = Relationship (
223+ source = ner_source ,
224+ target = ner_target ,
225+ type = Relationship .Type .BIDIRECTIONAL ,
226+ readonly = False ,
227+ ),
228+ )
229+
230+ label = Label (
231+ data = {"uid" : "clqbkpy236syk07978v3pscw1" },
232+ annotations = [
233+ ner_source ,
234+ ner_target ,
235+ readonly_relationship ,
236+ non_readonly_relationship ,
237+ ],
238+ )
239+
240+ serialized_label = list (NDJsonConverter .serialize ([label ]))
241+
242+ ner_source_serialized = next (
243+ annotation
244+ for annotation in serialized_label
245+ if annotation ["name" ] == ner_source .name
246+ )
247+ ner_target_serialized = next (
248+ annotation
249+ for annotation in serialized_label
250+ if annotation ["name" ] == ner_target .name
251+ )
252+ readonly_rel_serialized = next (
253+ annotation
254+ for annotation in serialized_label
255+ if annotation ["name" ] == readonly_relationship .name
256+ )
257+ non_readonly_rel_serialized = next (
258+ annotation
259+ for annotation in serialized_label
260+ if annotation ["name" ] == non_readonly_relationship .name
261+ )
262+
263+ # Verify readonly relationship
264+ assert readonly_rel_serialized ["relationship" ]["source" ] == ner_source_serialized ["uuid" ]
265+ assert readonly_rel_serialized ["relationship" ]["target" ] == ner_target_serialized ["uuid" ]
266+ assert readonly_rel_serialized ["relationship" ]["type" ] == "unidirectional"
267+ assert readonly_rel_serialized ["relationship" ]["readonly" ] is True
268+
269+ # Verify non-readonly relationship
270+ assert non_readonly_rel_serialized ["relationship" ]["source" ] == ner_source_serialized ["uuid" ]
271+ assert non_readonly_rel_serialized ["relationship" ]["target" ] == ner_target_serialized ["uuid" ]
272+ assert non_readonly_rel_serialized ["relationship" ]["type" ] == "bidirectional"
273+ assert non_readonly_rel_serialized ["relationship" ]["readonly" ] is False
0 commit comments