Json 格式化 Google 云 NLP API (documents.analyzeEntities)

Json formatting for Google cloud NLP API (documents.analyzeEntities)

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

{
"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' 下制作一个字典列表。但它不起作用。其中一项尝试如下所示。

{
"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              ^",

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