Case 1. Automatic contract parsing (Legal / CRM)

Entity extraction with Mitie\NER and local model

Install package: composer require ankane/mitie-php. This variant runs local NER with MITIE and extracts contract entities from a longer legal text.

 
<?php

include 'code-en.php';

if (
$nerError !== null) {
    echo 
'Warning: ' $nerError PHP_EOL;
    return;
}

echo 
$text;
echo 
PHP_EOL PHP_EOL '-----------' PHP_EOL PHP_EOL;

if (
$entities === []) {
    echo 
'No entities found.' PHP_EOL;
    return;
}

foreach (
$entities as $entity) {
    echo (
$entity['tag'] ?? '') . ' -> ' . ($entity['text'] ?? '') . PHP_EOL;
}
Result: Memory: 0.001 Mb Time running: < 0.001 sec.
This Agreement is made on March 12, 2025 between Apple Inc. and John Smith.
Apple Inc. agrees to provide software development services to the client.
The total amount of the agreement is $3,000,000.
The services will be delivered in London, United Kingdom.
The contract duration starts on March 12, 2025 and expires on March 12, 2027.

The agreement was approved by Michael Brown,
Legal Director of Apple Inc.

-----------

ORGANIZATION -> Apple Inc
PERSON -> John Smith
ORGANIZATION -> Apple Inc
LOCATION -> London
LOCATION -> United Kingdom
PERSON -> Michael Brown
ORGANIZATION -> Apple Inc