@@ -662,10 +662,13 @@ def test_document_extend_from_other_full_copy(text_document):
662
662
"relation_attributes" ,
663
663
"labels" ,
664
664
}
665
- for layer_name , annotation_set in added_annotations .items ():
666
- assert len (annotation_set ) > 0
665
+ for layer_name , annotation_mapping in added_annotations .items ():
666
+ assert len (annotation_mapping ) > 0
667
667
available_annotations = text_document [layer_name ]
668
- assert annotation_set == list (available_annotations )
668
+ assert set (annotation_mapping ) == set (available_annotations )
669
+ assert len (annotation_mapping ) == 1
670
+ # since we have only one annotation, we can construct the expected mapping
671
+ assert annotation_mapping == {available_annotations [0 ]: doc_new [layer_name ][0 ]}
669
672
670
673
671
674
def test_document_extend_from_other_wrong_override_annotation_mapping (text_document ):
@@ -705,12 +708,19 @@ class TestDocument2(TokenBasedDocument):
705
708
added_annotations = token_document .add_all_annotations_from_other (
706
709
text_document , override_annotations = annotation_mapping
707
710
)
711
+ added_annotation_sets = {k : set (v ) for k , v in added_annotations .items ()}
708
712
# check that the added annotations are as expected (the entity annotations are already there)
709
- assert added_annotations == {
710
- "relations" : list (text_document .relations ),
711
- "relation_attributes" : list (text_document .relation_attributes ),
712
- "labels" : list (text_document .labels ),
713
+ assert added_annotation_sets == {
714
+ "relations" : set (text_document .relations ),
715
+ "relation_attributes" : set (text_document .relation_attributes ),
716
+ "labels" : set (text_document .labels ),
713
717
}
718
+ for layer_name , annotation_mapping in added_annotations .items ():
719
+ text_annotations = text_document [layer_name ]
720
+ token_annotations = token_document [layer_name ]
721
+ assert len (annotation_mapping ) == len (text_annotations ) == len (token_annotations ) == 1
722
+ # since we have only one annotation, we can construct the expected mapping
723
+ assert annotation_mapping == {text_annotations [0 ]: token_annotations [0 ]}
714
724
715
725
assert (
716
726
len (token_document .entities1 )
@@ -740,11 +750,15 @@ def test_document_extend_from_other_remove(text_document):
740
750
removed_annotations = {"entities1" : {text_document .entities1 [0 ]._id }},
741
751
strict = False ,
742
752
)
743
-
753
+ added_annotation_sets = { k : set ( v ) for k , v in added_annotations . items ()}
744
754
# the only entity in entities1 is removed and since the relation has it as head, the relation is removed as well
755
+ assert added_annotation_sets == {
756
+ "entities2" : set (text_document .entities2 ),
757
+ "labels" : set (text_document .labels ),
758
+ }
745
759
assert added_annotations == {
746
- "entities2" : list ( text_document .entities2 ) ,
747
- "labels" : list ( text_document .labels ) ,
760
+ "entities2" : { text_document .entities2 [ 0 ]: doc_new . entities2 [ 0 ]} ,
761
+ "labels" : { text_document .labels [ 0 ]: doc_new . labels [ 0 ]} ,
748
762
}
749
763
750
764
assert len (doc_new .entities1 ) == 0
0 commit comments