<jupyter_start><jupyter_text>点击下列图标在线运行HanLP		 安装 无论是Windows、Linux还是macOS，HanLP的安装只需一句话搞定：<jupyter_code>!pip install hanlp_restful -U<jupyter_output><empty_output><jupyter_text>创建客户端<jupyter_code>from hanlp_restful import HanLPClient
HanLP = HanLPClient('https://www.hanlp.com/api', auth=None, language='zh') # auth不填则匿名，zh中文，mul多语种<jupyter_output><empty_output><jupyter_text>申请秘钥由于服务器算力有限，匿名用户每分钟限2次调用。如果你需要更多调用次数，[建议申请免费公益API秘钥auth](https://bbs.hanlp.com/t/hanlp2-1-restful-api/53)。  语义依存分析任务越少，速度越快。如指定仅执行语义依存分析：<jupyter_code>doc = HanLP('2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。', tasks='sdp')<jupyter_output><empty_output><jupyter_text>返回值为一个[Document](https://hanlp.hankcs.com/docs/api/common/document.html):<jupyter_code>print(doc)<jupyter_output>{
  "tok/fine": [
    ["2021年", "HanLPv2.1", "为", "生产", "环境", "带来", "次", "世代", "最", "先进", "的", "多", "语种", "NLP", "技术", "。"]
  ],
  "sdp": [
    [[[6, "Time"]], [[6, "Agt"]], [[5, "mPrep"]], [[5, "Desc"]], [[6, "Datv"]], [[0, "Root"]], [[8, "Qp"]], [[15, "TDur"]], [[10, "mDegr"]], [[15, "Desc"]], [[10, "mAux"]], [[13, "Quan"]], [[15, "Desc"]], [[15, "Nmod"]], [[6, "Cont"]], [[6, "mPunc"]]]
  ]
}<jupyter_text>`doc['sdp']`字段代表语义依存图的数组格式，数组中第`i`个子数组代表第`i`个单词的语义依存关系，子数组中每个二元组的格式为`[中心词的下标, 与中心词的语义依存关系]`。每个单词的语义依存关系可能有零个、一个或多个（任意数量）。 转换为[CoNLLSentence](https://hanlp.hankcs.com/docs/api/common/conll.htmlhanlp_common.conll.CoNLLSentence)格式更容易观察：<jupyter_code>print(doc.to_conll())<jupyter_output>1	2021年	_	_	_	_	_	_	6:Time	_
2	HanLPv2.1	_	_	_	_	_	_	6:Agt	_
3	为	_	_	_	_	_	_	5:mPrep	_
4	生产	_	_	_	_	_	_	5:Desc	_
5	环境	_	_	_	_	_	_	6:Datv	_
6	带来	_	_	_	_	_	_	0:Root	_
7	次	_	_	_	_	_	_	8:Qp	_
8	世代	_	_	_	_	_	_	15:TDur	_
9	最	_	_	_	_	_	_	10:mDegr	_
10	先进	_	_	_	_	_	_	15:Desc	_
11	的	_	_	_	_	_	_	10:mAux	_
12	多	_	_	_	_	_	_	13:Quan	_
13	语种	_	_	_	_	_	_	15:Desc	_
14	NLP	_	_	_	_	_	_	15:Nmod	_
15	技术	_	_	_	_	_	_	6:Cont	_
16	。	_	_	_	_	_	_	6:mPunc	_<jupyter_text>为已分词的句子执行语义依存分析：<jupyter_code>print(HanLP(tokens=[
    ["HanLP", "为", "生产", "环境", "带来", "次世代", "最", "先进", "的", "多语种", "NLP", "技术", "。"],
    ["我", "的", "希望", "是", "希望", "张晚霞", "的", "背影", "被", "晚霞", "映红", "。"]
  ], tasks='sdp').to_conll())<jupyter_output>1	HanLP	_	_	_	_	_	_	5:Agt	_
2	为	_	_	_	_	_	_	4:mPrep	_
3	生产	_	_	_	_	_	_	4:Desc	_
4	环境	_	_	_	_	_	_	5:Datv	_
5	带来	_	_	_	_	_	_	0:Root	_
6	次世代	_	_	_	_	_	_	12:Time	_
7	最	_	_	_	_	_	_	8:mDegr	_
8	先进	_	_	_	_	_	_	12:Desc	_
9	的	_	_	_	_	_	_	8:mAux	_
10	多语种	_	_	_	_	_	_	12:Desc	_
11	NLP	_	_	_	_	_	_	12:Nmod	_
12	技术	_	_	_	_	_	_	5:Cont	_
13	。	_	_	_	_	_	_	5:mPunc	_

1	我	_	_	_	_	_	_	3:Poss	_
2	的	_	_	_	_	_	_	1:mAux	_
3	希望	_	_	_	_	_	_	0:Root|4:Exp	_
4	是	_	_	_	_	_	_	5:mMod	_
5	希望	_	_	_	_	_	_	4:dClas	_
6	张晚霞	_	_	_	_	_	_	8:Poss	_
7	的	_	_	_	_	_	_	6:mAux	_
8	背影	_	_	_	_	_	_	11:Pat	_
9	被	_	_	_	_	_	_	10:mPrep	_
10	晚霞	_	_	_	_	_	_	11:Exp	_
11	映红	_	_	_	_	_	_	5:dCont	_
12	。	_	_	_	_	_	_	5:mPunc	_
{'fraction_non_alphanumeric': 0.17701312522170984, 'fraction_numerical': 0.055693508336289464, 'mean_word_length': 3.828767123287671, 'pattern_counts': {'":': 2, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '219594', 'license': 'Apache-2.0', 'n_tokens_mistral': 2028, 'n_tokens_neox': 2091, 'n_words': 218, 'path': 'plugins/hanlp_demo/hanlp_demo/zh/sdp_restful.ipynb', 'repo_name': 'chen88358323/HanLP', 'size': '2819'}