doc2json/jats2json/process_jats.py
def process_jats_file(
        jats_file: str,
        output_dir: str=BASE_OUTPUT_DIR,
        log_dir: str=BASE_LOG_DIR,
) -> Optional[str]:
    """
    Process files in a JATS XML file and get JSON representation
    :param jats_file:
    :param output_dir:
    :param log_dir:
    :return:
    """
    # create directories
    os.makedirs(output_dir, exist_ok=True)
    os.makedirs(log_dir, exist_ok=True)

    # get paper id as the name of the file
    paper_id = os.path.splitext(jats_file)[0].split('/')[-1]
    output_file = os.path.join(output_dir, f'{paper_id}.json')

    # check if input file exists and output file doesn't
    if not os.path.exists(jats_file):
        raise FileNotFoundError(f"{jats_file} doesn't exist")
    if os.path.exists(output_file):
        print(f'{output_file} already exists!')

    # convert to S2ORC
    paper = convert_jats_xml_to_s2orc_json(jats_file, log_dir)

    # write to file
    with open(output_file, 'w') as outf:
        json.dump(paper.release_json("jats"), outf, indent=4, sort_keys=False)

    return output_file

    Process files in a JATS XML file and get JSON representation
    :param jats_file:
    :param output_dir:
    :param log_dir:
    :return:
    
Process files in a JATS XML file and get JSON representation
Process files in a JATS XML file and get JSON representation
def process_jats_file(
        jats_file: str,
        output_dir: str=BASE_OUTPUT_DIR,
        log_dir: str=BASE_LOG_DIR,
) -> Optional[str]:
    os.makedirs(output_dir, exist_ok=True)
    os.makedirs(log_dir, exist_ok=True)
    paper_id = os.path.splitext(jats_file)[0].split('/')[-1]
    output_file = os.path.join(output_dir, f'{paper_id}.json')
    if not os.path.exists(jats_file):
        raise FileNotFoundError(f"{jats_file} doesn't exist")
    if os.path.exists(output_file):
        print(f'{output_file} already exists!')
    paper = convert_jats_xml_to_s2orc_json(jats_file, log_dir)
    with open(output_file, 'w') as outf:
        json.dump(paper.release_json("jats"), outf, indent=4, sort_keys=False)
    return output_file
def process_jats_file ( jats_file : str , output_dir : str = BASE_OUTPUT_DIR , log_dir : str = BASE_LOG_DIR , ) -> Optional [ str ] : os . makedirs ( output_dir , exist_ok = True ) os . makedirs ( log_dir , exist_ok = True ) paper_id = os . path . splitext ( jats_file ) [ 0 ] . split ( '/' ) [ - 1 ] output_file = os . path . join ( output_dir , f'{paper_id}.json' ) if not os . path . exists ( jats_file ) : raise FileNotFoundError ( f"{jats_file} doesn't exist" ) if os . path . exists ( output_file ) : print ( f'{output_file} already exists!' ) paper = convert_jats_xml_to_s2orc_json ( jats_file , log_dir ) with open ( output_file , 'w' ) as outf : json . dump ( paper . release_json ( "jats" ) , outf , indent = 4 , sort_keys = False ) return output_file
Process files in a JATS XML file and get JSON representation
Process files in a JATS XML file and get JSON representation
"""
    Process files in a JATS XML file and get JSON representation
    :param jats_file:
    :param output_dir:
    :param log_dir:
    :return:
    """ # create directories # get paper id as the name of the file # check if input file exists and output file doesn't # convert to S2ORC # write to file
None
jats_file
str
None
output_dir
str
None
log_dir
str
None