textmod / textmod-php
TextMod - php sdk
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7
Requires (Dev)
- phpunit/phpunit: ^9
README
This is an SDK for the TextMod API that allows you to easily moderate text content for various sentiments such as spam, hate, and pornography.
Installation
To use the TextMod SDK for PHP, you can add it as a dependency in your composer.json
file:
{ "require": { "textmod/textmod-php": "^8.0" } }
Then, run composer install
to install the SDK.
Usage
To use the TextMod SDK, you'll need an API authentication token from the TextMod website.
Once you have that, you can create an instance of the TextMod
class:
<?php use TextMod\TextMod; $textmod = new TextMod([ 'authToken' => '<YOUR_AUTH_TOKEN>', 'filterSentiments' => [ TextMod::SPAM, TextMod::SELF_PROMOTING, TextMod::HATE, TextMod::TERRORISM, TextMod::EXTREMISM, TextMod::SELF_HARM ] ]);
The filterSentiments
option is optional and defaults to allowing all sentiments.
If specified, only the specified sentiments will be moderated.
You can then use the moderate method to moderate
text content:
<?php $text = 'Hello world!'; $result = $textmod->moderate($text); var_dump($result);
The moderate
method returns a ModerationResult
object.
You can access the moderated sentiments as properties of the ModerationResult
object.
API Documentation
TextMod
The TextMod
class is the main class in this SDK. It has one method:
moderate(string $text): ModerationResult
Moderates the specified text and returns a ModerationResult
object.
The $text
parameter is a string representing the content to moderate.
ModerationResult
The ModerationResult
class represents the result returned by the moderate
method.
It has boolean properties for each sentiment that has been moderated.
Example
Here's an example of how to use the TextMod
class:
<?php use TextMod\TextMod; $textmod = new TextMod([ 'authToken' => '<YOUR_AUTH_TOKEN>', 'filterSentiments' => [ TextMod::SPAM, TextMod::SELF_PROMOTING, TextMod::HATE, TextMod::TERRORISM, TextMod::EXTREMISM, TextMod::SELF_HARM ] ]); $text = 'Hello world!'; $result = $textmod->moderate($text); // var_dump($result);
Contributing
If you have suggestions for how this SDK could be improved, or want to report a bug, please open an issue! We welcome contributions from the community.
License
This SDK is released under the MIT License.