PHP code example of directorytree / privacy-filter-classifier

1. Go to this page and download the library: Download directorytree/privacy-filter-classifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

directorytree / privacy-filter-classifier example snippets


use DirectoryTree\PrivacyFilterClassifier\Classifier;

$classifier = new Classifier(
    binaryPath: '/path/to/privacy-filter',
    modelPath: '/path/to/privacy-filter-f16.gguf',
    timeout: 60,
);

$entities = $classifier->entities('Contact John Doe at [email protected].');

$entities = $classifier->entities(
    text: 'Contact John Doe at [email protected].',
    threshold: 0.75,
);

/** @var \DirectoryTree\PrivacyFilterClassifier\Entity $entity */
foreach ($entities as $entity) {
    $entity->type;  // private_email
    $entity->text;  // [email protected]
    $entity->start; // 20
    $entity->end;   // 36
    $entity->score; // 0.98
}