PHPackages                             sinf/watsonphpsdk - 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. sinf/watsonphpsdk

ActiveLibrary

sinf/watsonphpsdk
=================

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

01.8kPHP

Since Mar 31Pushed 7y ago2 watchersCompare

[ Source](https://github.com/diegocardoso93/WatsonPHPSDK)[ Packagist](https://packagist.org/packages/sinf/watsonphpsdk)[ RSS](/packages/sinf-watsonphpsdk/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)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 sinf/watsonphpsdk
```

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)

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

Assistant
---------

[](#assistant)

Watson Assistant is an enterprise artificial intelligence (AI) assistant that helps businesses enhance brand loyalty and transform their customer experiences by delivering proactive and personalized services while ensuring data privacy. An AI assistant for:

Your brand Increased engagement and loyalty. Your customers Continual learning for customized experiences. Your data Secure and personalized insights.

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

```
$assistant = new Assistant( WatsonCredential::initWithCredentials('your_username', 'your_password') );
$result = $assistant->sendMessage('your_message', 'your_workspace_id');
echo $result->getContent();
```

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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.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/e940b46f0855729e8c9c33c8195b74157e03f1b1d15b04c67ff04058cde80380?d=identicon)[diegocardoso93](/maintainers/diegocardoso93)

---

Top Contributors

[![mihui](https://avatars.githubusercontent.com/u/1511528?v=4)](https://github.com/mihui "mihui (132 commits)")[![caopeng86](https://avatars.githubusercontent.com/u/3321290?v=4)](https://github.com/caopeng86 "caopeng86 (1 commits)")

### Embed Badge

![Health badge](/badges/sinf-watsonphpsdk/health.svg)

```
[![Health](https://phpackages.com/badges/sinf-watsonphpsdk/health.svg)](https://phpackages.com/packages/sinf-watsonphpsdk)
```

PHPackages © 2026

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