PHP code example of hop-top / c12n

1. Go to this page and download the library: Download hop-top/c12n 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/ */

    

hop-top / c12n example snippets


use HopTop\C12n\ClassificationContext;
use HopTop\C12n\Pipeline;
use HopTop\C12n\PipelineConfig;
use HopTop\C12n\PipelineResult;

$pipeline = new Pipeline(new PipelineConfig(
    maxConcurrency: 8,
    timeoutMs: 5000,
));

$json = $pipeline->evaluate(new ClassificationContext(
    text: 'Hello, world.',
    history: [],
    headers: ['x-trace' => 'abc'],
));

$result = new PipelineResult($json);

foreach ($result->results() as $signal) {
    printf("%s (%s): %.2f\n", $signal->name, $signal->type, $signal->confidence);
}

$pipeline->close(); // optional — __destruct cleans up