watson personality insights php
Updated Documentation
用於 IBM Watson Personality Insights API 的與框架無關的完全單元測試用戶端。
對於 PHP 7.0+
composer require darrynten/watson-personality-insights-php
// 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 ();
有些東西你可以設定
// 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 ,
];
也可以直接加入ContentItem
/**
* 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 );
IBM 有一個模式可以保留您的資料副本,以便對 Watson 進行明顯的訓練。這通常是選擇退出。
由於這一點沒有明確說明,我們決定預設為停用,因此如果您這樣做是為了幫助 Watson 學習,那麼您可以透過選擇加入來實現,如上面範例中所述。
預設情況下,此軟體包不允許任何類型的追蹤。
這是一些混亂的根源。這是格式為「YYYY-MM-DD」的日期,Watson 將使用當時的版本。
完整報價
請求的回應格式版本為 YYYY-MM-DD 格式的日期;例如,指定 2016-10-20 表示 2016 年 10 月 20 日。服務以響應格式進行回复,其版本不晚於您提供的日期。如果您指定的日期早於版本 3 的初始發布,則服務將傳回第一個版本的回應格式。如果您指定將來的日期或晚於最新版本的日期,則服務將傳回最新版本的回應格式。
您可以以json
檔案形式下載憑證,或從開發人員控制台取得它們。
IBM 的詳細信息
測試覆蓋率為 100%,但您還可以包含即時 API 測試,以查看一切是否正常。雖然您不必這樣做,但它可能很有用。
進行即時測試匯出
export DO_LIVE_API_TESTS=true
您還必須在專案的根目錄中包含真實的credentials.json
(它已經在gitignore
中)。
然後將進行現場測試。
目前專案的測試覆蓋率為100%,請確保在貢獻時更新測試。有關更多信息,請參閱 CONTRIBUTING.md