2017 © Pedro Peláez
 

library watson-personality-insights-php

PHP Watson Personality Insights Client with Extras

image

darrynten/watson-personality-insights-php

PHP Watson Personality Insights Client with Extras

  • Friday, March 17, 2017
  • by darrynten
  • Repository
  • 3 Watchers
  • 13 Stars
  • 1,000 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

watson-personality-insights-php

Travis Build Status StyleCI Status codecov Packagist Version MIT License, (*1)

A framework agnostic fully unit tested client for IBM Watson Personality insights API., (*2)

For PHP 7.0+, (*3)

Install

composer require darrynten/watson-personality-insights-php

Usage

// Required config
$config = [
    'username' => $username,
    'password' => $password
];

// Get an instance
$instance = new PersonalityInsights($config);

// Add some text
$text = file_get_contents('sample.txt');
$instance->addText($text);

// Get the insights
$insights = $instance->getInsights();

Some things you can set, (*4)

// Set standard options
$instance->config->setConsumptionPreferences(true);
$instance->config->setRawScores(true);
$instance->config->setVersion('2017-01-01');
$instance->config->setContentTypeHeader('application/json');
$instance->config->setContentLanguageHeader('en');
$instance->config->setAcceptHeader('application/json');
$instance->config->setAcceptLanguageHeader('en');
$instance->config->setCsvHeaders(false);
// https://watson-api-explorer.mybluemix.net/apis/personality-insights-v3#!/personality45insights/profile

// Set caching of requests
$instance->config->setCaching(false);

// Opt in to Watson tracking (off by default)
$instance->config->setOptOut(false);

// All config options
$config = [
    'username' => $username,
    'password' => $password,
    'version' => $version,
    'raw_scores' => $boolean,
    'consumption_preferences' => $boolean,
    'cache' => $boolean,
];

You can also add a ContentItem directly, (*5)

/**
 * All possible content item config options. Only the `text` one is
 * required.
 *
 * https://watson-api-explorer.mybluemix.net/apis/personality-insights-v3#!/personality45insights/profile
 *
 * Defaults
 *
 * id - An md5 of the text
 * created - 0
 * updated - 0
 * contenttype - 'text/plain'
 * language - en
 * parentid - null
 * reply - false
 * forward - false
 */
$contentConfig = [
    'text' => $text,          // The only required value
    'id' => $string,          // Is the md5 of the text if not set
    'created' => $timestamp,  // Is 0 if not set
    'updated' => $timestamp,  // Is 0 if not set
    'contenttype' => $string, // `text/plain` or `text/html`
    'language' => $string,    // `en` or similar
    'parentid' => $string,    // The ID of a parent item. Null if not set
    'reply' => $boolean,      // Indicates if it is a reply to another
    'forward' => $boolean,    // Indicates if it is a forwarded text
];

$contentItem = new ContentItem($contentConfig);
$contentItem->getContentItemJson();

$instance->addNewContentItem($contentItem);

Notes

Privacy

IBM have a mode that keeps a copy of your data on their side for the apparent training of Watson. This is normally opt-out., (*6)

As this isn't explicitly made clear, we have decided to disable by default so if you do with to help Watson learn then you can do so by opting-in as outlined in the examples above., (*7)

By default this package will not allow any tracking of any kind., (*8)

"Version"

This is the source of some confusion. This is a date in the format of 'YYYY-MM-DD' and Watson will use whichever version was around at that time., (*9)

Full quote, (*10)

The requested version of the response format as a date in the form YYYY-MM-DD; for example, specify 2016-10-20 for October 20, 2016. The date that you specify does not need to match a version of the service exactly; the service replies with the response format whose version is no later than the date you provide. If you specify a date that is earlier than the initial release of version 3, the service returns the response format for that first version. If you specify a date that is in the future or otherwise later than the most recent version, the service returns the response format for the latest version., (*11)

Credentials

You can download your credentials in a json file, or get them from the developer console., (*12)

Details on IBM, (*13)

Unit tests

Test coverage is 100%, but you can also include a live API test to see if everything is working on that end. You shouldn't have to though, but it can be useful., (*14)

To do live test export, (*15)

export DO_LIVE_API_TESTS=true

You must also include your real credentials.json in the root of the project (it is already in the gitignore)., (*16)

Which will then do the live test., (*17)

Not yet supported

  • Delete from ContentItems collection
  • Modify within ContentItems collection
  • Full error and exception handling
  • Manipulation of the results
  • Minimum text length configuration
  • CSV

Contributing and Testing

There is currently 100% test coverage in the project, please ensure that when contributing you update the tests. For more info see CONTRIBUTING.md, (*18)

Acknowledgements

The Versions

17/03 2017

dev-dev

dev-dev

PHP Watson Personality Insights Client with Extras

  Sources   Download

The Requires

 

The Development Requires

17/03 2017

dev-master

9999999-dev

PHP Watson Personality Insights Client with Extras

  Sources   Download

The Requires

 

The Development Requires

18/02 2017

v1.0.1

1.0.1.0

PHP Watson Personality Insights Client with Extras

  Sources   Download

The Requires

 

The Development Requires

18/02 2017

v1.0.0

1.0.0.0

PHP Watson Personality Insights Client with Extras

  Sources   Download

The Requires

 

The Development Requires