small for IBM Watson Natural Language Understanding在通过POST ( php)接收时仅获取英语短语。当我发布法语,西班牙语或葡萄牙语都不起作用。
我的代码:
include_once('JSON.php');$json =新的Services_JSON();
//Get参数$protocol =utf8_decode(($_GET‘’protocol‘)?$_GET’‘protocol’:$_POST‘’protocol‘);$report =utf8_decode(($_GET’‘report’)?$_GET‘’report‘:$_POST’‘report’);$class =utf8_decode(($_GET‘’classified‘)?$_GET’‘classified’:$_POST‘分类’);
//调用Watson
$report = strtoupper($report);
$username = 'xxxxxxx';
$password = 'XXXXX';
$url = 'https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27&text=Helloethics&features=entities,sentiment,keywords';
// Set post arguments for call
$post_args = array(
'text' => $report
);
// Set header arguments for call
$header_args = array(
'Content-Type: text/plain',
'Accept: application/json'
);
// Set options for REST call via curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_USERPWD, "xxxxxxxx:XXXXXXX");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Actual REST call via curl and cleanup (closing) of curl call
$result = curl_exec($curl);
print_r($result);
curl_close($curl);
POST/GET仅在prashe为english时有效,但其他语言Watson返回:
只有当prashe是英语,但其他语言Watson返回时,该帖子才有效:
{ "language":"pt","entities":[],"warnings":“关键字:内部服务器错误”,"sentiment:内部服务器错误“}
但是,当我使用局部变量时,OK是有效的。求求你救救我!谢谢!
https://stackoverflow.com/questions/44683331
复制