我正在尝试https://cloud.ibm.com/apidocs/natural-language-understanding中记录的各种功能的示例示例。尝试使用Curl时,除“情感”功能外,所有功能示例均正常运行。
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
}
答案 0 :(得分:0)
这就是它为我工作的方式。详细说明以帮助他人。
首先,您必须创建一个名为parameters.json
的文件并粘贴以下代码
{
"url": "www.wsj.com/news/markets",
"features": {
"sentiment": {
"targets": [
"stocks"
]
}
}
}
指向该JSON文件在终端或命令提示符下的文件夹,并用NLU服务值替换{apikey}
和{URL}
,运行以下命令
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"
}