0

要将文档发送到 Cloud NLP API,我们使用以下 JSON 格式(根据文档

{
"document":{
            "type":"PLAIN_TEXT",
            "content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Potter fantasy series. i am suffering without resolution.only communication coming about fees without knowledge of card.wrist ever banking experience."
},
"encodingType":"UTF8"
}

这种格式非常适合我正在使用的 curl 命令。

curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" -s -X POST -H "Content-Type: application/json" --data-binary @request.json

但是,如果要添加多个文档,我该怎么做?我尝试了几种方法,例如在“文档”下制作字典列表。但它不起作用。其中一种尝试如下所示。

{
"document":{[{
            "type":"PLAIN_TEXT",
            "content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Potter fantasy series. i am suffering without resolution.only communication coming about fees without knowledge of card.wrist ever banking experience."
            },
            {
            "type":"PLAIN_TEXT",
            "content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Potter fantasy series. i am suffering without resolution.only communication coming about fees without knowledge of card.wrist ever banking experience."
            }
            ]},
"encodingType":"UTF8"
}

我收到类似的错误

"message": "Invalid JSON payload received. Expected an object key or }.\n{\n\"document\":{[\n                {\"\n              ^",
4

1 回答 1

1

目前,Cloud Natural Language API 不接受多个文档请求。您必须将一个文本分组或发送多个请求。
已经有一个要实现的功能请求。
不要犹豫,添加有关您的用例的评论,以便让产品工程团队了解它。

于 2020-12-14T09:46:19.033 回答