|
|
@ -31,50 +31,50 @@ def alto_to_dict(alto, raise_errors=True):
|
|
|
|
for tag, group in sorted_groupby(alto, key=attrgetter('tag')):
|
|
|
|
for tag, group in sorted_groupby(alto, key=attrgetter('tag')):
|
|
|
|
group = list(group)
|
|
|
|
group = list(group)
|
|
|
|
|
|
|
|
|
|
|
|
# XXX Namespaces seem to use a trailing / sometimes, sometimes not.
|
|
|
|
localname = ET.QName(tag).localname
|
|
|
|
# (e.g. {http://www.loc.gov/METS/} vs {http://www.loc.gov/METS})
|
|
|
|
|
|
|
|
if tag == '{http://www.loc.gov/standards/alto/ns-v2#}Description':
|
|
|
|
if localname == 'Description':
|
|
|
|
value['Description'] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}MeasurementUnit':
|
|
|
|
elif localname == 'MeasurementUnit':
|
|
|
|
value['MeasurementUnit'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}OCRProcessing':
|
|
|
|
elif localname == 'OCRProcessing':
|
|
|
|
value['OCRProcessing'] = TagGroup(tag, group).is_singleton().descend(raise_errors)
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().descend(raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}ocrProcessingStep':
|
|
|
|
elif localname == 'ocrProcessingStep':
|
|
|
|
for n, e in enumerate(group):
|
|
|
|
for n, e in enumerate(group):
|
|
|
|
value['ocrProcessingStep{}'.format(n)] = alto_to_dict(e, raise_errors)
|
|
|
|
value[f'{localname}{n}'] = alto_to_dict(e, raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}preProcessingStep':
|
|
|
|
elif localname == 'preProcessingStep':
|
|
|
|
# TODO This enumerated descent is used more than once, DRY!
|
|
|
|
# TODO This enumerated descent is used more than once, DRY!
|
|
|
|
for n, e in enumerate(group):
|
|
|
|
for n, e in enumerate(group):
|
|
|
|
value['preProcessingStep{}'.format(n)] = alto_to_dict(e, raise_errors)
|
|
|
|
value[f'{localname}{n}'] = alto_to_dict(e, raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}processingDateTime':
|
|
|
|
elif localname == 'processingDateTime':
|
|
|
|
value['processingDateTime'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}processingSoftware':
|
|
|
|
elif localname == 'processingSoftware':
|
|
|
|
value['processingSoftware'] = TagGroup(tag, group).is_singleton().descend(raise_errors)
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().descend(raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}processingAgency':
|
|
|
|
elif localname == 'processingAgency':
|
|
|
|
value['processingAgency'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}processingStepDescription':
|
|
|
|
elif localname == 'processingStepDescription':
|
|
|
|
value['processingStepDescription'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}processingStepSettings':
|
|
|
|
elif localname == 'processingStepSettings':
|
|
|
|
value['processingStepSettings'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}softwareCreator':
|
|
|
|
elif localname == 'softwareCreator':
|
|
|
|
value['softwareCreator'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}softwareName':
|
|
|
|
elif localname == 'softwareName':
|
|
|
|
value['softwareName'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}softwareVersion':
|
|
|
|
elif localname == 'softwareVersion':
|
|
|
|
value['softwareVersion'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
|
|
|
|
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}sourceImageInformation':
|
|
|
|
elif localname == 'sourceImageInformation':
|
|
|
|
value['sourceImageInformation'] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}fileName':
|
|
|
|
elif localname == 'fileName':
|
|
|
|
value['fileName'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
|
|
|
|
|
|
|
|
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Layout':
|
|
|
|
elif localname == 'Layout':
|
|
|
|
value['Layout'] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
value[localname] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Page':
|
|
|
|
elif localname == 'Page':
|
|
|
|
value['Page'] = {}
|
|
|
|
value['Page'] = {}
|
|
|
|
value['Page'].update(TagGroup(tag, group).is_singleton().attributes())
|
|
|
|
value['Page'].update(TagGroup(tag, group).is_singleton().attributes())
|
|
|
|
value['Page'].update(TagGroup(tag, group).subelement_counts())
|
|
|
|
value['Page'].update(TagGroup(tag, group).subelement_counts())
|
|
|
|
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Styles':
|
|
|
|
elif localname == 'Styles':
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if raise_errors:
|
|
|
|
if raise_errors:
|
|
|
|