diff --git a/ocrd_models/ocrd_models/ocrd_page_generateds.py b/ocrd_models/ocrd_models/ocrd_page_generateds.py index 4633c6358c..53b2b7e978 100644 --- a/ocrd_models/ocrd_models/ocrd_page_generateds.py +++ b/ocrd_models/ocrd_models/ocrd_page_generateds.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- # -# Generated Mon Sep 21 14:00:49 2020 by generateDS.py version 2.35.20. -# Python 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0] +# Generated Sat Oct 31 00:59:08 2020 by generateDS.py version 2.35.20. +# Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] # # Command line options: # ('-f', '') @@ -16,7 +16,7 @@ # ocrd_validators/ocrd_validators/page.xsd # # Command line: -# /home/kba/build/github.com/OCR-D/monorepo/ocrd_all/venv/bin/generateDS -f --root-element="PcGts" -o "ocrd_models/ocrd_models/ocrd_page_generateds.py" --disable-generatedssuper-lookup --user-methods="ocrd_models/ocrd_page_user_methods.py" ocrd_validators/ocrd_validators/page.xsd +# generateDS -f --root-element="PcGts" -o "ocrd_models/ocrd_models/ocrd_page_generateds.py" --disable-generatedssuper-lookup --user-methods="ocrd_models/ocrd_page_user_methods.py" ocrd_validators/ocrd_validators/page.xsd # # Current working directory (os.getcwd()): # core @@ -3036,6 +3036,57 @@ def get_AllRegions(self, classes=None, order='document', depth=0): else: ret = in_reading_order + [r for r in ret if r not in in_reading_order] return ret + def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) + def set_Border(self, Border): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + self.invalidate_AlternativeImage(feature_selector='cropped') + self.Border = Border + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class PageType @@ -3187,6 +3238,22 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_points(self, points): + """ + Set coordinate polygon by given string. + Moreover, invalidate the parent's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'parent_object_'): + parent = self.parent_object_ + if hasattr(parent, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + parent.invalidate_AlternativeImage() + elif hasattr(parent, 'parent_object_') and hasattr(parent.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + parent.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.points = points # end class CoordsType @@ -3633,6 +3700,51 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) + def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords # end class TextLineType @@ -4047,6 +4159,51 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) + def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords # end class WordType @@ -4414,6 +4571,51 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) + def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords # end class GlyphType @@ -7029,6 +7231,20 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords # end class BorderType @@ -8867,6 +9083,51 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) + def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords # end class RegionType @@ -10722,6 +10983,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class AdvertRegionType @@ -10863,6 +11135,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class MusicRegionType @@ -10976,6 +11259,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class MapRegionType @@ -11118,6 +11412,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class ChemRegionType @@ -11260,6 +11565,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class MathsRegionType @@ -11403,6 +11719,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class SeparatorRegionType @@ -11611,6 +11938,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class ChartRegionType @@ -11860,6 +12198,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class TableRegionType @@ -12039,6 +12388,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class GraphicRegionType @@ -12218,6 +12578,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class LineDrawingRegionType @@ -12410,6 +12781,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class ImageRegionType @@ -12890,6 +13272,17 @@ def __hash__(self): else: raise ValueError("Cannot hash %s" % self) return hash(val) + def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation # end class TextRegionType diff --git a/ocrd_models/ocrd_page_user_methods.py b/ocrd_models/ocrd_page_user_methods.py index 1c5e524289..44899076b3 100644 --- a/ocrd_models/ocrd_page_user_methods.py +++ b/ocrd_models/ocrd_page_user_methods.py @@ -109,6 +109,12 @@ def _add_method(class_re, method_name, file_name=None): _add_method(r'^(PageType)$', 'get_AllRegions'), _add_method(r'^(PcGtsType)$', 'get_AllAlternativeImagePaths'), _add_method(r'^(PcGtsType)$', 'prune_ReadingOrder'), + _add_method(r'^(PageType|RegionType|TextLineType|WordType|GlyphType)$', 'invalidate_AlternativeImage'), + _add_method(r'^(BorderType|RegionType|TextLineType|WordType|GlyphType)$', 'set_Coords'), + _add_method(r'^(PageType)$', 'set_Border'), + _add_method(r'^(CoordsType)$', 'set_points'), + # for some reason, pagecontent.xsd does not declare @orientation at the abstract/base RegionType: + _add_method(r'^(PageType|AdvertRegionType|MusicRegionType|MapRegionType|ChemRegionType|MathsRegionType|SeparatorRegionType|ChartRegionType|TableRegionType|GraphicRegionType|LineDrawingRegionType|ImageRegionType|TextRegionType)$', 'set_orientation'), ) diff --git a/ocrd_models/ocrd_page_user_methods/invalidate_AlternativeImage.py b/ocrd_models/ocrd_page_user_methods/invalidate_AlternativeImage.py new file mode 100644 index 0000000000..a398ef4c6e --- /dev/null +++ b/ocrd_models/ocrd_page_user_methods/invalidate_AlternativeImage.py @@ -0,0 +1,31 @@ +def invalidate_AlternativeImage(self, feature_selector=None): + """ + Remove derived images from this segment (due to changed coordinates). + + If ``feature_selector`` is not none, remove only images with + matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``. + """ + existing_images = self.AlternativeImage or [] + removed_images = [] + if feature_selector: + new_images = [] + for image in existing_images: + features = image.get_comments() or '' + if any(feature in features.split(',') + for feature in feature_selector.split(',') if feature): + removed_images.append(image) + else: + new_images.append(image) + self.AlternativeImage = new_images + else: + removed_images = existing_images + self.AlternativeImage = [] + if hasattr(self, 'id'): + name = self.id + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'): + name = self.parent_object_.pcGtsId + else: + name = '' + for image in removed_images: + self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % ( + image.get_comments() or '', name)) diff --git a/ocrd_models/ocrd_page_user_methods/set_Border.py b/ocrd_models/ocrd_page_user_methods/set_Border.py new file mode 100644 index 0000000000..568fd1d02d --- /dev/null +++ b/ocrd_models/ocrd_page_user_methods/set_Border.py @@ -0,0 +1,9 @@ +def set_Border(self, Border): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + self.invalidate_AlternativeImage(feature_selector='cropped') + self.Border = Border diff --git a/ocrd_models/ocrd_page_user_methods/set_Coords.py b/ocrd_models/ocrd_page_user_methods/set_Coords.py new file mode 100644 index 0000000000..ce16f76fbf --- /dev/null +++ b/ocrd_models/ocrd_page_user_methods/set_Coords.py @@ -0,0 +1,14 @@ +def set_Coords(self, Coords): + """ + Set coordinate polygon by given object. + Moreover, invalidate self's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + self.invalidate_AlternativeImage() + elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.Coords = Coords diff --git a/ocrd_models/ocrd_page_user_methods/set_orientation.py b/ocrd_models/ocrd_page_user_methods/set_orientation.py new file mode 100644 index 0000000000..d9beaad07b --- /dev/null +++ b/ocrd_models/ocrd_page_user_methods/set_orientation.py @@ -0,0 +1,11 @@ +def set_orientation(self, orientation): + """ + Set deskewing angle to given number. + Moreover, invalidate self's AlternativeImages + (because they will have been rotated and enlarged + with the angle of the previous value). + """ + if hasattr(self, 'invalidate_AlternativeImage'): + # PageType, RegionType: + self.invalidate_AlternativeImage(feature_selector='deskewed') + self.orientation = orientation diff --git a/ocrd_models/ocrd_page_user_methods/set_points.py b/ocrd_models/ocrd_page_user_methods/set_points.py new file mode 100644 index 0000000000..bad9873305 --- /dev/null +++ b/ocrd_models/ocrd_page_user_methods/set_points.py @@ -0,0 +1,16 @@ +def set_points(self, points): + """ + Set coordinate polygon by given string. + Moreover, invalidate the parent's AlternativeImages + (because they will have been cropped with a bbox + of the previous polygon). + """ + if hasattr(self, 'parent_object_'): + parent = self.parent_object_ + if hasattr(parent, 'invalidate_AlternativeImage'): + # RegionType, TextLineType, WordType, GlyphType: + parent.invalidate_AlternativeImage() + elif hasattr(parent, 'parent_object_') and hasattr(parent.parent_object_, 'invalidate_AlternativeImage'): + # BorderType: + parent.parent_object_.invalidate_AlternativeImage(feature_selector='cropped') + self.points = points