Code Duplication    Length = 31-31 lines in 6 locations

src/ocrd_page_user_methods/invalidate_AlternativeImage.py 1 location

@@ 1-31 (lines=31) @@
1
def invalidate_AlternativeImage(self, feature_selector=None):
2
    """
3
    Remove derived images from this segment (due to changed coordinates).
4
5
    If `feature_selector` is not none, remove only images with
6
    matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
7
    """
8
    existing_images = self.AlternativeImage or []
9
    removed_images = []
10
    if feature_selector:
11
        new_images = []
12
        for image in existing_images:
13
            features = image.get_comments() or ''
14
            if any(feature in features.split(',')
15
                   for feature in feature_selector.split(',') if feature):
16
                removed_images.append(image)
17
            else:
18
                new_images.append(image)
19
        self.AlternativeImage = new_images
20
    else:
21
        removed_images = existing_images
22
        self.AlternativeImage = []
23
    if hasattr(self, 'id'):
24
        name = self.id
25
    elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
26
        name = self.parent_object_.pcGtsId
27
    else:
28
        name = ''
29
    for image in removed_images:
30
        self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
31
            image.get_comments() or '', name))
32

src/ocrd_models/ocrd_page_generateds.py 5 locations

@@ 10614-10644 (lines=31) @@
10611
            obj_.original_tagname_ = 'CustomRegion'
10612
    def __hash__(self):
10613
        return hash(self.id)
10614
    def invalidate_AlternativeImage(self, feature_selector=None):
10615
        """
10616
        Remove derived images from this segment (due to changed coordinates).
10617
    
10618
        If `feature_selector` is not none, remove only images with
10619
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
10620
        """
10621
        existing_images = self.AlternativeImage or []
10622
        removed_images = []
10623
        if feature_selector:
10624
            new_images = []
10625
            for image in existing_images:
10626
                features = image.get_comments() or ''
10627
                if any(feature in features.split(',')
10628
                       for feature in feature_selector.split(',') if feature):
10629
                    removed_images.append(image)
10630
                else:
10631
                    new_images.append(image)
10632
            self.AlternativeImage = new_images
10633
        else:
10634
            removed_images = existing_images
10635
            self.AlternativeImage = []
10636
        if hasattr(self, 'id'):
10637
            name = self.id
10638
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
10639
            name = self.parent_object_.pcGtsId
10640
        else:
10641
            name = ''
10642
        for image in removed_images:
10643
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
10644
                image.get_comments() or '', name))
10645
    def set_Coords(self, Coords):
10646
        """
10647
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 5621-5651 (lines=31) @@
5618
            obj_.original_tagname_ = 'Labels'
5619
    def __hash__(self):
5620
        return hash(self.id)
5621
    def invalidate_AlternativeImage(self, feature_selector=None):
5622
        """
5623
        Remove derived images from this segment (due to changed coordinates).
5624
    
5625
        If `feature_selector` is not none, remove only images with
5626
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
5627
        """
5628
        existing_images = self.AlternativeImage or []
5629
        removed_images = []
5630
        if feature_selector:
5631
            new_images = []
5632
            for image in existing_images:
5633
                features = image.get_comments() or ''
5634
                if any(feature in features.split(',')
5635
                       for feature in feature_selector.split(',') if feature):
5636
                    removed_images.append(image)
5637
                else:
5638
                    new_images.append(image)
5639
            self.AlternativeImage = new_images
5640
        else:
5641
            removed_images = existing_images
5642
            self.AlternativeImage = []
5643
        if hasattr(self, 'id'):
5644
            name = self.id
5645
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
5646
            name = self.parent_object_.pcGtsId
5647
        else:
5648
            name = ''
5649
        for image in removed_images:
5650
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
5651
                image.get_comments() or '', name))
5652
    def set_Coords(self, Coords):
5653
        """
5654
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 5160-5190 (lines=31) @@
5157
            obj_.original_tagname_ = 'Labels'
5158
    def __hash__(self):
5159
        return hash(self.id)
5160
    def invalidate_AlternativeImage(self, feature_selector=None):
5161
        """
5162
        Remove derived images from this segment (due to changed coordinates).
5163
    
5164
        If `feature_selector` is not none, remove only images with
5165
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
5166
        """
5167
        existing_images = self.AlternativeImage or []
5168
        removed_images = []
5169
        if feature_selector:
5170
            new_images = []
5171
            for image in existing_images:
5172
                features = image.get_comments() or ''
5173
                if any(feature in features.split(',')
5174
                       for feature in feature_selector.split(',') if feature):
5175
                    removed_images.append(image)
5176
                else:
5177
                    new_images.append(image)
5178
            self.AlternativeImage = new_images
5179
        else:
5180
            removed_images = existing_images
5181
            self.AlternativeImage = []
5182
        if hasattr(self, 'id'):
5183
            name = self.id
5184
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
5185
            name = self.parent_object_.pcGtsId
5186
        else:
5187
            name = ''
5188
        for image in removed_images:
5189
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
5190
                image.get_comments() or '', name))
5191
    def set_Coords(self, Coords):
5192
        """
5193
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 4649-4679 (lines=31) @@
4646
            obj_.original_tagname_ = 'Labels'
4647
    def __hash__(self):
4648
        return hash(self.id)
4649
    def invalidate_AlternativeImage(self, feature_selector=None):
4650
        """
4651
        Remove derived images from this segment (due to changed coordinates).
4652
    
4653
        If `feature_selector` is not none, remove only images with
4654
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
4655
        """
4656
        existing_images = self.AlternativeImage or []
4657
        removed_images = []
4658
        if feature_selector:
4659
            new_images = []
4660
            for image in existing_images:
4661
                features = image.get_comments() or ''
4662
                if any(feature in features.split(',')
4663
                       for feature in feature_selector.split(',') if feature):
4664
                    removed_images.append(image)
4665
                else:
4666
                    new_images.append(image)
4667
            self.AlternativeImage = new_images
4668
        else:
4669
            removed_images = existing_images
4670
            self.AlternativeImage = []
4671
        if hasattr(self, 'id'):
4672
            name = self.id
4673
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
4674
            name = self.parent_object_.pcGtsId
4675
        else:
4676
            name = ''
4677
        for image in removed_images:
4678
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
4679
                image.get_comments() or '', name))
4680
    def set_Coords(self, Coords):
4681
        """
4682
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 3853-3883 (lines=31) @@
3850
                            ret += this_glyph.get_AlternativeImage()
3851
        return ret
3852
    
3853
    def invalidate_AlternativeImage(self, feature_selector=None):
3854
        """
3855
        Remove derived images from this segment (due to changed coordinates).
3856
    
3857
        If `feature_selector` is not none, remove only images with
3858
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
3859
        """
3860
        existing_images = self.AlternativeImage or []
3861
        removed_images = []
3862
        if feature_selector:
3863
            new_images = []
3864
            for image in existing_images:
3865
                features = image.get_comments() or ''
3866
                if any(feature in features.split(',')
3867
                       for feature in feature_selector.split(',') if feature):
3868
                    removed_images.append(image)
3869
                else:
3870
                    new_images.append(image)
3871
            self.AlternativeImage = new_images
3872
        else:
3873
            removed_images = existing_images
3874
            self.AlternativeImage = []
3875
        if hasattr(self, 'id'):
3876
            name = self.id
3877
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
3878
            name = self.parent_object_.pcGtsId
3879
        else:
3880
            name = ''
3881
        for image in removed_images:
3882
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
3883
                image.get_comments() or '', name))
3884
    def set_Border(self, Border):
3885
        """
3886
        Set coordinate polygon by given :py:class:`BorderType` object.