← 输入框|github.com|刷新
Skip to content

About

Document Intelligence CLI is a Python command-line tool that extracts and validates useful information from readable UTF-8 text documents. It identifies candidate values, validates them against the project's rules, and presents the results in a human-readable report.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Document Intelligence CLI

PyPI version Python versions License: MIT

Document Intelligence CLI is a Python command-line tool that extracts and validates useful information from readable UTF-8 text documents. It identifies candidate values, validates them against the project's rules, and presents the results in a human-readable report.

Features

  • Extract structured information from text documents.
  • Validate extracted candidates.
  • Generate human-readable reports.
  • Provide a command-line interface using Python's argparse.
  • Run as an installed docintel command or as a Python module.
  • Handle missing files and empty documents.
  • Include automated unit and integration tests.
  • Require no third-party runtime dependencies.

Supported Extraction Types

Type Example
Email address support@example.com
Phone number +2348012345678
Monetary amount $2,500.50
Date 2024-02-29
Hashtag #Python
Mention @michael
IPv4 address 192.168.1.1
URL https://example.com

For most supported types, the application uses two stages:

  1. Extraction identifies candidate values in the document.
  2. Validation checks whether candidates satisfy the project's rules.

Requirements

  • Python 3.10 or newer
  • Git, if you are cloning the source repository

The application has no third-party runtime dependencies. pytest and the other configured development tools are used for development and testing.

Installation

Install from PyPI

python -m pip install document-intelligence-cli

Install from source

1. Clone the repository

git clone https://github.com/michaelbag8/document-intelligence-cli.git
cd document-intelligence-cli

2. Create and activate a virtual environment

Linux, macOS, and WSL:

python3 -m venv .venv
source .venv/bin/activate

Windows PowerShell:

python -m venv .venv
.venv\Scripts\Activate.ps1

3. Install the project and development dependencies

python -m pip install -e ".[dev]"

The -e option installs the project in editable mode. The [dev] extra installs the development tools configured by the project.

Quick Start

1. Check the installation

docintel --version

2. Display help

docintel --help

3. Analyze a text document

Create a sample file:

echo "Contact support@example.com" > sample.txt

Run the CLI:

docintel sample.txt

You can also run it as a Python module:

python -m docintel sample.txt

Both commands execute the same application.

Example output

For the sample input above, the report will include the extracted email address:

Document Intelligence Report
===========================

Emails:
  - support@example.com

Phone Numbers:

Money:

Dates:

Hashtags:

Mentions:

IP Addresses:

URLs:

The actual report depends on the document's contents.

Command-Line Options

Display help

docintel --help

Or:

python -m docintel --help

Display the version

docintel --version

Or:

python -m docintel --version

Analyze a document

Pass the path to a readable UTF-8 text file as the required positional argument:

docintel sample_data/sample.txt

Handle a missing document

docintel sample_data/does-not-exist.txt

The application reports that the file does not exist and exits with a non-zero status.

Handle an empty document

docintel sample_data/empty.txt

The application reports:

No content found. Nothing to analyze.

An empty document is treated as a valid execution rather than a processing error.

If you omit the required file path, argparse reports that the argument is missing.

Sample Input

Contact support@acme.com or call +2348012345678.
The transaction amount was $2,500.50 on 2024-02-29.
Follow us on #Python and contact @michael.
The server is available at 192.168.1.1.
Visit https://example.com for more information.

The report will include values that are successfully extracted and validated according to the current rules.

Architecture

The application follows a processing pipeline:

CLI (cli.py)
    |
    v
Reader (reader.py)
    |
    v
Processor (processor.py)
    |
    +------> Extractors (extractors.py)
    |
    +------> Validators (validators.py)
    |
    v
Report (report.py)

Project Structure

document-intelligence-cli/
├── README.md
├── CONTRIBUTING.md
├── LICENSE
├── pyproject.toml
├── .gitignore
├── sample_data/
│   ├── sample.txt
│   └── empty.txt
├── .github/
│   └── workflows/
│       └── ci.yml
├── src/
│   └── docintel/
│       ├── __init__.py
│       ├── __main__.py
│       ├── cli.py
│       ├── extractors.py
│       ├── processor.py
│       ├── reader.py
│       ├── report.py
│       └── validators.py
└── tests/
    ├── test_cli.py
    ├── test_extractors.py
    ├── test_processor.py
    ├── test_reader.py
    ├── test_report.py
    └── test_validators.py

Module Responsibilities

  • cli.py: Handles command-line arguments and user-facing CLI behavior.
  • reader.py: Reads the supplied document.
  • extractors.py: Searches document text for candidate values, primarily using regular expressions.
  • validators.py: Checks extracted candidates against the project's validation rules.
  • processor.py: Coordinates extractors and validators and produces structured results.
  • report.py: Converts processed data into a human-readable report.
  • __main__.py: Enables module execution with python -m docintel.

Testing

The project uses pytest.

Run the full test suite:

python -m pytest

The test suite covers:

  • Email, phone number, money, and date extraction and validation
  • Hashtags and mentions
  • IP address and URL extraction and validation
  • Document reading and processing
  • Report generation
  • Empty documents and missing files
  • CLI help, version, and execution

Run a specific test file

python -m pytest tests/test_extractors.py

Run a specific test

python -m pytest tests/test_validators.py::test_valid_email

Development Workflow

When changing the project:

  1. Understand the existing behavior.
  2. Identify the responsible module.
  3. Review the relevant tests.
  4. Make the smallest reasonable change.
  5. Add or update tests.
  6. Run the complete test suite.
  7. Review the final changes.

Changes to functionality should be accompanied by appropriate tests.

Limitations

Document Intelligence CLI uses pattern-based extraction and validation. It is not intended to recognize every possible representation of every supported data type.

Current limitations include:

  • Extraction relies primarily on regular expressions.
  • Supported formats are intentionally limited.
  • Phone numbers follow the project's current digit and length rules.
  • Money extraction currently focuses on dollar amounts.
  • Dates use the YYYY-MM-DD format.
  • IP addresses are extracted as candidates and validated as IPv4 addresses.
  • Hashtags, mentions, and URLs follow the project's current extraction and validation rules.
  • The application processes readable UTF-8 text documents.
  • PDF and Microsoft Word document parsing are not currently supported.
  • Extracted email addresses, URLs, phone numbers, and IP addresses are not guaranteed to exist or be reachable.

Future Improvements

Possible future improvements include:

  • Support for additional date formats
  • Improved phone number handling
  • Support for additional currencies
  • Support for additional document formats
  • Configurable extraction rules
  • JSON output
  • Customizable reports
  • More comprehensive end-to-end CLI tests

Project Links

License

This project is licensed under the MIT License. See the LICENSE file for the complete license text.

About

Document Intelligence CLI is a Python command-line tool that extracts and validates useful information from readable UTF-8 text documents. It identifies candidate values, validates them against the project's rules, and presents the results in a human-readable report.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages