-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ocrd_page: add invalidate_AlternativeImage method
- Loading branch information
Showing
3 changed files
with
190 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ocrd_models/ocrd_page_user_methods/invalidate_AlternativeImage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |