PHP code example of directorytree / privacy-filter
1. Go to this page and download the library: Download directorytree/privacy-filter 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 example snippets
'paths' => [
'binary' => env('PRIVACY_FILTER_BINARY_PATH', storage_path('app/privacy-filter/bin/privacy-filter')),
'model' => env('PRIVACY_FILTER_MODEL_PATH', storage_path('app/privacy-filter/models/privacy-filter-f16.gguf')),
],
'process' => [
'timeout' => (float) env('PRIVACY_FILTER_TIMEOUT', 60),
],
'model' => [
'url' => env('PRIVACY_FILTER_MODEL_URL', 'https://huggingface.co/LocalAI-io/privacy-filter-GGUF/resolve/main/privacy-filter-f16.gguf'),
],
'release' => [
'repository' => env('PRIVACY_FILTER_BINARY_REPOSITORY', 'DirectoryTree/PrivacyFilterBinaries'),
'version' => env('PRIVACY_FILTER_BINARY_VERSION', 'v1.0.0'),
],
use DirectoryTree\PrivacyFilter\Facades\PrivacyFilter;
$entities = PrivacyFilter::entities('Contact John Doe at [email protected] .');
/** @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
}
$length = $entity->length();
use DirectoryTree\PrivacyFilter\Facades\PrivacyFilter;
$text = 'Contact John Doe at [email protected] or 555-0100.';
// Find personal information.
$entities = PrivacyFilter::entities($text);
// Redact detected entities.
$redacted = collect($entities)->reduce(function (string $text, $entity) {
return str_replace($entity->text, '[redacted]', $text);
}, $text);
// Contact [redacted] at [redacted] or [redacted].
echo $redacted;
$entities = PrivacyFilter::entities(
text: 'Contact John Doe at [email protected] .',
threshold: 0.75,
);
'privacy-filter' => [
'connection' => 'redis',
'queue' => ['privacy-filter'],
'balance' => 'simple',
'processes' => 2,
'tries' => 1,
'timeout' => 300,
],
RedactTranscript::dispatch($transcript)->onQueue('privacy-filter');
$entity->type;
use DirectoryTree\PrivacyFilterClassifier\EntityType;
if ($entity->type() === EntityType::PrivateEmail) {
// ...
}
use DirectoryTree\PrivacyFilterClassifier\Entity;
use DirectoryTree\PrivacyFilter\Facades\PrivacyFilter;
PrivacyFilter::fake([
new Entity(
type: 'private_email',
start: 20,
end: 36,
score: 0.98,
text: '[email protected] ',
),
]);
PrivacyFilter::fake([
'*[email protected] *' => [
new Entity(
type: 'private_email',
start: 20,
end: 36,
score: 0.98,
text: '[email protected] ',
),
],
]);
bash
php artisan privacy-filter:install
bash
php artisan privacy-filter:install --force
bash
php artisan privacy-filter:install
bash
php artisan privacy-filter:install-binary
php artisan privacy-filter:install-model