Watson NLU 的情感特征示例失败,错误代码为 400

Sample example of Sentiment feature of Watson NLU failing with error code 400

我正在尝试 https://cloud.ibm.com/apidocs/natural-language-understanding 中记录的各种功能的示例。尝试使用 Curl 时,除 Sentiment 功能外,所有功能示例均正常工作。

curl -X POST \
-H "Content-Type: application/json" \
-u "apikey:{apikey}" \
-d @parameters.json \
"{url}/v1/analyze?version=2018-11-16"

parameters.json
{
  "url": "www.wsj.com/news/markets",
  "features": {
    "sentiment": {
      "targets": [
        "stocks"
      ]
    }
  }
}



Sentiment feature response:
{
  "language": "en",
  "error": "target(s) not found",
  "code": 400
}

以下是它对我的作用。详细解释以帮助他人。

首先,您必须创建一个名为 parameters.json 的文件并粘贴以下代码

{
  "url": "www.wsj.com/news/markets",
  "features": {
    "sentiment": {
      "targets": [
        "stocks"
      ]
    }
  }
}

在终端或命令提示符中指向此 JSON 文件所在的文件夹,并将 {apikey}{URL} 替换为 NLU 服务值 运行下面的命令

curl -X POST \                                                                                                                            
-H "Content-Type: application/json" \
-u "apikey:{APIKEY}" \
-d @parameters.json \
"{URL}/v1/analyze?version=2018-11-16"

我的{URL}是https://gateway.watsonplatform.net/natural-language-understanding/api

然后应该看到下面的输出

{
  "usage": {
    "text_units": 1,
    "text_characters": 1421,
    "features": 1
  },
  "sentiment": {
    "targets": [
      {
        "text": "stocks",
        "score": -0.640222,
        "mixed": "1",
        "label": "negative"
      }
    ],
    "document": {
      "score": -0.662399,
      "label": "negative"
    }
  },
  "retrieved_url": "https://www.wsj.com/news/markets",
  "language": "en"
}