Skip to content

Commit

Permalink
ocrd_page: add invalidate_AlternativeImage method
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Oct 30, 2020
1 parent ff4c13d commit 39c6281
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 3 deletions.
161 changes: 158 additions & 3 deletions ocrd_models/ocrd_models/ocrd_page_generateds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:32:57 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', '')
Expand All @@ -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
Expand Down Expand Up @@ -3036,6 +3036,37 @@ 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))
# end class PageType


Expand Down Expand Up @@ -3633,6 +3664,37 @@ 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))
# end class TextLineType


Expand Down Expand Up @@ -4047,6 +4109,37 @@ 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))
# end class WordType


Expand Down Expand Up @@ -4414,6 +4507,37 @@ 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))
# end class GlyphType


Expand Down Expand Up @@ -8867,6 +8991,37 @@ 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))
# end class RegionType


Expand Down
1 change: 1 addition & 0 deletions ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ 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'),
)


Expand Down
31 changes: 31 additions & 0 deletions ocrd_models/ocrd_page_user_methods/invalidate_AlternativeImage.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 39c6281

Please sign in to comment.