!pip install hanlp_restful -U

"""
Explanation: <h2 align="center">点击下列图标在线运行HanLP</h2>
<div align="center">
    <a href="https://colab.research.google.com/github/hankcs/HanLP/blob/doc-zh/plugins/hanlp_demo/hanlp_demo/zh/con_restful.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
    <a href="https://mybinder.org/v2/gh/hankcs/HanLP/doc-zh?filepath=plugins%2Fhanlp_demo%2Fhanlp_demo%2Fzh%2Fcon_restful.ipynb" target="_blank"><img src="https://mybinder.org/badge_logo.svg" alt="Open In Binder"/></a>
</div>

安装
无论是Windows、Linux还是macOS，HanLP的安装只需一句话搞定：
End of explanation
"""


from hanlp_restful import HanLPClient
HanLP = HanLPClient('https://www.hanlp.com/api', auth=None, language='zh') # auth不填则匿名，zh中文，mul多语种

"""
Explanation: 创建客户端
End of explanation
"""


doc = HanLP('2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。', tasks='con')

"""
Explanation: 申请秘钥
由于服务器算力有限，匿名用户每分钟限2次调用。如果你需要更多调用次数，建议申请免费公益API秘钥auth。
短语句法分析
任务越少，速度越快。如指定仅执行短语句法分析：
End of explanation
"""


print(doc)

"""
Explanation: 返回值为一个Document:
End of explanation
"""


doc.pretty_print()

"""
Explanation: doc['con']为Tree类型，是list的子类。
可视化短语句法树：
End of explanation
"""


print(doc['con'][0])

"""
Explanation: 转换为bracketed格式：
End of explanation
"""


HanLP(tokens=[
    ["HanLP", "为", "生产", "环境", "带来", "次世代", "最", "先进", "的", "多语种", "NLP", "技术", "。"],
    ["我", "的", "希望", "是", "希望", "张晚霞", "的", "背影", "被", "晚霞", "映红", "。"]
  ], tasks='con').pretty_print()

"""
Explanation: 为已分词的句子执行短语句法分析：
End of explanation
"""


