2017 © Pedro Peláez
 

detox detox

Detox is a library to detect toxic text (comments/posts etc) of variable length with different patterns

image

arthurkushman/detox

Detox is a library to detect toxic text (comments/posts etc) of variable length with different patterns

  • Sunday, July 8, 2018
  • by arthurkushman
  • Repository
  • 1 Watchers
  • 7 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Detox is a library to detect toxic comments/posts of variable length with different patterns

Scrutinizer Code Quality Build Status Total Downloads Code Intelligence Status codecov License: MIT, (*1)

It's inspired by providing tool for simple scoring/filtering with just a PHP implementation (without the need to set multiple libs probably on C/Python, or importing db dumps etc)., (*2)

Installation

composer require arthurkushman/detox

Using words and word patterns

To get toxicity score on any text:, (*3)

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

to test an input string on asterisk pattern occurrences:, (*4)

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

Using phrases

Another option is to check for phrases:, (*5)

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

There are no constraints to use all options at once, so u can do the following:, (*6)

    // 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';
    }

Replace with custom templates and prefix/postfix pre-sets

An additional option that u may need in particular situations is to replace words/phrases with pre-set template:, (*7)

    $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 

By default pattern is 5 dashes, so u can call only $this->text->setReplaceable(true); before any processor to achieve replacement with default settings., (*8)

Creating custom data-set

    $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

Run tests

In root directory (in console) run the following:, (*9)

phpunit

Be sure to install phpunit globally, or run it from vendor:, (*10)

vendor/bin/phpunit

All contributions are welcome, (*11)

The Versions

08/07 2018

dev-master

9999999-dev

Detox is a library to detect toxic text (comments/posts etc) of variable length with different patterns

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

08/07 2018

dev-develop

dev-develop

Detox is a library to detect toxic text (comments/posts etc) of variable length with different patterns

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

03/07 2018

1.1.5

1.1.5.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

02/07 2018

1.1.4

1.1.4.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

01/07 2018

1.1.3

1.1.3.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

01/07 2018

1.1.2

1.1.2.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

01/07 2018

1.1.1

1.1.1.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

01/07 2018

1.1.0

1.1.0.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Arthur Kushman

30/06 2018

1.0.1

1.0.1.0

DETOX - toxic comments detection library

  Sources   Download

MIT

The Development Requires

by Arthur Kushman