Code Duplication    Length = 31-31 lines in 6 locations

src/ocrd_models/ocrd_page_generateds.py 5 locations

@@ 9710-9740 (lines=31) @@
9707
            obj_.original_tagname_ = 'CustomRegion'
9708
    def __hash__(self):
9709
        return hash(self.id)
9710
    def invalidate_AlternativeImage(self, feature_selector=None):
9711
        """
9712
        Remove derived images from this segment (due to changed coordinates).
9713
    
9714
        If `feature_selector` is not none, remove only images with
9715
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
9716
        """
9717
        existing_images = self.AlternativeImage or []
9718
        removed_images = []
9719
        if feature_selector:
9720
            new_images = []
9721
            for image in existing_images:
9722
                features = image.get_comments() or ''
9723
                if any(feature in features.split(',')
9724
                       for feature in feature_selector.split(',') if feature):
9725
                    removed_images.append(image)
9726
                else:
9727
                    new_images.append(image)
9728
            self.AlternativeImage = new_images
9729
        else:
9730
            removed_images = existing_images
9731
            self.AlternativeImage = []
9732
        if hasattr(self, 'id'):
9733
            name = self.id
9734
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
9735
            name = self.parent_object_.pcGtsId
9736
        else:
9737
            name = ''
9738
        for image in removed_images:
9739
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
9740
                image.get_comments() or '', name))
9741
    def set_Coords(self, Coords):
9742
        """
9743
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 4917-4947 (lines=31) @@
4914
            obj_.original_tagname_ = 'Labels'
4915
    def __hash__(self):
4916
        return hash(self.id)
4917
    def invalidate_AlternativeImage(self, feature_selector=None):
4918
        """
4919
        Remove derived images from this segment (due to changed coordinates).
4920
    
4921
        If `feature_selector` is not none, remove only images with
4922
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
4923
        """
4924
        existing_images = self.AlternativeImage or []
4925
        removed_images = []
4926
        if feature_selector:
4927
            new_images = []
4928
            for image in existing_images:
4929
                features = image.get_comments() or ''
4930
                if any(feature in features.split(',')
4931
                       for feature in feature_selector.split(',') if feature):
4932
                    removed_images.append(image)
4933
                else:
4934
                    new_images.append(image)
4935
            self.AlternativeImage = new_images
4936
        else:
4937
            removed_images = existing_images
4938
            self.AlternativeImage = []
4939
        if hasattr(self, 'id'):
4940
            name = self.id
4941
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
4942
            name = self.parent_object_.pcGtsId
4943
        else:
4944
            name = ''
4945
        for image in removed_images:
4946
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
4947
                image.get_comments() or '', name))
4948
    def set_Coords(self, Coords):
4949
        """
4950
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 4473-4503 (lines=31) @@
4470
            obj_.original_tagname_ = 'Labels'
4471
    def __hash__(self):
4472
        return hash(self.id)
4473
    def invalidate_AlternativeImage(self, feature_selector=None):
4474
        """
4475
        Remove derived images from this segment (due to changed coordinates).
4476
    
4477
        If `feature_selector` is not none, remove only images with
4478
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
4479
        """
4480
        existing_images = self.AlternativeImage or []
4481
        removed_images = []
4482
        if feature_selector:
4483
            new_images = []
4484
            for image in existing_images:
4485
                features = image.get_comments() or ''
4486
                if any(feature in features.split(',')
4487
                       for feature in feature_selector.split(',') if feature):
4488
                    removed_images.append(image)
4489
                else:
4490
                    new_images.append(image)
4491
            self.AlternativeImage = new_images
4492
        else:
4493
            removed_images = existing_images
4494
            self.AlternativeImage = []
4495
        if hasattr(self, 'id'):
4496
            name = self.id
4497
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
4498
            name = self.parent_object_.pcGtsId
4499
        else:
4500
            name = ''
4501
        for image in removed_images:
4502
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
4503
                image.get_comments() or '', name))
4504
    def set_Coords(self, Coords):
4505
        """
4506
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 3981-4011 (lines=31) @@
3978
            obj_.original_tagname_ = 'Labels'
3979
    def __hash__(self):
3980
        return hash(self.id)
3981
    def invalidate_AlternativeImage(self, feature_selector=None):
3982
        """
3983
        Remove derived images from this segment (due to changed coordinates).
3984
    
3985
        If `feature_selector` is not none, remove only images with
3986
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
3987
        """
3988
        existing_images = self.AlternativeImage or []
3989
        removed_images = []
3990
        if feature_selector:
3991
            new_images = []
3992
            for image in existing_images:
3993
                features = image.get_comments() or ''
3994
                if any(feature in features.split(',')
3995
                       for feature in feature_selector.split(',') if feature):
3996
                    removed_images.append(image)
3997
                else:
3998
                    new_images.append(image)
3999
            self.AlternativeImage = new_images
4000
        else:
4001
            removed_images = existing_images
4002
            self.AlternativeImage = []
4003
        if hasattr(self, 'id'):
4004
            name = self.id
4005
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
4006
            name = self.parent_object_.pcGtsId
4007
        else:
4008
            name = ''
4009
        for image in removed_images:
4010
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
4011
                image.get_comments() or '', name))
4012
    def set_Coords(self, Coords):
4013
        """
4014
        Set coordinate polygon by given :py:class:`CoordsType` object.
@@ 3249-3279 (lines=31) @@
3246
                            ret += this_glyph.get_AlternativeImage()
3247
        return ret
3248
    
3249
    def invalidate_AlternativeImage(self, feature_selector=None):
3250
        """
3251
        Remove derived images from this segment (due to changed coordinates).
3252
    
3253
        If `feature_selector` is not none, remove only images with
3254
        matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
3255
        """
3256
        existing_images = self.AlternativeImage or []
3257
        removed_images = []
3258
        if feature_selector:
3259
            new_images = []
3260
            for image in existing_images:
3261
                features = image.get_comments() or ''
3262
                if any(feature in features.split(',')
3263
                       for feature in feature_selector.split(',') if feature):
3264
                    removed_images.append(image)
3265
                else:
3266
                    new_images.append(image)
3267
            self.AlternativeImage = new_images
3268
        else:
3269
            removed_images = existing_images
3270
            self.AlternativeImage = []
3271
        if hasattr(self, 'id'):
3272
            name = self.id
3273
        elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
3274
            name = self.parent_object_.pcGtsId
3275
        else:
3276
            name = ''
3277
        for image in removed_images:
3278
            self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
3279
                image.get_comments() or '', name))
3280
    def set_Border(self, Border):
3281
        """
3282
        Set coordinate polygon by given :py:class:`BorderType` object.

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