doc2json/tex2json/xml_to_json.py
def replace_ref_tokens(sp: BeautifulSoup, el: bs4.element.Tag, ref_map: Dict):
    """
    Replace all references in element with special tokens
    :param sp:
    :param el:
    :param ref_map:
    :return:
    """
    # replace all citations with cite keyword
    for cite in el.find_all('cit'):
        try:
            target = cite.ref.get('target').replace('bid', 'BIBREF')
            cite.replace_with(sp.new_string(f" {target} "))
        except AttributeError:
            print('Attribute error: ', cite)
            continue

    # replace all non citation references
    for rtag in el.find_all('ref'):
        try:
            if rtag.get('target') and not rtag.get('target').startswith('bid'):
                if rtag.get('target').startswith('cid'):
                    target = rtag.get('target').replace('cid', 'SECREF')
                elif rtag.get('target').startswith('uid'):
                    if rtag.get('target').replace('uid', 'FIGREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'FIGREF')
                    elif rtag.get('target').replace('uid', 'TABREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'TABREF')
                    elif rtag.get('target').replace('uid', 'EQREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'EQREF')
                    elif rtag.get('target').replace('uid', 'FOOTREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'FOOTREF')
                    elif rtag.get('target').replace('uid', 'SECREFU') in ref_map:
                        target = rtag.get('target').replace('uid', 'SECREFU')
                    else:
                        target = rtag.get('target').upper()
                else:
                    print('Weird ID!')
                    target = rtag.get('target').upper()
                rtag.replace_with(sp.new_string(f" {target} "))
        except AttributeError:
            print('Attribute error: ', rtag)
            continue

    return el

    Replace all references in element with special tokens
    :param sp:
    :param el:
    :param ref_map:
    :return:
    
Replace all references in element with special tokens
Replace all references in element with special tokens
def replace_ref_tokens(sp: BeautifulSoup, el: bs4.element.Tag, ref_map: Dict):
    for cite in el.find_all('cit'):
        try:
            target = cite.ref.get('target').replace('bid', 'BIBREF')
            cite.replace_with(sp.new_string(f" {target} "))
        except AttributeError:
            print('Attribute error: ', cite)
            continue
    for rtag in el.find_all('ref'):
        try:
            if rtag.get('target') and not rtag.get('target').startswith('bid'):
                if rtag.get('target').startswith('cid'):
                    target = rtag.get('target').replace('cid', 'SECREF')
                elif rtag.get('target').startswith('uid'):
                    if rtag.get('target').replace('uid', 'FIGREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'FIGREF')
                    elif rtag.get('target').replace('uid', 'TABREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'TABREF')
                    elif rtag.get('target').replace('uid', 'EQREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'EQREF')
                    elif rtag.get('target').replace('uid', 'FOOTREF') in ref_map:
                        target = rtag.get('target').replace('uid', 'FOOTREF')
                    elif rtag.get('target').replace('uid', 'SECREFU') in ref_map:
                        target = rtag.get('target').replace('uid', 'SECREFU')
                    else:
                        target = rtag.get('target').upper()
                else:
                    print('Weird ID!')
                    target = rtag.get('target').upper()
                rtag.replace_with(sp.new_string(f" {target} "))
        except AttributeError:
            print('Attribute error: ', rtag)
            continue
    return el
def replace_ref_tokens ( sp : BeautifulSoup , el : bs4 . element . Tag , ref_map : Dict ) : for cite in el . find_all ( 'cit' ) : try : target = cite . ref . get ( 'target' ) . replace ( 'bid' , 'BIBREF' ) cite . replace_with ( sp . new_string ( f" {target} " ) ) except AttributeError : print ( 'Attribute error: ' , cite ) continue for rtag in el . find_all ( 'ref' ) : try : if rtag . get ( 'target' ) and not rtag . get ( 'target' ) . startswith ( 'bid' ) : if rtag . get ( 'target' ) . startswith ( 'cid' ) : target = rtag . get ( 'target' ) . replace ( 'cid' , 'SECREF' ) elif rtag . get ( 'target' ) . startswith ( 'uid' ) : if rtag . get ( 'target' ) . replace ( 'uid' , 'FIGREF' ) in ref_map : target = rtag . get ( 'target' ) . replace ( 'uid' , 'FIGREF' ) elif rtag . get ( 'target' ) . replace ( 'uid' , 'TABREF' ) in ref_map : target = rtag . get ( 'target' ) . replace ( 'uid' , 'TABREF' ) elif rtag . get ( 'target' ) . replace ( 'uid' , 'EQREF' ) in ref_map : target = rtag . get ( 'target' ) . replace ( 'uid' , 'EQREF' ) elif rtag . get ( 'target' ) . replace ( 'uid' , 'FOOTREF' ) in ref_map : target = rtag . get ( 'target' ) . replace ( 'uid' , 'FOOTREF' ) elif rtag . get ( 'target' ) . replace ( 'uid' , 'SECREFU' ) in ref_map : target = rtag . get ( 'target' ) . replace ( 'uid' , 'SECREFU' ) else : target = rtag . get ( 'target' ) . upper ( ) else : print ( 'Weird ID!' ) target = rtag . get ( 'target' ) . upper ( ) rtag . replace_with ( sp . new_string ( f" {target} " ) ) except AttributeError : print ( 'Attribute error: ' , rtag ) continue return el
Replace all references in element with special tokens
Replace all references in element with special tokens
"""
    Replace all references in element with special tokens
    :param sp:
    :param el:
    :param ref_map:
    :return:
    """ # replace all citations with cite keyword # replace all non citation references
None
sp
BeautifulSoup
None
el
bs4.element.Tag
None
ref_map
Dict
None