ALTO: Add Layout/Page's attribute values

master
Gerber, Mike 3 years ago
parent 102b15ffa9
commit c9737683b1

@ -53,7 +53,10 @@ def alto_to_dict(alto, raise_errors=True):
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}softwareVersion': elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}softwareVersion':
value['softwareVersion'] = TagGroup(tag, group).is_singleton().has_no_attributes().text() value['softwareVersion'] = TagGroup(tag, group).is_singleton().has_no_attributes().text()
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Layout': elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Layout':
pass # TODO value['Layout'] = TagGroup(tag, group).is_singleton().has_no_attributes().descend(raise_errors)
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Page':
value['Page'] = TagGroup(tag, group).is_singleton().attributes()
# TODO subelements
elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Styles': elif tag == '{http://www.loc.gov/standards/alto/ns-v2#}Styles':
pass pass
else: else:

@ -181,6 +181,19 @@ class TagGroup:
value[sub_tag] = s value[sub_tag] = s
return value return value
def attributes(self):
"""
Return a merged dict of all attributes of the tag group.
Probably most useful if used on a singleton, for example:
value['Page'] = TagGroup(tag, group).is_singleton().attributes()
"""
attrib = {}
for e in self.group:
attrib.update(e.attrib)
return attrib
def sorted_groupby(iterable, key=None): def sorted_groupby(iterable, key=None):
""" """

Loading…
Cancel
Save