Skip to content

Commit

Permalink
Merge pull request #4 from darrynten/dev
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
darrynten authored Feb 18, 2017
2 parents 5e89cb5 + 625b8d7 commit 4e50192
Show file tree
Hide file tree
Showing 14 changed files with 795 additions and 186 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.6
- 7.0
- 7.1

Expand All @@ -10,5 +9,7 @@ before_script:
- travis_retry composer install --prefer-dist --no-interaction

script:
- bin/phpunit
- bin/phpunit --coverage-clover=coverage.xml

after_success:
- bash <(curl -s https://codecov.io/bash)
134 changes: 118 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
## watson-personality-insights-php

![Travis Build Status](https://travis-ci.org/darrynten/watson-personality-insights-php.svg?branch=master)
![StyleCI Status](https://styleci.io/repos/81687310/shield?branch=master)
[![codecov](https://codecov.io/gh/darrynten/watson-personality-insights-php/branch/master/graph/badge.svg)](https://codecov.io/gh/darrynten/watson-personality-insights-php)
![Packagist Version](https://img.shields.io/packagist/v/darrynten/watson-personality-insights-php.svg)
![MIT License](https://img.shields.io/github/license/darrynten/watson-personality-insights-php.svg)

A framework agnostic fully unit tested client for IBM Watson Personality
insights API.

For PHP 7.0+

### Install

```bash
Expand All @@ -19,26 +27,35 @@ $config = [
];

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

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

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

// Receive raw scores back
$personality->setRawScores(true);

// Receive consumption preferences
$personality->setConsumptionPreferences(true);
$insights = $instance->getInsights();
```

// Change the version
$personality->version = '2012-01-01';
Some things you can set

// Disable caching
$personality->setCaching(false);
```php
// 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 = [
Expand All @@ -52,12 +69,62 @@ $config = [

```

You can also add a `ContentItem` directly

```php
/**
* 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.

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.

By default this package will not allow any tracking of any kind.

### "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.
'YYYY-MM-DD' and Watson will use whichever version was around at that
time.

Full quote

Expand All @@ -71,10 +138,45 @@ 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.

### Credentials

You can download your credentials in a `json` file, or get them from the
developer console.

[Details on IBM](https://www.ibm.com/watson/developercloud/doc/getting_started/gs-credentials.shtml)

### 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.

To do live test export

```bash
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`).

Which will then do the live test.

### Not yet supported

* CSV support
* 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

## Acknowledgements

* [Dmitry Semenov](https://github.com/mxnr), as always.
* Add yourself here!
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"require": {
"php": "^5.5.9 || ^7.0",
"guzzlehttp/guzzle": "^6.2.1",
"darrynten/any-cache": "^1.0",
"internations/http-mock": "^0.8.1"
"darrynten/any-cache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"mockery/mockery": "dev-master"
"mockery/mockery": "dev-master",
"internations/http-mock": "^0.8.1"
},
"config": {
"bin-dir": "bin"
Expand Down
Loading

0 comments on commit 4e50192

Please sign in to comment.