Skip to content

Commit

Permalink
ocrd_page: custom GdsCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Aug 24, 2020
1 parent 52eb3f2 commit 7687cd6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ generate-page: repo/assets
-e '/def parseString(/,/return rootObj/ d' \
$(GDS_PAGE)
cat ocrd_models/ocrd_page_parse.py >> $(GDS_PAGE)
sed -i 's,from generatedscollector import,from .generatedscollector import,' $(GDS_PAGE)


#
Expand Down
28 changes: 28 additions & 0 deletions ocrd_models/ocrd_models/generatedscollector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class OcrdGdsCollector(object):

def __init__(self, messages=None):
print('GdsCollector.__init__', self)
if messages is None:
self.messages = []
else:
self.messages = messages

def add_message(self, msg):
self.messages.append(msg)

def get_messages(self):
return self.messages

def clear_messages(self):
self.messages = []

def print_messages(self):
for msg in self.messages:
print("Warning: {}".format(msg))

def write_messages(self, outstream):
for msg in self.messages:
outstream.write("Warning: {}\n".format(msg))

class GdsCollector(OcrdGdsCollector):
pass
4 changes: 2 additions & 2 deletions ocrd_models/ocrd_models/ocrd_page_generateds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

#
# Generated Thu Jul 30 12:33:49 2020 by generateDS.py version 2.35.24.
# Generated Thu Jul 30 13:44:35 2020 by generateDS.py version 2.35.24.
# Python 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
#
# Command line options:
Expand Down Expand Up @@ -124,7 +124,7 @@ def parsexmlstring_(instring, parser=None, **kwargs):
# clues about the possible content of that class.
#
try:
from generatedscollector import GdsCollector as GdsCollector_
from .generatedscollector import GdsCollector as GdsCollector_
except ImportError:

class GdsCollector_(object):
Expand Down
7 changes: 7 additions & 0 deletions tests/model/test_ocrd_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,12 @@ def test_get_AllAlternativeImagePaths(self):
# TODO: Test with word/glyph-level AlternativeImages
# self.assertEqual(len(pcgts.get_AllAlternativeImagePaths(word=False)), 37)

def test_gdscollector_override(self):
from ocrd_models.generatedscollector import OcrdGdsCollector
with open(assets.path_to('gutachten/data/TEMP1/PAGE_TEMP1.xml'), 'r') as f:
pcgts = parseString(f.read().encode('utf8'), silence=True)
gdc = pcgts.gds_collector_
self.assertTrue(isinstance(gdc, OcrdGdsCollector))

if __name__ == '__main__':
main(__file__)

0 comments on commit 7687cd6

Please sign in to comment.