PHP Classes
elePHPant
Icontem

File: examples/language/LanguageUnderstanding.php

Recommend this page to a friend!
  Classes of MERAJ AHMAD SIDDIQUI  >  PHP IBM Watson  >  examples/language/LanguageUnderstanding.php  >  Download  
File: examples/language/LanguageUnderstanding.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP IBM Watson
Call IBM Watson API services
Author: By
Last change:
Date: 7 months ago
Size: 903 bytes
 

Contents

Class file image Download
<?php

include dirname(dirname(__DIR__)) . "/vendor/autoload.php";
//Provide jspn file to config
use IBMWatson\Config;
//json file containing url, username and password for the service
$api_credintial_json_file = dirname(dirname(__DIR__)) . "/config/conversation.json";
$config = Config::init($api_credintial_json_file);

use
IBMWatson\Language\Natural\Language\Understanding;

$nlu = new Understanding($config);
//See IBM features
$features_to_be_analyzed = [
   
"version" => "2017-02-27",
   
"features" => "keywords,entities",
   
"entities.emotion" => true,
   
"entities.sentiment" => true,
   
"keywords.emotion" => true,
   
"keywords.sentiment" => true,
];
//data to be analyzed
$data_type = "url"; //url, text, html
$data_value = "www.rankwatch.com";
$analyze_data = [$data_type => $data_value];
//analyze this

$analyzed_data = $nlu->analyze($features_to_be_analyzed, $analyze_data);
var_dump($analyzed_data);