doc2json/tex2json/xml_to_json.py
def process_figures_from_tex(sp: BeautifulSoup, ref_map: Dict) -> Dict:
    """
    Add figure captions to fig_map and decompose
    :param sp:
    :param ref_map:
    :return:
    """
    # process floats first because they are on the outside
    for flt in sp.find_all('float'):
        try:
            if flt.name and flt.get('name') == 'figure':
                if flt.get('id'):
                    ref_id = flt.get('id').replace('uid', 'FIGREF')
                    # remove equation tex
                    for eq in flt.find_all('texmath'):
                        eq.decompose()
                    # clean caption text
                    caption_text = None
                    if flt.caption:
                        flt = replace_ref_tokens(sp, flt, ref_map)
                        caption_text = flt.caption.text.strip()
                        caption_text = re.sub(r'\s+', ' ', caption_text)
                        caption_text = re.sub(r'\s', ' ', caption_text)
                    # form figmap entry
                    ref_map[ref_id]['text'] = caption_text
                flt.decompose()
        except AttributeError:
            print('Attribute error with figure float: ', flt.name)
            continue

    for fig in sp.find_all('figure'):
        try:
            if fig.name and fig.get('id'):
                # normalize figure id
                ref_id = fig.get('id').replace('uid', 'FIGREF')
                # remove equation tex
                for eq in fig.find_all('texmath'):
                    eq.decompose()
                # clean caption text
                caption_text = None
                if fig.text:
                    fig = replace_ref_tokens(sp, fig, ref_map)
                    caption_text = fig.text.strip()
                    caption_text = re.sub(r'\s+', ' ', caption_text)
                    caption_text = re.sub(r'\s', ' ', caption_text)
                # add text to figmap entry
                ref_map[ref_id]["text"] = caption_text
        except AttributeError:
            print('Attribute error with figure: ', fig.name)
            continue
        fig.decompose()

    return ref_map

    Add figure captions to fig_map and decompose
    :param sp:
    :param ref_map:
    :return:
    
Add figure captions to fig_map and decompose
Add figure captions to fig_map and decompose
def process_figures_from_tex(sp: BeautifulSoup, ref_map: Dict) -> Dict:
    for flt in sp.find_all('float'):
        try:
            if flt.name and flt.get('name') == 'figure':
                if flt.get('id'):
                    ref_id = flt.get('id').replace('uid', 'FIGREF')
                    for eq in flt.find_all('texmath'):
                        eq.decompose()
                    caption_text = None
                    if flt.caption:
                        flt = replace_ref_tokens(sp, flt, ref_map)
                        caption_text = flt.caption.text.strip()
                        caption_text = re.sub(r'\s+', ' ', caption_text)
                        caption_text = re.sub(r'\s', ' ', caption_text)
                    ref_map[ref_id]['text'] = caption_text
                flt.decompose()
        except AttributeError:
            print('Attribute error with figure float: ', flt.name)
            continue
    for fig in sp.find_all('figure'):
        try:
            if fig.name and fig.get('id'):
                ref_id = fig.get('id').replace('uid', 'FIGREF')
                for eq in fig.find_all('texmath'):
                    eq.decompose()
                caption_text = None
                if fig.text:
                    fig = replace_ref_tokens(sp, fig, ref_map)
                    caption_text = fig.text.strip()
                    caption_text = re.sub(r'\s+', ' ', caption_text)
                    caption_text = re.sub(r'\s', ' ', caption_text)
                ref_map[ref_id]["text"] = caption_text
        except AttributeError:
            print('Attribute error with figure: ', fig.name)
            continue
        fig.decompose()
    return ref_map
def process_figures_from_tex ( sp : BeautifulSoup , ref_map : Dict ) -> Dict : for flt in sp . find_all ( 'float' ) : try : if flt . name and flt . get ( 'name' ) == 'figure' : if flt . get ( 'id' ) : ref_id = flt . get ( 'id' ) . replace ( 'uid' , 'FIGREF' ) for eq in flt . find_all ( 'texmath' ) : eq . decompose ( ) caption_text = None if flt . caption : flt = replace_ref_tokens ( sp , flt , ref_map ) caption_text = flt . caption . text . strip ( ) caption_text = re . sub ( r'\s+' , ' ' , caption_text ) caption_text = re . sub ( r'\s' , ' ' , caption_text ) ref_map [ ref_id ] [ 'text' ] = caption_text flt . decompose ( ) except AttributeError : print ( 'Attribute error with figure float: ' , flt . name ) continue for fig in sp . find_all ( 'figure' ) : try : if fig . name and fig . get ( 'id' ) : ref_id = fig . get ( 'id' ) . replace ( 'uid' , 'FIGREF' ) for eq in fig . find_all ( 'texmath' ) : eq . decompose ( ) caption_text = None if fig . text : fig = replace_ref_tokens ( sp , fig , ref_map ) caption_text = fig . text . strip ( ) caption_text = re . sub ( r'\s+' , ' ' , caption_text ) caption_text = re . sub ( r'\s' , ' ' , caption_text ) ref_map [ ref_id ] [ "text" ] = caption_text except AttributeError : print ( 'Attribute error with figure: ' , fig . name ) continue fig . decompose ( ) return ref_map
Add figure captions to fig_map and decompose
Add figure captions to fig_map and decompose
"""
    Add figure captions to fig_map and decompose
    :param sp:
    :param ref_map:
    :return:
    """ # process floats first because they are on the outside # remove equation tex # clean caption text # form figmap entry # normalize figure id # remove equation tex # clean caption text # add text to figmap entry
None
sp
BeautifulSoup
None
ref_map
Dict
None