2017 © Pedro PelĂĄez
 

library watson-tone-analyzer

IBM Watson Tone Analyzer

image

adam-paterson/watson-tone-analyzer

IBM Watson Tone Analyzer

  • Wednesday, October 4, 2017
  • by Adam_Paterson
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

IBM Watson - Tone Analyzer

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

The IBM Watsonℱ Tone Analyzer service uses linguistic analysis to detect emotional and language tones in written text. The service can analyze tone at both the document and sentence levels. You can use the service to understand how your written communications are perceived and then to improve the tone of your communications. Businesses can use the service to learn the tone of their customers' communications and to respond to each customer appropriately, or to understand and improve their customer conversations., (*2)

Note: Request logging is disabled for the Tone Analyzer service. The service neither logs nor retains data from requests and responses, regardless of whether the X-Watson-Learning-Opt-Out request header is set., (*3)

Install

Via Composer, (*4)

``` bash $ composer require adam-paterson/watson-tone-analyzer php-http/guzzle6-adapter, (*5)


**Note:** This library uses an abstraction layer called HTTPlug which decouples it from any HTTP messaging client. To see which adapters are available and learn more visit: http://httplug.io/. ## Usage ### General Tone ``` php /** @var $service IBM\Watson\ToneAnalyzer\Client */ $service = IBM\Watson\ToneAnalyzer\Client::create('username', 'password'); /** @var $analysis \IBM\Watson\ToneAnalyzer\Model\ToneAnalysis */ $analysis = $service->tone()->analyze('My fake plants died because I did not pretend to water them.', [ 'content_language' => 'en', 'accept_language' => 'en', 'sentences' => true ]); /** @var $documentAnalysis \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis */ $documentAnalysis = $analysis->getDocumentAnalysis(); foreach ($documentAnalysis->getTones() as $tone) { /** @var $tone \IBM\Watson\ToneAnalyzer\Model\ToneScore */ echo $tone->getName() . ': ' . $tone->getScore() . PHP_EOL; } // Sadness: 0.6165 // Analytical: 0.829888 $sentenceAnalysis = $analysis->getSentenceAnalysis(); foreach ($sentenceAnalysis as $sentence) { echo sprintf('#%d - %s: ', $sentence->getId(), $sentence->getText()) . PHP_EOL; foreach ($sentence->getTones() as $tone) { echo $tone->getName() . ': ' . $tone->getScore() . PHP_EOL; } } // #0 - Team, I know that times are tough! // Analytical: 0.801827 // #1 - Product sales have been disappointing for the past three quarters. // Sadness: 0.771241 // Analytical: 0.687768

Engagement Tone


use IBM\Watson\ToneAnalyzer\Model\Utterance; /** @var $service IBM\Watson\ToneAnalyzer\Client */ $service = IBM\Watson\ToneAnalyzer\Client::create('username', 'password'); $utterances = [ Utterance::create([ Utterance::KEY_TEXT => 'Hello, I\'m having a problem with your product.', Utterance::KEY_USER => 'customer' ]), Utterance::create([ Utterance::KEY_TEXT => 'Sorry to hear that, let me know what\'s going on, please.', Utterance::KEY_USER => 'agent' ]) ]; /** @var $analysis \IBM\Watson\ToneAnalyzer\Model\UtteranceAnalyses */ $analysis = $service->toneChat()->analyze($utterances); /** @var $documentAnalysis \IBM\Watson\ToneAnalyzer\Model\UtteranceAnalyses */ $utteranceAnalysis = $analysis->getTones(); if (null !== $utteranceAnalysis->getWarning()) { echo $utterances->getWarning(); } foreach ($utterances->getTones() as $tone) { /** @var $tone \IBM\Watson\ToneAnalyzer\Model\UtteranceAnalysis */ echo sprintf('#%d - %s: ', $tone->getId(), $tone->getText()) . PHP_EOL; foreach ($tone->getTones() as $utteranceTone) { /** @var $utteranceTone \IBM\Watson\ToneAnalyzer\Model\ToneScore */ echo $utteranceTone->getName() . ': ' . $utteranceTone->getScore() . PHP_EOL; } } // #0 - Hello, I'm having a problem with your product. // Polite: 0.686361 // #1 - Sorry to hear that, let me know what's going on, please. // Polite: 0.92724 // Sympathetic: 0.672499

Change log

Please see CHANGELOG for more information on what has changed recently., (*6)

Testing

bash $ composer test, (*7)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*8)

Security

If you discover any security related issues, please email hello[at]adampaterson.co.uk instead of using the issue tracker., (*9)

Credits

License

The MIT License (MIT). Please see License File for more information., (*10)

The Versions

04/10 2017

dev-develop

dev-develop

IBM Watson Tone Analyzer

  Sources   Download

MIT

The Requires

 

The Development Requires

sdk machine learning ibm watson adam-paterson watson-tone-analyzer tone analysis