2021-07-11

实体识别_基于百度AI

# -*- coding:utf-8 -*-
import requests
import json

from tornado.escape import json_decode


def Tag(data):
    tag = ''

    APIKey = '官网apikey'
    secret = '官网secretkey'
    host ='https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+APIKey+'&client_secret='+secret
    response = requests.get(host)
    if response:
        print(response.json()['access_token'])

    kv = {
        'accept-encoding': 'gzip, deflate',
        'connection': 'keep-alive',
        'content-type': 'application/json'
    }

    params = {
        "data": data
    }

    text = json.dumps(params)
    # print(type(text))
    url = 'https://aip.baidubce.com/rpc/2.0/kg/v1/cognitive/entity_annotation?charset=UTF-8&access_token=' + response.json()['access_token']
    response1=requests.post(url, headers=kv, timeout=5, data=text)
    if response1:
        result=json.dumps(response1.json(), sort_keys=True, indent=4, ensure_ascii=False)
        print(result)
        result1=json_decode(result)

if __name__=="__main__":
    print(Tag("C语言的祖先是BCPL语言。1967年英国剑桥大学的Martin Richards推出了没有类型的BCPL语言"))

参考文献:https://ai.baidu.com/ai-doc/NLP/7k6z52ggx#%E8%BF%94%E5%9B%9E%E6%A0%BC%E5%BC%8F
https://www.jianshu.com/p/d2fc896dff37
https://cloud.baidu.com/doc/KG/s/jk3h9ztgd
结果:在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值