如何使用curl命令为Watson NLU指定输入文件?

问题描述 投票:0回答:1

我有一个文本文件,我想通过curl命令将其输入到Watson的自然语言理解服务中,并且想知道如何在传递给该服务的数据上指出这一点。我已经使用URL使它工作了,但是想使用其他来源。在下面的示例中,我要替换“我爱苹果!我不喜欢橘子”。与文件名。谢谢。

curl -X POST -u "apikey:{apikey}" \
"{url}/v1/analyze?version=2019-07-12" \
--request POST \
--header "Content-Type: application/json" \
--data '{
  "text": "I love apples! I do not like oranges.",
  "features": {
    "sentiment": {
      "targets": [
        "apples",
        "oranges",
        "broccoli"
      ]
    },
    "keywords": {
      "emotion": true
    }
  }
}'
curl nlp ibm-watson
1个回答
0
投票

您可以将--data参数作为.json文件提供,以包括文本,但还需要包括其他查询参数。

从API文档-https://cloud.ibm.com/apidocs/natural-language-understanding#analyze-text

 curl -X POST -u "apikey":"{apikey}" -H "Content-Type: application/json" -d @parameters.json "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2019-07-12"

其中parameters.json看起来像:

 {
   "text": "IBM is an American multinational technology company headquartered in Armonk, New York, United States, with operations in over 170 countries.",
   "features": {
     "entities": {
       "emotion": true,
       "sentiment": true,
       "limit": 2
     },
     "keywords": {
       "emotion": true,
       "sentiment": true,
       "limit": 2
     }
   }
 }
© www.soinside.com 2019 - 2024. All rights reserved.