0

我正在尝试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
}
4

1 回答 1

0

这是它对我的工作方式。以详尽的方式解释以帮助他人。

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

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

在终端或命令提示符上指向此 JSON 文件所在的文件夹,并将 and 替换{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"
}
于 2019-01-21T10:58:09.940 回答