def test_annotations_filter_can_remove_empty_items(self): class SrcExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=0), DatasetItem(id=1, annotations=[ Label(0), Label(1), ]), DatasetItem(id=2, annotations=[ Label(0), Label(2), ]), ]) class DstExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=2, annotations=[ Label(2), ]), ]) extractor = SrcExtractor() filtered = XPathAnnotationsFilter(extractor, '/item/annotation[label_id = 2]', remove_empty=True) self.assertListEqual(list(filtered), list(DstExtractor()))
def test_annotations_filter_can_remove_empty_items(self): source = Dataset.from_iterable([ DatasetItem(id=0), DatasetItem(id=1, annotations=[ Label(0), Label(1), ]), DatasetItem(id=2, annotations=[ Label(0), Label(2), ]), ], categories=['a', 'b', 'c']) expected = Dataset.from_iterable([ DatasetItem(id=2, annotations=[Label(2)]), ], categories=['a', 'b', 'c']) filtered = XPathAnnotationsFilter(source, '/item/annotation[label_id = 2]', remove_empty=True) compare_datasets(self, expected, filtered)