我正在尝试访问TexSmart HTTP API
https://ai.tencent.com/ailab/nlp/texsmart/en/api.html
,其中输入文本是与以下结构匹配的词典:
Dict("str" => "text you want to analyze",
"options"=> Dict( "input_spec"=>Dict("lang"=>"auto"),
"word_seg"=>Dict("enable"=>true),
"pos_tagging"=>Dict("enable"=>true,
"alg"=>"log_linear"),
"ner"=>Dict("enable"=>true,
"alg"=>"fine.std"),
"syntactic_parsing"=>Dict("enable"=>false),
"srl"=>Dict("enable"=>false)),
"echo_data"=>Dict("request_id"=>12345)
)
“options”和“echo_data”字段是可选的,可能对我的实现并不重要,所以可以将它们排除在您的答案之外。
我将如何在HTTP.request中提交此内容?
基于API页面上的Python示例,我尝试了以下操作:
HTTP.request("POST", "https://texsmart.qq.com/api",
[codeunits(json(Dict("str"=>"He stayed in San Francisco.")))])
我没有收到回复,也不知道为什么。以下是API文档中的Python示例:
import json
import requests
obj = {"str": "he stayed in San Francisco."}
req_str = json.dumps(obj).encode()
url = "https://texsmart.qq.com/api"
r = requests.post(url, data=req_str)
r.encoding = "utf-8"
print(r.text)
自
json.dumps().encode()
函数返回
bytes
,我想
codeunits()
包装输入字符串的json表示会起到作用,但仍然没有效果。我没有收到错误,只是收到一个内容长度为0的响应。
注意:如果有人知道如何使用
PyCall
或
ccall()
,这个答案也适用于我!