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

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