mcpField
P
Portuguese Legal Document PDF Metadata Extractor

Portuguese Legal Document PDF Metadata Extractor

Local
github.com/geek2geeksFiles & Storage0Updated 73w ago

About Portuguese Legal Document PDF Metadata Extractor

A Python extractor for structured metadata in Portuguese legal PDFs, especially ECLI-formatted documents. It supports single-file and directory processing, validation, and confidence scoring with or without ground truth.

Key features

  1. 01Table and coordinate-based extraction
  2. 02ECLI and field validation
  3. 03Confidence scoring with or without ground truth
  4. 04Batch directory processing
  5. 05CLI with progress reporting

Use cases

  1. 01Extract metadata from Portuguese legal PDFs
  2. 02Process folders of ECLI documents
  3. 03Validate extracted fields against ground truth

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

Portuguese Legal Document PDF Metadata Extractor

A robust Python tool for extracting structured metadata from Portuguese legal document PDFs, specifically designed for European Case Law Identifier (ECLI) formatted documents.

🚀 Features

  • High Accuracy: 100% confidence score with 96.84% exact match rate
  • Production Ready: Two extractor variants optimized for different use cases
  • Robust Error Handling: Comprehensive validation and error recovery
  • Flexible Confidence Scoring: Works with or without ground truth data
  • User-Friendly Interface: Clear progress reporting and detailed feedback
  • Field Classification: Distinguishes between missing and legitimately empty fields

📁 Project Structure

├── production_extractor.py    # Production-ready extractor with user-friendly interface
├── robust_extractor.py        # Core robust extraction engine
├── run_test1.py              # Test runner for batch processing
├── ground_truth/             # Ground truth data for validation
│   └── ground_truth.json
├── pdfs/                     # Input PDF documents
│   ├── test1/               # Test subset
│   └── *.pdf                # Legal documents
├── IMPROVEMENTS_SUMMARY.md   # Performance improvements documentation
└── README.md                # This file

🔧 Installation

Prerequisites
  • Python 3.8+
  • Required packages:
pip install pdfplumber
Setup
  1. Clone or download the project files
  2. Install dependencies:
    pip install pdfplumber
    
  3. Ensure your PDF files are in the pdfs/ directory

📖 Usage

Basic Usage with Production Extractor

The PortugueseLegalPDFExtractor class provides a user-friendly, production-ready interface:

from production_extractor import PortugueseLegalPDFExtractor

# Initialize extractor with optional ground truth validation
extractor = PortugueseLegalPDFExtractor(
    ground_truth_path="ground_truth/ground_truth.json",  # Optional
    verbose=True  # Enable progress reporting
)

# Extract metadata from a single PDF
result = extractor.extract_metadata("pdfs/document.pdf")

# Process multiple PDFs in a directory
summary = extractor.extract_batch(
    pdf_directory="pdfs/",
    output_directory="results/"  # Optional - saves individual results
)
Command Line Interface

The production extractor includes a full CLI:

# Process single file
python production_extractor.py "pdfs/document.pdf" -o "results/"

# Process entire directory with ground truth validation
python production_extractor.py "pdfs/" -g "ground_truth/ground_truth.json" -o "results/"

# Quiet mode (suppress progress messages)
python production_extractor.py "pdfs/" -q

# Force single file processing
python production_extractor.py "pdfs/document.pdf" --single

📊 Performance Metrics

Current Performance (After Improvements)
  • Overall Confidence: 100.0%
  • Exact Match Rate: 96.84% (153/158 populated fields)
  • Acceptable Match Rate: 100.0%
  • Processing Speed: ~2-3 seconds per document
Field Classification
  • Data Fields: 14 fields with actual content
  • Empty Fields: 8 fields correctly identified as empty
  • Match Types: Exact, case differences, punctuation differences, partial matches

🎯 How It Works

Pattern Recognition

The extractor leverages discovered patterns in Portuguese legal documents:

  1. Fixed Relative Positions: Fields appear in predictable locations
  2. Synchronized Pairs: Left-right column field synchronization
  3. Predictable Order: Consistent field sequence across documents
  4. Table Structure: Metadata organized in structured tables
Confidence Calculation

Two confidence calculation modes:

  1. With Ground Truth: Accuracy-based scoring against known correct values
  2. Without Ground Truth: Heuristic-based scoring using extraction quality indicators

🛠️ Development

Key Components
PortugueseLegalPDFExtractor (production_extractor.py)

Main Features:

  • Dual Confidence Modes: Accuracy-based (with ground truth) and population-based (without)
  • Multiple Extraction Methods: Table-based (primary) and coordinate-based (fallback)
  • Comprehensive Validation: Field validation, ECLI extraction, date formatting
  • Batch Processing: Process entire directories with detailed summaries
  • Command Line Interface: Full CLI with flexible options
  • Progress Reporting: User-friendly status messages and error handling

📈 Recent Improvements

Version 2.0 Enhancements
  1. Fixed Confidence Calculation: Improved from 44.4% to 100.0% by properly handling empty fields
  2. Enhanced Field Classification: Clear distinction between missing and legitimately empty fields
  3. Per-Field Confidence: Individual confidence scores for each extracted field

See IMPROVEMENTS_SUMMARY.md for detailed information.

📄 License

This project is provided as-is for educational and research purposes.

🔗 Related Resources


Last updated: January 2025

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.