#coding: utf-8 import os from pyltp import SentenceSplitter from pyltp import Segmentor from pyltp import Postagger from pyltp import NamedEntityRecognizer from pyltp import Parser from pyltp import SementicRoleLabeller import re # import processHandler import pyltpT #pyltp官方文档http://pyltp.readthedocs.io/zh_CN/develop/api.html#id15 #http://blog.csdn.net/MebiuW/article/details/52496920 #http://blog.csdn.net/lalalawxt/article/details/55804384 LTP_DATA_DIR = 'E:\BaiduNetdiskDownload\ltp_data_v3.4.0' # ltp模型目录的路径 cws_model_path = os.path.join(LTP_DATA_DIR, 'cws.model') # 分词模型路径,模型名称为`cws.model` pos_model_path = os.path.join(LTP_DATA_DIR, 'pos.model') # 词性标注模型路径,模型名称为`pos.model` ner_model_path = os.path.join(LTP_DATA_DIR, 'ner.model') # 命名实体识别模型路径,模型名称为`pos.model` par_model_path = os.path.join(LTP_DATA_DIR, 'parser.model') # 依存句法分析模型路径,模型名称为`parser.model` srl_model_path = os.path.join(LTP_DATA_DIR, 'pisrl.model') # 语义角色标注模型目录路径, print("======================>>>>"+srl_model_path) def main(): #sentence_splitter() words = segmentor('我家在中科院,我现在在北京上学。中秋节你是否会想到李白?') # print(words) tags = posttagger(words) netags=ner(words,tags) arcs = parse(words,tags) roles = role_label(words, tags, netags, arcs) print(roles) # 分句,也就是将一片文本分割为独立的句子 def sentence_splitter(sentence='你好,你觉得这个例子从哪里来的?当然还是直接复制官方文档,然后改了下这里得到的。我的微博是MebiuW,转载请注明来自MebiuW!'): sents = SentenceSplitter.split(sentence) # 分句 print('\n'.join(sents))
哈工大LTP部署及测试Demo
最新推荐文章于 2021-09-04 20:03:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)