关于python:Request-interface-and-transform-Hanlp

I got some problems when I am using the client recommend in the official document, that doesn’t work for my current project. Instead I used the same way that work as I expected.


import requests
import pandas as pd

if __name__ == '__main__':
    '''
        1. login and get api and token.
        2. change test contents.
    '''
    url = "http://comdo.hanlp.com/api"

    msg = "2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。阿婆主来到北京立方庭参观天然语义科技公司。"

    headers = {
        "token":"your token"
    }

    postData = {
        "text":"2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。阿婆主来到北京立方庭参观天然语义科技公司."
    }

    r = requests.post(url, headers=headers, data=postData)
    data = r.json()
    # transform into dataframe
    df = pd.DataFrame.from_dict(data)

Reference:

1.hanlp doc

2.use hanlp api

3.convert JSON data from Request into Pandas Dataframe

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理