@@ 15326-15358 (lines=33) @@ | ||
15323 | return rootObj, rootElement, mapping, reverse_node_mapping |
|
15324 | ||
15325 | ||
15326 | def parseString(inString, silence=False, print_warnings=True): |
|
15327 | '''Parse a string, create the object tree, and export it. |
|
15328 | ||
15329 | Arguments: |
|
15330 | - inString -- A string. This XML fragment should not start |
|
15331 | with an XML declaration containing an encoding. |
|
15332 | - silence -- A boolean. If False, export the object. |
|
15333 | Returns -- The root object in the tree. |
|
15334 | ''' |
|
15335 | parser = None |
|
15336 | rootNode= parsexmlstring_(inString, parser) |
|
15337 | gds_collector = GdsCollector_() |
|
15338 | rootTag, rootClass = get_root_tag(rootNode) |
|
15339 | if rootClass is None: |
|
15340 | rootTag = 'PcGts' |
|
15341 | rootClass = PcGts |
|
15342 | rootObj = rootClass.factory() |
|
15343 | rootObj.build(rootNode, gds_collector_=gds_collector) |
|
15344 | if not SaveElementTreeNode: |
|
15345 | rootNode = None |
|
15346 | ## if not silence: |
|
15347 | ## sys.stdout.write('<?xml version="1.0" ?>\n') |
|
15348 | ## rootObj.export( |
|
15349 | ## sys.stdout, 0, name_=rootTag, |
|
15350 | ## namespacedef_='xmlns:pc="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15"') |
|
15351 | if print_warnings and len(gds_collector.get_messages()) > 0: |
|
15352 | separator = ('-' * 50) + '\n' |
|
15353 | sys.stderr.write(separator) |
|
15354 | sys.stderr.write('----- Warnings -- count: {} -----\n'.format( |
|
15355 | len(gds_collector.get_messages()), )) |
|
15356 | gds_collector.write_messages(sys.stderr) |
|
15357 | sys.stderr.write(separator) |
|
15358 | return rootObj |
|
15359 | ||
15360 | ||
15361 | def parseLiteral(inFileName, silence=False, print_warnings=True): |
|
@@ 15361-15389 (lines=29) @@ | ||
15358 | return rootObj |
|
15359 | ||
15360 | ||
15361 | def parseLiteral(inFileName, silence=False, print_warnings=True): |
|
15362 | parser = None |
|
15363 | doc = parsexml_(inFileName, parser) |
|
15364 | gds_collector = GdsCollector_() |
|
15365 | rootNode = doc.getroot() |
|
15366 | rootTag, rootClass = get_root_tag(rootNode) |
|
15367 | if rootClass is None: |
|
15368 | rootTag = 'PcGts' |
|
15369 | rootClass = PcGts |
|
15370 | rootObj = rootClass.factory() |
|
15371 | rootObj.build(rootNode, gds_collector_=gds_collector) |
|
15372 | # Enable Python to collect the space used by the DOM. |
|
15373 | if not SaveElementTreeNode: |
|
15374 | doc = None |
|
15375 | rootNode = None |
|
15376 | ## if not silence: |
|
15377 | ## sys.stdout.write('#from ocrd_page_generateds import *\n\n') |
|
15378 | ## sys.stdout.write('import ocrd_page_generateds as model_\n\n') |
|
15379 | ## sys.stdout.write('rootObj = model_.rootClass(\n') |
|
15380 | ## rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) |
|
15381 | ## sys.stdout.write(')\n') |
|
15382 | if print_warnings and len(gds_collector.get_messages()) > 0: |
|
15383 | separator = ('-' * 50) + '\n' |
|
15384 | sys.stderr.write(separator) |
|
15385 | sys.stderr.write('----- Warnings -- count: {} -----\n'.format( |
|
15386 | len(gds_collector.get_messages()), )) |
|
15387 | gds_collector.write_messages(sys.stderr) |
|
15388 | sys.stderr.write(separator) |
|
15389 | return rootObj |
|
15390 | ||
15391 | ||
15392 | def main(): |