欢迎光临
我们一直在努力

九八云百度小程序教程:swan.ai.nlpLexerCustom

  • swan.ai.nlpLexerCustom
    • 方法参数
      • object 参数说明
      • success 返回参数说明
      • items 参数说明
    • 示例
      • 图片示例
      • 代码示例
      • 返回值示例

    swan.ai.nlpLexerCustom

    基础库 3.20.11 开始支持,低版本需做兼容处理。

    解释:词法分析,提供分词、词性标注、专名识别三大功能。
    Web 态说明:受宿主环境限制,Web 态暂不支持 AI 能力相关接口。在 Web 态会做 打开百度 App 对应小程序页面 的降级处理。

    方法参数

    Object object

    object 参数说明

    属性名 类型 必填 默认值 说明

    text

    String

    待分析文本

    success

    Function

    接口调用成功后的回调函数

    fail

    Function

    接口调用失败的回调函数

    complete

    Function

    接口调用结束的回调函数(调用成功、失败都会执行)

    success 返回参数说明

    参数名 参数类型 说明

    log_id

    Number

    唯一的 log id,用于问题定位

    text

    String

    原始单条请求文本

    items

    Array

    词汇数组,每个元素对应结果中的一个词

    items 参数说明

    参数名 参数类型 说明

    item

    String

    词汇的字符串

    ne

    String

    命名实体类型,命名实体识别算法使用。词性标注算法中,此项为空串

    pos

    String

    词性,词性标注算法使用。命名实体识别算法中,此项为空串

    byte_offset

    Number

    在 text 中的字节级 offset(使用 GBK 编码)

    byte_length

    Number

    字节级 length(使用 GBK 编码)

    uri

    String

    链指到知识库的 URI,只对命名实体有效。对于非命名实体和链接不到知识库的命名实体,此项为空串

    formal

    String

    词汇的标准化表达,主要针对时间、数字单位,没有归一化表达的,此项为空串

    basic_words

    Array

    基本词成分

    loc_details

    Array

    地址成分,非必需,仅对地址型命名实体有效,没有地址成分的,此项为空数组

    示例

    跳转编辑工具

    在开发者工具中打开

    在 WEB IDE 中打开

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例

    • SWAN
    • JS
    
     
    1. <view class="wrap">
    2. <view class="card-area">
    3. <view class="top-description border-bottom">识别内容</view>
    4. <view class="display-area">{{content}}</view>
    5. </view>
    6. <view s-if="{{hasResult}}" class="card-area bottom">
    7. <view class="top-description border-bottom">识别结果</view>
    8. <view s-if="{{sucResult}}">
    9. <view s-for="item in result" class="list-area border-bottom">
    10. <view class="list-item">
    11. <text class="list-item-key-6">词汇的字符串:</text>
    12. <text class="list-item-value">{{item.item}}</text>
    13. </view>
    14. <view class="list-item">
    15. <view class="list-item-key-6">命名实体类型:</view>
    16. <view class="list-item-value">{{item.ne !== '' ? item.ne : '暂无'}}</view>
    17. </view>
    18. <view class="list-item">
    19. <view class="list-item-key-6">词性:</view>
    20. <view class="list-item-value">{{item.pos !== '' ? item.pos : '暂无'}}</view>
    21. </view>
    22. </view>
    23. </view>
    24. <view s-else>
    25. <view class="result-area-fail">识别出错,请到控制台查看信息</view>
    26. </view>
    27. </view>
    28. <view class="swan-security-padding-bottom flex-button">
    29. <button type="primary" class="" bindtap="nlpLexerCustom">
    30. nlpLexerCustom
    31. </button>
    32. </view>
    33. </view>

    返回值示例

    • JSON
    
     
    1. {
    2. "text":"百度是一家高科技公司",
    3. "items":[
    4. {
    5. "byte_length":4,
    6. "byte_offset":0,
    7. "formal":"",
    8. "item":"百度",
    9. "ne":"ORG",
    10. "pos":"",
    11. "uri":"",
    12. "loc_details":[ ],
    13. "basic_words":["百度"]
    14. },
    15. {
    16. "byte_length":2,
    17. "byte_offset":4,
    18. "formal":"",
    19. "item":"是",
    20. "ne":"",
    21. "pos":"v",
    22. "uri":"",
    23. "loc_details":[ ],
    24. "basic_words":["是"]
    25. },
    26. {
    27. "byte_length":4,
    28. "byte_offset":6,
    29. "formal":"",
    30. "item":"一家",
    31. "ne":"",
    32. "pos":"m",
    33. "uri":"",
    34. "loc_details":[ ],
    35. "basic_words":["一","家"]
    36. },
    37. {
    38. "byte_length":6,
    39. "byte_offset":10,
    40. "formal":"",
    41. "item":"高科技",
    42. "ne":"",
    43. "pos":"n",
    44. "uri":"",
    45. "loc_details":[ ],
    46. "basic_words":["高","科技"]
    47. },
    48. {
    49. "byte_length":4,
    50. "byte_offset":16,
    51. "formal":"",
    52. "item":"公司",
    53. "ne":"",
    54. "pos":"n",
    55. "uri":"",
    56. "loc_details":[ ],
    57. "basic_words":["公司"]
    58. }
    59. ]
    60. }

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.ai.nlpLexerCustom

    评论 抢沙发