NER: example in PHP with MITIE

Extracting entities with Mitie\NER and local model file

This example runs NER via MITIE and prints entity text with detected tags. Runtime checks protect from missing class, FFI extension, or model file.

 
<?php

include 'code-en.php';

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

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

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

foreach (
$entities as $entity) {
    echo (
$entity['text'] ?? '') . ' -> ' . ($entity['tag'] ?? '') . PHP_EOL;
}
Result: Memory: 0 Mb Time running: < 0.001 sec.
Apple signed a contract with John Smith in London for $3 million.
-----------
Apple -> ORGANIZATION
John Smith -> PERSON
London -> LOCATION