PHPackages                             mauricioschmitz/watson-php-sdk - 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. mauricioschmitz/watson-php-sdk

ActiveLibrary[API Development](/categories/api)

mauricioschmitz/watson-php-sdk
==============================

PHP SDK for Watson so that the developer could apply Watson quickly in PHP applications

024JavaScript

Since Nov 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/schmitz-mauricio/WatsonPHPSDK)[ Packagist](https://packagist.org/packages/mauricioschmitz/watson-php-sdk)[ RSS](/packages/mauricioschmitz-watson-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Watson PHP SDK
==============

[](#watson-php-sdk)

[![Language: PHP](https://camo.githubusercontent.com/02e8771b801f79c341fe2f969c2817573d8a77816910e10edd3141066f007bb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d352e362b2d6f72616e67652e7376673f7374796c653d666c6174)](http://php.net/)[![Build Status](https://camo.githubusercontent.com/08c9755816cf9785fc7477f101a22d60991214ed5e69c08093011ce198eef660/68747470733a2f2f7472617669732d63692e6f72672f436f676e69746976654275696c642f576174736f6e50485053444b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CognitiveBuild/WatsonPHPSDK)[![codecov](https://camo.githubusercontent.com/91964be13fc28e0d3d67c2432fb00a98e8223bb2f65e5a4489476e38e9b55c30/68747470733a2f2f636f6465636f762e696f2f67682f436f676e69746976654275696c642f576174736f6e50485053444b2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/CognitiveBuild/WatsonPHPSDK)

Watson PHP SDK for IBM Watson Developer Cloud

Installation
------------

[](#installation)

Installing [Composer](http://getcomposer.org) will be easier to manage dependencies for your application.

Run the Composer command to install the latest version of the Watson PHP SDK:

```
composer require mauricioschmitz/watsonphpsdk:dev-master
```

If the Watson PHP SDK is downloaded from GitHub already, run the update command:

```
composer update
```

Include `autoload.php` in your application:

```
require 'vendor/autoload.php';
```

Namespaces
----------

[](#namespaces)

For common use, one of the namespaces of `WatsonCredential` or `SimpleTokenProvider` can be optional, depends on how to invoke the Watson services, and you can reference the classes like so:

```
use WatsonSDK\Common\WatsonCredential;
use WatsonSDK\Common\SimpleTokenProvider;
use WatsonSDK\Services\ToneAnalyzer;
use WatsonSDK\Services\ToneAnalyzer\ToneModel;
```

API Reference
-------------

[](#api-reference)

Please [visit our wiki](https://github.com/CognitiveBuild/WatsonPHPSDK/wiki).

Services
--------

[](#services)

- [Tone Analyzer](#tone-analyzer)
- [Natural Language Classifier](#natural-language-classifier)
- [Natural Language Understanding](#natural-language-understanding)
- [Personality Insights](#personality-insights)

Tone Analyzer
-------------

[](#tone-analyzer)

The IBM Watson Tone Analyzer service can be used to discover, understand, and revise the language tones in text. The service uses linguistic analysis to detect three types of tones from written text: emotions, social tendencies, and writing style.

Emotions identified include things like anger, fear, joy, sadness, and disgust. Identified social tendencies include things from the Big Five personality traits used by some psychologists. These include openness, conscientiousness, extraversion, agreeableness, and emotional range. Identified writing styles include confident, analytical, and tentative.

The following example demonstrates how to use the Tone Analyzer service by using credentials:

```
$analyzer = new ToneAnalyzer( WatsonCredential::initWithCredentials('your_username', 'your_password') );
```

or invoke Tone Analyzer API using token, the `SimpleTokenProvider` is a sample of TokenProvider, we recommend you to implement your own Token Provider, by implementing the `TokenProviderInterface`.

```
$tokenProvider = new SimpleTokenProvider('https://your-token-factory-url');
$analyzer = new ToneAnalyzer( WatsonCredential::initWithTokenProvider( $tokenProvider ) );
```

Place the content to be analyzed, call the Tone API and check the result:

```
$model = new ToneModel();
$model->setText('your text to be analyzed.');
$result = $analyzer->getTone($model);
echo $result->getContent();
```

Natural Language Classifier
---------------------------

[](#natural-language-classifier)

The IBM Watson™ Natural Language Classifier service uses machine learning algorithms to return the top matching predefined classes for short text input. You create and train a classifier to connect predefined classes to example texts so that the service can apply those classes to new inputs.

The following example demonstrates how to use the Natural Language Classifier:

```
$nlc = new NaturalLanguageClassifier( WatsonCredential::initWithCredentials('your_username', 'your_password') );
$result = $nlc->classify('your text to be classified.', 'your classifier id');
echo $result->getContent();
```

Natural Language Understanding
------------------------------

[](#natural-language-understanding)

Analyze text to extract meta-data from content such as concepts, entities, keywords, categories, sentiment, emotion, relations, semantic roles, using natural language understanding. With custom annotation models developed using Watson Knowledge Studio, identify industry/domain specific entities and relations in unstructured text.

The following example demonstrates how to use the Natural Language Understanding:

```
$nlu = new NaturalLanguageUnderstanding( WatsonCredential::initWithCredentials('your_username', 'your_password') );
$model = new AnalyzeModel('Watson PHP SDK for IBM Watson Developer Cloud.', [ 'keywords' => [ 'limit' => 5 ] ]);
$result = $nlu->analyze($model);
echo $result->getContent();
```

Personality Insights
--------------------

[](#personality-insights)

Personality Insights extracts personality characteristics based on how a person writes. You can use the service to match individuals to other individuals, opportunities, and products, or tailor their experience with personalized messaging and recommendations. Characteristics include the Big 5 Personality Traits, Values, and Needs. At least 1200 words of input text are recommended when using this service.

The following example demonstrates how to use the Personality Insights service:

```
$insights = new PersonalityInsights( WatsonCredential::initWithCredentials('your_username', 'your_password') );
$model = new ProfileModel( new ContentItemModel('Enter more than 100 unique words here...'));
$mode->setConsumptionPreferences(TRUE);
$result = $insights->getProfile($model);
echo $result->getContent();
```

API response
------------

[](#api-response)

All of the service responses are wrapped in `HttpResponse` class instead of original format of response, so it will be easy for you to use your own HttpClient if necessory. Once there is a result from Watson APIs, there are three common methods you can leverage:

```
// Get HTTP status code
public function getStatusCode();
// Get actual size of response content
public function getSize();
// Get the content of the response
public function getContent();
```

We use `Tone Analyzer` for instance:

```
$analyzer = new ToneAnalyzer(...);
// getTone will return HttpResponse type
$result = $analyzer->getTone('your text to be analyzed.');

var_dump($result->getStatusCode());
var_dump($result->getSize());
var_dump($result->getContent());

// Also there is another way under string context
// You can use $result as the response content instead of using $result->getContent();.
echo $result;
```

Token based authentication
--------------------------

[](#token-based-authentication)

Refer to the samples of [Tone Analyzer](#tone-analyzer) about how to invoke the service by using TokenProvider.

License
-------

[](#license)

Copyright 2017 GCG GBS CTO Office under [the Apache 2.0 license](LICENSE).

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6137bb40d4213ae96f9b97e67a190a461d2249f591e84c072679ee98467d36a5?d=identicon)[mauricioschmitz](/maintainers/mauricioschmitz)

---

Top Contributors

[![mihui](https://avatars.githubusercontent.com/u/1511528?v=4)](https://github.com/mihui "mihui (125 commits)")[![schmitz-mauricio](https://avatars.githubusercontent.com/u/15797891?v=4)](https://github.com/schmitz-mauricio "schmitz-mauricio (26 commits)")[![caopeng86](https://avatars.githubusercontent.com/u/3321290?v=4)](https://github.com/caopeng86 "caopeng86 (1 commits)")

### Embed Badge

![Health badge](/badges/mauricioschmitz-watson-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/mauricioschmitz-watson-php-sdk/health.svg)](https://phpackages.com/packages/mauricioschmitz-watson-php-sdk)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M186](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[microsoft/microsoft-graph

The Microsoft Graph SDK for PHP

65723.5M95](/packages/microsoft-microsoft-graph)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
