doc2json/jats2json/pmc_utils/front_tag_utils.py
def parse_affiliations(front_tag) -> List[Dict]:
    """
    Sometimes affiliations is nested within '<contrib-group>' along with
    authors.  Sometimes, they're not and listed outside as multiple tags.

    Not all <aff> have IDs.  For example:
        <aff>St. Paul, Minnesota</aff>
    """
    outs = []
    for aff_tag in front_tag.find_all('aff'):
        if aff_tag.find('label'):                   # get rid of unused markers so `.text` is cleaner
            aff_tag.find('label').decompose()
        if aff_tag.find('sup'):
            aff_tag.find('sup').decompose()         # same treatment as label

        aff_id = aff_tag.get('id')

        # it looks like we want to go to the full affiliation surface form without worrying about all possible handlings of <named-content> and other fields
        # BUT, we do want to keep ISNI and GRID IDs when they occur.  They seem to occur typically within <institution-wrap>
        # so let's handle those if they exist; safely decompose the tags (because they dont contribute to surface form); then grab remaining affiliation surface form

        # implicit in this approach is that we dont need to actually handle <institution-wrap> tags because only one per affiliation
        if len(aff_tag.find_all('institution-wrap')) > 1:
            import pdb; pdb.set_trace()
        id_type_to_id = {}
        for institution_id_tag in aff_tag.find_all('institution-id'):
            id_type_to_id[institution_id_tag['institution-id-type']] = institution_id_tag.text
            institution_id_tag.decompose()

        # TODO: processing of text:  there are a lot of random newline chars (cuz XML preserves page layout)
        # --> replace them with whitespace if there's preceding punctuation char
        # --> otherwise, replace them with comma
        text = aff_tag.text

        outs.append({
            'id': aff_id,
            'other_ids': id_type_to_id,
            'text': text
        })

    return outs

    Sometimes affiliations is nested within '<contrib-group>' along with
    authors.  Sometimes, they're not and listed outside as multiple tags.

    Not all <aff> have IDs.  For example:
        <aff>St. Paul, Minnesota</aff>
    
Sometimes affiliations is nested within '' along with
authors.  Sometimes, they're not and listed outside as multiple tags.

Not all  have IDs.  For example:
St. Paul, Minnesota
Sometimes affiliations is nested within ' ' along with authors . Sometimes they ' re not and listed outside as multiple tags . Not all have IDs . For example : St . Paul Minnesota
def parse_affiliations(front_tag) -> List[Dict]:
    outs = []
    for aff_tag in front_tag.find_all('aff'):
        if aff_tag.find('label'):                   
            aff_tag.find('label').decompose()
        if aff_tag.find('sup'):
            aff_tag.find('sup').decompose()         
        aff_id = aff_tag.get('id')
        if len(aff_tag.find_all('institution-wrap')) > 1:
            import pdb; pdb.set_trace()
        id_type_to_id = {}
        for institution_id_tag in aff_tag.find_all('institution-id'):
            id_type_to_id[institution_id_tag['institution-id-type']] = institution_id_tag.text
            institution_id_tag.decompose()
        text = aff_tag.text
        outs.append({
            'id': aff_id,
            'other_ids': id_type_to_id,
            'text': text
        })
    return outs
def parse_affiliations ( front_tag ) -> List [ Dict ] : outs = [ ] for aff_tag in front_tag . find_all ( 'aff' ) : if aff_tag . find ( 'label' ) : aff_tag . find ( 'label' ) . decompose ( ) if aff_tag . find ( 'sup' ) : aff_tag . find ( 'sup' ) . decompose ( ) aff_id = aff_tag . get ( 'id' ) if len ( aff_tag . find_all ( 'institution-wrap' ) ) > 1 : import pdb ; pdb . set_trace ( ) id_type_to_id = { } for institution_id_tag in aff_tag . find_all ( 'institution-id' ) : id_type_to_id [ institution_id_tag [ 'institution-id-type' ] ] = institution_id_tag . text institution_id_tag . decompose ( ) text = aff_tag . text outs . append ( { 'id' : aff_id , 'other_ids' : id_type_to_id , 'text' : text } ) return outs
Sometimes affiliations is nested within '<contrib-group>' along with
authors.
Sometimes affiliations is nested within ' <contrib - group > ' along with authors .
"""
    Sometimes affiliations is nested within '<contrib-group>' along with
    authors.  Sometimes, they're not and listed outside as multiple tags.

    Not all <aff> have IDs.  For example:
        <aff>St. Paul, Minnesota</aff>
    """ # get rid of unused markers so `.text` is cleaner # same treatment as label # it looks like we want to go to the full affiliation surface form without worrying about all possible handlings of <named-content> and other fields # BUT, we do want to keep ISNI and GRID IDs when they occur.  They seem to occur typically within <institution-wrap> # so let's handle those if they exist; safely decompose the tags (because they dont contribute to surface form); then grab remaining affiliation surface form # implicit in this approach is that we dont need to actually handle <institution-wrap> tags because only one per affiliation # TODO: processing of text:  there are a lot of random newline chars (cuz XML preserves page layout) # --> replace them with whitespace if there's preceding punctuation char # --> otherwise, replace them with comma
front_tag