2017-06-21 77 views
1

IBM Watson自然語言理解的小型文件只有在通過POST(在php中)接收時纔會獲得英文短語。 當我發佈法語,西班牙語或葡萄牙語不起作用。IBM Watson自然語言理解僅獲得英語短語

我的代碼:

include_once( 'JSON.php'); $ json = new Services_JSON();

//獲取參數 $ 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 ['classified']);

//調用沃森

$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是英語,但其他語言沃森返回:

的POST只能當prashe是英語,但其他語言沃森返回:

{ 「語言」: 「PT」, 「實體」:[], 「警告」: 「關鍵字:內部服務器錯誤」, 「感悟:內部服務器錯誤」]}

但是,當我使用本地變量時,確定,工作。請幫幫我!謝謝!

回答

0

解決!

在行 $ report = utf8_decode(($ _ GET ['report'])?$ _GET ['report']:$ _POST ['report']);

只要刪除utf8_decode即可。

作品!