Skip to main content

GrobidArticleExtractor is a Python package designed to extract and organize content from scientific papers in PDF format.

Project description

GrobidArticleExtractor

This Python tool extracts content from PDF files using GROBID and organizes it by sections. It provides a structured way to extract both metadata and content from academic papers and other structured documents.

Features

  • Direct PDF processing using GROBID API
  • Metadata extraction (title, authors, abstract, publication date)
  • Hierarchical section organization with subsections

Prerequisites

  1. Install GROBID:

    # Using Docker (recommended)
    docker pull lfoppiano/grobid:0.7.3
    docker run -t --rm -p 8070:8070 lfoppiano/grobid:0.7.3
    
  2. Install Python dependencies:

     pip install poetry
    
     poetry install
    

Usage

Command Line Interface

The tool provides a user-friendly command-line interface for batch processing PDF files:

# Basic usage (processes PDFs from 'pdfs' directory)
python cli.py

# Process PDFs from a specific directory
python cli.py path/to/pdfs

# Specify custom output directory
python cli.py path/to/pdfs -o path/to/output

# Use custom GROBID server and disable content preview
python cli.py path/to/pdfs --grobid-url http://custom:8070 --no-preview

Available options:

$ python cli.py --help
Usage: cli.py [OPTIONS] [INPUT_FOLDER]

  Process PDF files from INPUT_FOLDER and extract their content using GROBID.

  The extracted content is saved as JSON files in the output directory.
  Each JSON file is named after its source PDF file.

Options:
  -o, --output-dir PATH  Directory to save extracted JSON files (default: output)
  -g, --grobid-url TEXT  GROBID service URL (default: http://localhost:8070)
  --preview / --no-preview
                        Show preview of extracted content (default: True)
  --help                Show this message and exit.

Example:
  python cli.py path/to/pdfs -o path/to/output

Python API Usage

You can also use the tool programmatically in your Python code:

from app import GrobidArticleExtractor

# Initialize extractor (default GROBID URL: http://localhost:8070)
extractor = GrobidArticleExtractor()

# Process a PDF file
xml_content = extractor.process_pdf("path/to/your/paper.pdf")

if xml_content:
    # Extract and organize content
    result = extractor.extract_content(xml_content)
    
    # Access metadata
    print(result['metadata'])
    
    # Access sections
    for section in result['sections']:
        print(section['heading'])
        if 'content' in section:
            print(section['content'])

Custom GROBID server:

extractor = GrobidArticleExtractor(grobid_url="http://your-grobid-server:8070")

Output Structure

The extracted content is organized as follows:

{
    'metadata': {
        'title': 'Paper Title',
        'authors': ['Author 1', 'Author 2'],
        'abstract': 'Paper abstract...',
        'publication_date': '2023'
    },
    'sections': [
        {
            'heading': 'Introduction',
            'content': ['Paragraph 1...', 'Paragraph 2...'],
            'subsections': [
                {
                    'heading': 'Background',
                    'content': ['Subsection content...']
                }
            ]
        }
        # More sections...
    ]
}

Project Structure

The project is organized into two main files:

  • app.py - Contains the core GrobidArticleExtractor class with all the PDF processing and content extraction functionality
  • cli.py - Contains the command-line interface implementation using Click

Error Handling

The tool includes comprehensive error handling for common scenarios:

  • PDF file not found
  • GROBID service unavailable
  • XML parsing errors
  • Invalid content structure

All errors are logged with appropriate messages using Python's logging module.

Contributing

Feel free to submit issues and enhancement requests!

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grobidarticleextractor-0.0.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grobidarticleextractor-0.0.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file grobidarticleextractor-0.0.1.tar.gz.

File metadata

  • Download URL: grobidarticleextractor-0.0.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/23.6.0

File hashes

Hashes for grobidarticleextractor-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3df52defc69dbdc345d7d7fd8b684fd1aea2a19892f430c4984be2f613aa4534
MD5 437d22895737d4fc12fb27788b0c384e
BLAKE2b-256 a14afa18af33b1c21d85bed629a2d1a137489d25978c9c45684a6fc22dd34077

See more details on using hashes here.

File details

Details for the file grobidarticleextractor-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for grobidarticleextractor-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a125ff5246b6c46e422ec993225f4c35b7cc070ee5c40ce1bfa604f77e44e5c
MD5 dbe957c5089d2270362153ed0abc6c1d
BLAKE2b-256 415a9d7b79aa760b3424e5da41c9897d64b2e191fce2ab29971ab64d422edcaa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page