doc2json/grobid2json/process_pdf.py
def process_pdf_file(
        input_file: str,
        temp_dir: str = BASE_TEMP_DIR,
        output_dir: str = BASE_OUTPUT_DIR,
        grobid_config: Optional[Dict] = None
) -> str:
    """
    Process a PDF file and get JSON representation
    :param input_file:
    :param temp_dir:
    :param output_dir:
    :return:
    """
    os.makedirs(temp_dir, exist_ok=True)
    os.makedirs(output_dir, exist_ok=True)

    # get paper id as the name of the file
    paper_id = '.'.join(input_file.split('/')[-1].split('.')[:-1])
    tei_file = os.path.join(temp_dir, f'{paper_id}.tei.xml')
    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(input_file):
        raise FileNotFoundError(f"{input_file} doesn't exist")
    if os.path.exists(output_file):
        print(f'{output_file} already exists!')

    # process PDF through Grobid -> TEI.XML
    client = GrobidClient(grobid_config)
    # TODO: compute PDF hash
    # TODO: add grobid version number to output
    client.process_pdf(input_file, temp_dir, "processFulltextDocument")

    # process TEI.XML -> JSON
    assert os.path.exists(tei_file)
    paper = convert_tei_xml_file_to_s2orc_json(tei_file)

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

    return output_file

    Process a PDF file and get JSON representation
    :param input_file:
    :param temp_dir:
    :param output_dir:
    :return:
    
Process a PDF file and get JSON representation
Process a PDF file and get JSON representation
def process_pdf_file(
        input_file: str,
        temp_dir: str = BASE_TEMP_DIR,
        output_dir: str = BASE_OUTPUT_DIR,
        grobid_config: Optional[Dict] = None
) -> str:
    os.makedirs(temp_dir, exist_ok=True)
    os.makedirs(output_dir, exist_ok=True)
    paper_id = '.'.join(input_file.split('/')[-1].split('.')[:-1])
    tei_file = os.path.join(temp_dir, f'{paper_id}.tei.xml')
    output_file = os.path.join(output_dir, f'{paper_id}.json')
    if not os.path.exists(input_file):
        raise FileNotFoundError(f"{input_file} doesn't exist")
    if os.path.exists(output_file):
        print(f'{output_file} already exists!')
    client = GrobidClient(grobid_config)
    client.process_pdf(input_file, temp_dir, "processFulltextDocument")
    assert os.path.exists(tei_file)
    paper = convert_tei_xml_file_to_s2orc_json(tei_file)
    with open(output_file, 'w') as outf:
        json.dump(paper.release_json(), outf, indent=4, sort_keys=False)
    return output_file
def process_pdf_file ( input_file : str , temp_dir : str = BASE_TEMP_DIR , output_dir : str = BASE_OUTPUT_DIR , grobid_config : Optional [ Dict ] = None ) -> str : os . makedirs ( temp_dir , exist_ok = True ) os . makedirs ( output_dir , exist_ok = True ) paper_id = '.' . join ( input_file . split ( '/' ) [ - 1 ] . split ( '.' ) [ : - 1 ] ) tei_file = os . path . join ( temp_dir , f'{paper_id}.tei.xml' ) output_file = os . path . join ( output_dir , f'{paper_id}.json' ) if not os . path . exists ( input_file ) : raise FileNotFoundError ( f"{input_file} doesn't exist" ) if os . path . exists ( output_file ) : print ( f'{output_file} already exists!' ) client = GrobidClient ( grobid_config ) client . process_pdf ( input_file , temp_dir , "processFulltextDocument" ) assert os . path . exists ( tei_file ) paper = convert_tei_xml_file_to_s2orc_json ( tei_file ) with open ( output_file , 'w' ) as outf : json . dump ( paper . release_json ( ) , outf , indent = 4 , sort_keys = False ) return output_file
Process a PDF file and get JSON representation
Process a PDF file and get JSON representation
"""
    Process a PDF file and get JSON representation
    :param input_file:
    :param temp_dir:
    :param output_dir:
    :return:
    """ # get paper id as the name of the file # check if input file exists and output file doesn't # process PDF through Grobid -> TEI.XML # TODO: compute PDF hash # TODO: add grobid version number to output # process TEI.XML -> JSON # write to file
None
input_file
str
None
temp_dir
str
None
output_dir
str
None
grobid_config
Optional[Dict]