PHP code example of keevitaja / language-detector-socket

1. Go to this page and download the library: Download keevitaja/language-detector-socket 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/ */

    

keevitaja / language-detector-socket example snippets


use Keevitaja\LanguageDetectorSocket\Server;

$server = new Server([
    'socket' => '/tmp/language-detector.sock',
]);

$server->run();

use Keevitaja\LanguageDetectorSocket\Client;

$client = new Client([
    'socket' => '/tmp/language-detector.sock',
])->make();

$scores = $client->detect('Hello world');
// ['en' => 0.95, 'nl' => 0.03, ...]

$client->close();

[
    // Unix socket path
    'socket' => '/tmp/language.detector.sock',

    // Number of worker processes
    'processes' => 1,

    // Connection timeout in seconds
    'timeout' => 10,

    // Limit detection to specific languages (null = all or ['en', 'nl'])
    'locales' => null,

    // Language model size (SMALL, MEDIUM, LARGE)
    'eldDataFile' => EldDataFile::SMALL,

    // Language code format (ISO639_1, ISO639_3)
    'eldFormat' => EldFormat::ISO639_1,

    // Path to store the worker process ID file
    'workerPidFile' => '/tmp/language.detector.worker.pid',

    // Path to store the worker log file
    'workerLogFile' => '/tmp/language.detector.worker.log',

    // Path to store the worker an stdout log file
    'workerStdoutFile' => '/tmp/language.detector.worker.stdout.log',

    // Whether to run the worker as a daemon process
    'workerDemonize' => false,
]