PHPackages                             bredmor/comment-analyzer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bredmor/comment-analyzer

AbandonedArchivedLibrary[API Development](/categories/api)

bredmor/comment-analyzer
========================

Google Perspective Comment Analyzer API for PHP

v3.0.2(3y ago)96.8k4[1 issues](https://github.com/bredmor/comment-analyzer/issues)[1 PRs](https://github.com/bredmor/comment-analyzer/pulls)MITPHPPHP &gt;=8.0

Since May 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bredmor/comment-analyzer)[ Packagist](https://packagist.org/packages/bredmor/comment-analyzer)[ Docs](https://github.com/bredmor/comment-analyzer)[ RSS](/packages/bredmor-comment-analyzer/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (11)Used By (0)

Deprecated
==========

[](#deprecated)

This project is no longer kept up to date. With the introduction of the Google Gemini LLM as part of the Perspective API, I consider the service no longer reliable for use and have no interest in maintaining this API Wrapper.

CommentAnalyzer
===============

[](#commentanalyzer)

CommentAnalyzer is an API Wrapper for the [Google Perspective Comment Analyzer API](https://www.perspectiveapi.com/#/home)

This package enables you to programmatically scan any kind of text written in supported languages for various metrics associated with negative tones and apply the resulting score, such as automatically hiding harassing or explicit comments from a blog or social media platform.

Installation / Usage
--------------------

[](#installation--usage)

### From Source:

[](#from-source)

Clone the repository from GitHub or unzip into your vendor directory. CommentAnalyzer is packaged for [PSR-4](https://www.php-fig.org/psr/psr-4/) autoloading.

### From Composer:

[](#from-composer)

`composer require bredmor/comment-analyzer`

### Basic Usage:

[](#basic-usage)

CommentAnalyzer accepts text in the form of `Comment` objects that are constructed with a single argument - the text you wish to analyze.

Instantiate the `Analyzer` object, providing it your Perspective API key and an optional [PSR-3](https://www.php-fig.org/psr/psr-3/) compliant `LoggerInterface`. Then add the attribute models you wish to score comments on by calling the instance's `addAttributeModel()` method. **Note**: You *must* provide at least one attribute model for scoring before calling the `analyze()` method or an `AnalyzerException` will be thrown.

Pass an instance of a Comment object to the `Analyzer` object's analyze method. This will start the API call process.

**Note**: If you wish to use this library in an asynchronus manner, the Comment object holds a state variable of `STATE_CREATED`, `STATE_SUBMITTED` and `STATE_ANALYZED`. You can check for the instance's current state via its `getState()` method, to ensure you aren't trying to process the same comment via multiple threads.

After successfully completing the call, the Comment object, which is passed by reference, will be filled out with `SummaryScore` and `SpanScore` objects representing the summary and span scores data returned by the API, respectively. These objects are accessed by calling the Comment object's `getSummaryScore()` or `getSpanScore()` methods with one required argument - one of the attribute models you provided to the Analyzer instance.

#### Example:

[](#example)

```
