PHP code example of arthurkushman / detox

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

    

arthurkushman / detox example snippets


composer 

    $text  = new Text('Some text');   
    $words = new Words(new EnglishSet(), $text);
    $words->processWords();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }

    $words->processPatterns();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }    

    $phrases = new Phrases(new EnglishSet(), $text);
    $phrases->processPhrases();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }

    // Phrases object extends Words - just use all inherited methods 
    $detox = new Phrases(new EnglishSet(), $text);
    $detox->processWords();
    // change string in Text object
    $text->setString('Another text');
    // inject Text object to Phrases 
    $detox->setText($text);
    $detox->processPhrases();
    $text->setString('Yet another text');
    $detox->setText($text);
    $detox->processPatterns();
    if ($detox->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }

    $this->text->setPrefix('[');
    $this->text->setPostfix(']');
    $this->text->setReplaceChars('____');
    $this->text->setString('Just piss off dude');
    $this->text->setReplaceable(true);
    $this->phrases->setText($this->text);

    $this->phrases->processPhrases();
    echo $this->phrases->getText()->getString(); // output: Just [____] dude 

    $customSet = new CustomSet();
    $customSet->setWords([
        '0.9' => ['weird']
    ]);
    $this->text->setString('This weird text should be detected');
    $this->words->setText($this->text);
    $this->words->setDataSet($customSet);
    $this->words->processWords();
    echo $this->words->getScore(); // output: 0.9

phpunit

vendor/bin/phpunit