PHP code example of survos / classifier-bundle

1. Go to this page and download the library: Download survos/classifier-bundle 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/ */

    

survos / classifier-bundle example snippets


use Survos\ClassifierBundle\Vocabulary\ArrayVocabulary;

$lawsuits = ArrayVocabulary::fromRows('lawsuit', [
    ['code' => 'engle', 'label' => 'Engle v. Liggett', 'properNouns' => ['Engle'],
     'definition' => 'The article is about the Engle class action or its progeny cases.'],
]);

ArrayVocabulary::fromRows('project', [['code' => 'tobacco', 'threshold' => 10, 'rules' => [
    ['match' => 'cigarette', 'score' => 6],                          // a hit adds 6
    ['match' => 'smoking gun', 'score' => -8],                       // a hit takes 8 away
    ['regex' => 'R\.?J\.? Reynolds', 'scope' => 'headline', 'score' => 10],
    ['except' => 'Alcohol, Tobacco and Firearms'],                   // blanked out before matching
    ['meta' => 'host', 'is' => 'tobaccoreporter.com', 'accept' => true],  // existing metadata: accept, nothing else consulted
    ['meta' => 'marking', 'is' => 'spam', 'reject' => true],         // ... or reject outright
]]]);

use Survos\ClassifierBundle\Model\Document;
use Survos\ClassifierBundle\Policy\AssignmentMerger;
use Survos\ClassifierBundle\Strategy\RulesStrategy;
use Survos\ClassifierBundle\Vocabulary\VocabularyRegistry;

$result = $rules->classify(new Document($id, $headline, $summary), $registry->get('country'));

if ($result->abstained === null) {
    // Keeps editor assignments; replaces this strategy's earlier ones in this vocabulary.
    $assignments = $merger->merge($existingAssignments, $result);
}