{"id":16275315,"url":"https://github.com/arthurkushman/detox","last_synced_at":"2025-03-20T01:30:52.880Z","repository":{"id":62488013,"uuid":"138625284","full_name":"arthurkushman/detox","owner":"arthurkushman","description":"Toxic text (comments/posts etc) detection library","archived":false,"fork":false,"pushed_at":"2020-01-19T10:41:04.000Z","size":38,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-21T08:34:36.027Z","etag":null,"topics":["badwords","detox","filter","php","php-lib","php-library","php7","toxic","toxicity"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arthurkushman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-25T17:02:13.000Z","updated_at":"2023-11-01T15:16:23.000Z","dependencies_parsed_at":"2022-11-02T10:47:06.166Z","dependency_job_id":null,"html_url":"https://github.com/arthurkushman/detox","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Fdetox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Fdetox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Fdetox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Fdetox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arthurkushman","download_url":"https://codeload.github.com/arthurkushman/detox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219865974,"owners_count":16555917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["badwords","detox","filter","php","php-lib","php-library","php7","toxic","toxicity"],"created_at":"2024-10-10T18:33:01.158Z","updated_at":"2024-10-10T18:33:01.234Z","avatar_url":"https://github.com/arthurkushman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Detox is a library to detect toxic comments/posts of variable length with different patterns\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/arthurkushman/detox/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/arthurkushman/detox/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/arthurkushman/detox/badges/build.png?b=master)](https://scrutinizer-ci.com/g/arthurkushman/detox/build-status/master)\n[![Total Downloads](https://poser.pugx.org/arthurkushman/detox/downloads)](https://packagist.org/packages/arthurkushman/detox)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/arthurkushman/detox/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)\n[![codecov](https://codecov.io/gh/arthurkushman/detox/branch/master/graph/badge.svg)](https://codecov.io/gh/arthurkushman/detox)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nIt'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).   \n\n### Installation\n\n```php\ncomposer require arthurkushman/detox\n```\n\n### Using words and word patterns\nTo get toxicity score on any text:\n```php\n    $text  = new Text('Some text');   \n    $words = new Words(new EnglishSet(), $text);\n    $words-\u003eprocessWords();\n    if ($words-\u003egetScore() \u003e= 0.5) {\n        echo 'Toxic text detected';\n    }\n```\nto test an input string on asterisk pattern occurrences:\n```php\n    $words-\u003eprocessPatterns();\n    if ($words-\u003egetScore() \u003e= 0.5) {\n        echo 'Toxic text detected';\n    }    \n```\n\n### Using phrases \nAnother option is to check for phrases:\n```php\n    $phrases = new Phrases(new EnglishSet(), $text);\n    $phrases-\u003eprocessPhrases();\n    if ($words-\u003egetScore() \u003e= 0.5) {\n        echo 'Toxic text detected';\n    }\n```\n\nThere are no constraints to use all options at once, so u can do the following:\n```php\n    // Phrases object extends Words - just use all inherited methods \n    $detox = new Phrases(new EnglishSet(), $text);\n    $detox-\u003eprocessWords();\n    // change string in Text object\n    $text-\u003esetString('Another text');\n    // inject Text object to Phrases \n    $detox-\u003esetText($text);\n    $detox-\u003eprocessPhrases();\n    $text-\u003esetString('Yet another text');\n    $detox-\u003esetText($text);\n    $detox-\u003eprocessPatterns();\n    if ($detox-\u003egetScore() \u003e= 0.5) {\n        echo 'Toxic text detected';\n    }\n```\n\n### Replace with custom templates and prefix/postfix pre-sets\nAn additional option that u may need in particular situations is to replace words/phrases with pre-set template:\n```php\n    $this-\u003etext-\u003esetPrefix('[');\n    $this-\u003etext-\u003esetPostfix(']');\n    $this-\u003etext-\u003esetReplaceChars('____');\n    $this-\u003etext-\u003esetString('Just piss off dude');\n    $this-\u003etext-\u003esetReplaceable(true);\n    $this-\u003ephrases-\u003esetText($this-\u003etext);\n\n    $this-\u003ephrases-\u003eprocessPhrases();\n    echo $this-\u003ephrases-\u003egetText()-\u003egetString(); // output: Just [____] dude \n```\nBy default pattern is 5 dashes, so u can call only `$this-\u003etext-\u003esetReplaceable(true);` before any processor to achieve replacement with default settings. \n\n### Creating custom data-set\n```php\n    $customSet = new CustomSet();\n    $customSet-\u003esetWords([\n        '0.9' =\u003e ['weird']\n    ]);\n    $this-\u003etext-\u003esetString('This weird text should be detected');\n    $this-\u003ewords-\u003esetText($this-\u003etext);\n    $this-\u003ewords-\u003esetDataSet($customSet);\n    $this-\u003ewords-\u003eprocessWords();\n    echo $this-\u003ewords-\u003egetScore(); // output: 0.9\n```\n\n### Run tests\nIn root directory (in console) run the following:\n```php\nphpunit\n```\nBe sure to install phpunit globally, or run it from vendor:\n```php\nvendor/bin/phpunit\n```\n\nAll contributions are welcome","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurkushman%2Fdetox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farthurkushman%2Fdetox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurkushman%2Fdetox/lists"}