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.
- 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
docintelcommand or as a Python module. - Handle missing files and empty documents.
- Include automated unit and integration tests.
- Require no third-party runtime dependencies.
| 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:
- Extraction identifies candidate values in the document.
- Validation checks whether candidates satisfy the project's rules.
- 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.
python -m pip install document-intelligence-cligit clone https://github.com/michaelbag8/document-intelligence-cli.git
cd document-intelligence-cliLinux, macOS, and WSL:
python3 -m venv .venv
source .venv/bin/activateWindows PowerShell:
python -m venv .venv
.venv\Scripts\Activate.ps1python -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.
docintel --versiondocintel --helpCreate a sample file:
echo "Contact support@example.com" > sample.txtRun the CLI:
docintel sample.txtYou can also run it as a Python module:
python -m docintel sample.txtBoth commands execute the same application.
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.
docintel --helpOr:
python -m docintel --helpdocintel --versionOr:
python -m docintel --versionPass the path to a readable UTF-8 text file as the required positional argument:
docintel sample_data/sample.txtdocintel sample_data/does-not-exist.txtThe application reports that the file does not exist and exits with a non-zero status.
docintel sample_data/empty.txtThe 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.
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.
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)
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
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 withpython -m docintel.
The project uses pytest.
Run the full test suite:
python -m pytestThe 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
python -m pytest tests/test_extractors.pypython -m pytest tests/test_validators.py::test_valid_emailWhen changing the project:
- Understand the existing behavior.
- Identify the responsible module.
- Review the relevant tests.
- Make the smallest reasonable change.
- Add or update tests.
- Run the complete test suite.
- Review the final changes.
Changes to functionality should be accompanied by appropriate tests.
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-DDformat. - 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.
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
This project is licensed under the MIT License. See the LICENSE file for the complete license text.