def components(soup):
components = []<EOL>nodenames = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"]<EOL>position = <NUM_LIT:1><EOL>position_by_type = {}<EOL>for nodename in nodenames:<EOL><INDENT>position_by_type[nodename] = <NUM_LIT:1><EOL><DEDENT>article_doi = doi(soup)<EOL>component_tags = extract_nodes(soup, nodenames)<EOL>for tag in component_tags:<EOL><INDENT>component = OrderedDict()<EOL>ctype = tag.name<EOL>component_doi = extract_component_doi(tag, nodenames)<EOL>if component_doi is None:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>component['<STR_LIT>'] = doi_uri_to_doi(component_doi)<EOL>component['<STR_LIT>'] = doi_to_doi_uri(component['<STR_LIT>'])<EOL><DEDENT>copy_attribute(tag.attrs, '<STR_LIT:id>', component)<EOL>if(ctype == "<STR_LIT>"):<EOL><INDENT>title_tag = raw_parser.article_title(tag)<EOL><DEDENT>elif(ctype == "<STR_LIT>"):<EOL><INDENT>title_tag = title_tag_inspected(tag, tag.name, direct_sibling_only=True)<EOL>if not title_tag:<EOL><INDENT>title_tag = title_tag_inspected(tag, "<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>if (not title_tag and tag.parent and tag.parent.name in ["<STR_LIT>", "<STR_LIT>"]<EOL>and not caption_tag_inspected(tag, tag.name)):<EOL><INDENT>title_tag = title_tag_inspected(tag.parent, tag.parent.name, direct_sibling_only=True)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>title_tag = raw_parser.title(tag)<EOL><DEDENT>if title_tag:<EOL><INDENT>component['<STR_LIT:title>'] = node_text(title_tag)<EOL>component['<STR_LIT>'] = node_contents_str(title_tag)<EOL><DEDENT>if ctype == "<STR_LIT>":<EOL><INDENT>label_tag = label_tag_inspected(tag, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>label_tag = raw_parser.label(tag)<EOL><DEDENT>if label_tag:<EOL><INDENT>component['<STR_LIT:label>'] = node_text(label_tag)<EOL>component['<STR_LIT>'] = node_contents_str(label_tag)<EOL><DEDENT>if raw_parser.caption(tag):<EOL><INDENT>first_paragraph = first(paragraphs(raw_parser.caption(tag)))<EOL>if first_paragraph:<EOL><INDENT>nested_caption = raw_parser.caption(first_paragraph)<EOL>if nested_caption:<EOL><INDENT>nested_paragraphs = paragraphs(nested_caption) <EOL>first_paragraph = first(nested_paragraphs) or first_paragraph<EOL><DEDENT><DEDENT>if first_paragraph and not starts_with_doi(first_paragraph):<EOL><INDENT>if raw_parser.supplementary_material(first_paragraph):<EOL><INDENT>first_paragraph = remove_tag_from_tag(first_paragraph, '<STR_LIT>')<EOL><DEDENT>if node_text(first_paragraph).strip():<EOL><INDENT>component['<STR_LIT>'] = node_text(first_paragraph)<EOL>component['<STR_LIT>'] = node_contents_str(first_paragraph)<EOL><DEDENT><DEDENT><DEDENT>if raw_parser.permissions(tag):<EOL><INDENT>component['<STR_LIT>'] = []<EOL>for permissions_tag in raw_parser.permissions(tag):<EOL><INDENT>permissions_item = {}<EOL>if raw_parser.copyright_statement(permissions_tag):<EOL><INDENT>permissions_item['<STR_LIT>'] =node_text(raw_parser.copyright_statement(permissions_tag))<EOL><DEDENT>if raw_parser.copyright_year(permissions_tag):<EOL><INDENT>permissions_item['<STR_LIT>'] =node_text(raw_parser.copyright_year(permissions_tag))<EOL><DEDENT>if raw_parser.copyright_holder(permissions_tag):<EOL><INDENT>permissions_item['<STR_LIT>'] =node_text(raw_parser.copyright_holder(permissions_tag))<EOL><DEDENT>if raw_parser.licence_p(permissions_tag):<EOL><INDENT>permissions_item['<STR_LIT>'] =node_text(first(raw_parser.licence_p(permissions_tag)))<EOL>permissions_item['<STR_LIT>'] =node_contents_str(first(raw_parser.licence_p(permissions_tag)))<EOL><DEDENT>component['<STR_LIT>'].append(permissions_item)<EOL><DEDENT><DEDENT>if raw_parser.contributors(tag):<EOL><INDENT>component['<STR_LIT>'] = []<EOL>for contributor_tag in raw_parser.contributors(tag):<EOL><INDENT>component['<STR_LIT>'].append(format_contributor(contributor_tag, soup))<EOL><DEDENT><DEDENT>parent_nodenames = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>parent_tag = first_parent(tag, parent_nodenames)<EOL>if parent_tag:<EOL><INDENT>acting_parent_tag = component_acting_parent_tag(parent_tag, tag)<EOL>if (acting_parent_tag andextract_component_doi(acting_parent_tag, parent_nodenames) is not None):<EOL><INDENT>component['<STR_LIT>'] = acting_parent_tag.name<EOL>component['<STR_LIT>'] = tag_ordinal(acting_parent_tag)<EOL>component['<STR_LIT>'] = tag_details_sibling_ordinal(acting_parent_tag)<EOL>component['<STR_LIT>'] = tag_details_asset(acting_parent_tag)<EOL><DEDENT>parent_parent_tag = first_parent(parent_tag, parent_nodenames)<EOL>if parent_parent_tag:<EOL><INDENT>acting_parent_tag = component_acting_parent_tag(parent_parent_tag, parent_tag)<EOL>if (acting_parent_tag andextract_component_doi(acting_parent_tag, parent_nodenames) is not None):<EOL><INDENT>component['<STR_LIT>'] = acting_parent_tag.name<EOL>component['<STR_LIT>'] = tag_ordinal(acting_parent_tag)<EOL>component['<STR_LIT>'] = tag_details_sibling_ordinal(acting_parent_tag)<EOL>component['<STR_LIT>'] = tag_details_asset(acting_parent_tag)<EOL><DEDENT><DEDENT><DEDENT>content = "<STR_LIT>"<EOL>for p_tag in extract_nodes(tag, "<STR_LIT:p>"):<EOL><INDENT>if content != "<STR_LIT>":<EOL><INDENT>content = content + "<STR_LIT:U+0020>"<EOL><DEDENT>content = content + node_text(p_tag)<EOL><DEDENT>if(content != "<STR_LIT>"):<EOL><INDENT>component['<STR_LIT:content>'] = content<EOL><DEDENT>media_tag = None<EOL>if(ctype == "<STR_LIT>"):<EOL><INDENT>media_tag = tag<EOL><DEDENT>elif(ctype == "<STR_LIT>"):<EOL><INDENT>media_tag = first(raw_parser.media(tag))<EOL><DEDENT>if media_tag:<EOL><INDENT>component['<STR_LIT>'] = media_tag.get("<STR_LIT>")<EOL>component['<STR_LIT>'] = media_tag.get("<STR_LIT>")<EOL><DEDENT>if(len(component) > <NUM_LIT:0>):<EOL><INDENT>component['<STR_LIT>'] = article_doi<EOL>component['<STR_LIT:type>'] = ctype<EOL>component['<STR_LIT>'] = position<EOL>component['<STR_LIT>'] = tag_ordinal(tag)<EOL>component['<STR_LIT>'] = tag_details_sibling_ordinal(tag)<EOL>component['<STR_LIT>'] = tag_details_asset(tag)<EOL>components.append(component)<EOL>position += <NUM_LIT:1><EOL>position_by_type[ctype] += <NUM_LIT:1><EOL><DEDENT><DEDENT>return components<EOL>
Find the components, i.e. those parts that would be assigned
a unique component DOI, such as figures, tables, etc.
- position is in what order the tag appears in the entire set of nodes
- ordinal is in what order it is for all the tags of its own type