curl - 如何使用 curl 命令为 Watson NLU 指定输入文件?
问题描述
我有一个文本文件,我想通过 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
}
}
}'
解决方案
您可以将 --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
}
}
}
推荐阅读
- bluetooth - Raspberry Pi/Raspian:通过 arecord 从蓝牙耳机录制声音不起作用,但也没有错误消息
- java - 为什么我不能在字符串数组的第 0 个索引处输入值?
- bash - 对多个文件中的列求和的脚本
- python - 选择对象实例化的几种方法之一
- javascript - 基于行中文本匹配的JQuery过滤器
- go - GO中的第二次scanf跳转扫描
- javascript - 如何将 kebab-case 转换为 PascalCase?
- java - 无法使用 Selenium(3.11)、GeckoDriver(0.24.0)、Firefox(57 版本)运行 selenium java 脚本
- sql - SQL server - 使用行窗口函数计算不同的函数或row_numer
- hadoop - Hive - 将叶节点的金额余额汇总到顶级父节点