请求方式:POST (HTTPS)
请求地址:
https://open.welink.huaweicloud.com/api/aiservice/v1/nlp/semantic-parser
认证方式: access_token,请参考获取access_token
请求头部:
Content-Type: application/json
x-wlk-Authorization: access_token
请求参数:
{
"text":"来一首周杰伦的青花瓷",
"lang":"zh"
}
请求参数说明:
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
text | 是 | String | 待分析分本列表,UTF-8编码,限定32个字符以内,文本长度超过32个字符时,只检测前32个字符。 |
lang | 否 | String | 支持的文本语言类型,目前只支持中文,默认为zh。 |
请求示例:
curl -X POST \
'https://open.welink.huaweicloud.com/api/aiservice/v1/nlp/semantic-parser' \
-H 'Accept-Charset: UTF-8' \
-H 'Content-Type: application/json' \
-H 'x-wlk-Authorization: access_token' \
-d '{"text":"来一首周杰伦的青花瓷","lang":"zh" }'
响应格式说明
返回结果
正常返回结果
{
"code": "0",
"data": {
"confidence": 1,
"label": "music",
"slots": [
{
"length": 3,
"normalized_word": "周杰伦",
"offset": 3,
"tag": "singer",
"word": "周杰伦"
},
{
"length": 3,
"normalized_word": "青花瓷",
"offset": 7,
"tag": "song",
"word": "青花瓷"
}
],
"text": "来一首周杰伦的青花瓷"
},
"error": "",
"message": "ok"
}
异常返回结果
- 意图理解失败响应示例
{
"code": "58002",
"data": null,
"error": "parameter error.",
"message": "NLP service call exception"
}
- Token验证失败响应示例
{
"code": "58401",
"data": null,
"error": "Failed to verify the token.",
"message": "Login authentication failed."
}
返回参数说明
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
code | 是 | String | 错误码 |
message | 是 | String | 调用成功时为"ok"。调用失败时的错误信息。 |
data | 是 | Object | 调用成功时表示调用结果,详见data数据结构。调用失败时为null。 |
error | 是 | String | 错误信息。 |
- data 数据结构
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
text | 是 | String | 返回待分析分本。 |
label | 是 | String | 待分析文本的意图标签。标签共有以下9类: weather:天气,time:报时,news:新闻,joke:笑话,translation:翻译,notification:提醒,alarm:闹钟,music:音乐,others:其它。 |
confidence | 是 | Float | 标签label的置信度。 |
slots | 是 | Array [slot] | slot数据结构,请参见slot数据结构 |
- slot 数据结构
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
word | 是 | String | 实体文本。 |
tag | 是 | String | 实体类型。对于每个意图类别所支持的实体类型分别为: weather:date(日期),time(时间),location(位置) time:location(位置),timezone(时区) news:genre(风格) joke:genre(风格) translation:content(内容) notification:content(内容),date(日期),time(时间),singer(歌手) alarm:date(日期),time:(时间) music:singer(歌手),song(歌曲),content(内容) |
offset | 是 | Integer | 实体文本在待分析文本中的起始位置。 |
length | 是 | Integer | 实体文本长度。 |
normalized_word | 是 | String | 同义词或者其他标准表达的词,默认为原始的word。 |
错误码说明
错误码 | 说明 |
---|---|
0 | 成功。 |
58401 | 无权限。 |
58402 | 非法参数异常。 |
58500 | 服务异常。 |
58002 | NLP服务异常。 |